Elisp function returns sign instead of the correct value

I am writing a regular procedure to check if a point is at the practical end of a line.

(defun end-of-line-p () "T if there is only \w* between point and end of line" (interactive) (save-excursion (set-mark-command nil) ;mark where we are (move-end-of-line nil) ;move to the end of the line (let ((str (buffer-substring (mark) (point)))) ;; does any non-ws text exist in the region? return false (if (string-match-p "\W*" str) t nil)))) 

The problem is that when I start, I see a β€œlabel” in the minibuffer window instead of T or nil.

+4
source share
2 answers

There is a built-in eolp function. (editing: but that was not what you were trying to achieve, was it.)

Here is my version of the function (although you will have to test it in more detail than me):

 (defun end-of-line-p () "true if there is only [ \t] between point and end of line" (interactive) (let ( (point-initial (point)) ; save point for returning (result t) ) (move-end-of-line nil) ; move point to end of line (skip-chars-backward " \t" (point-min)) ; skip backwards over whitespace (if (> (point) point-initial) (setq result nil) ) (goto-char point-initial) ; restore where we were result ) ) 
+1
source

(looking-at-p "\\s-*$")

+8
source

All Articles