You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
“An Introduction to Programming in Emacs Lisp” Exercises
(info “(eintr) Error Message Exercises”)
foo
(foo)
(setq counter 0)
(setq counter (+ counter 2))
(message"Hello %s!" user-full-name)
(info “(eintr) Evaluation Exercise”)
(goto-char (/ (buffer-size) 2))
(buffer-name)
(buffer-file-name)
(buffer-size)
(point)
(info “(eintr) defun Exercises”)
(defundouble (number)
"Double NUMBER."
(* number 2))
(double 3)
(defundouble (number)
"Double NUMBER."
(interactive"p")
(message"The result is %d" (* number 2)))
(defunfoo (number)
(interactive"p")
(if (> number fill-column)
(message"%d is larger than fill-column" number)))
(info “(eintr) Buffer Exercises”)
(defunsimplified-end-of-buffer ()
"Move point to the end of the buffer, leave mark at previous position."
(interactive)
(push-mark)
(goto-char (point-max)))
(defunfoo (&optionalarg)
(interactive"p")
(unless arg
(setq arg 50))
(if (>= arg fill-column)
(message"%s is equal or larger than fill-column" arg)
(message"%s is smaller than fill-column" arg)))
(info “(eintr) narrow Exercise”)
(defunnarrowing-exercise ()
"Display the first 60 characters of the current buffer."
(save-restriction
(widen)
(message"%s" (buffer-substring (point-min) (+ (point-min) 60)))))
(narrowing-exercise)
(defunprint-third-kill-ring ()
(interactive)
(if (> (length kill-ring) 2)
(message"%s" (nth2 kill-ring))
(message"kill-ring doesn't have at least three elements")))
(defuncount-puncuation (begend)
"Print number of punctuation marks in the region."
(interactive"r")
(message"Counting punctuation marks in the region...")
(save-excursion
(goto-char beg)
(let ((count0))
(while (and (< (point) end)
(re-search-forward"[.,;:!?]" end t))
(setq count (1+ count)))
(cond ((zerop count)
(message"The region does NOT have any punctuation marks."))
((=1 count)
(message"The region has 1 punctuation mark."))
(t
(message"The region has %d punctuation marks." count))))))
(defunrecursive-count-punctuation (region-end)
"Number of punctuation marks between point and REGION-END."
(if (and (< (point) region-end)
(re-search-forward"[.,;:!?]" region-end t))
(1+ (recursive-count-punctuation region-end))
0))
(defuncount-puncuation (begend)
(interactive"r")
(save-excursion
(goto-char beg)
(let ((count (recursive-count-punctuation end)))
(cond ((zerop count)
(message"The region does NOT have any punctuation marks."))
((=1 count)
(message"The region has 1 punctuation mark."))
(t
(message"The region has %d punctuation marks." count))))))