EndOfLineNoComments

13:07 impaktor
Is there a command/key like C-e but ignore comments? Like “(lisp-code-here) ;;comment”

There is not, but here’s how you could write one yourself:

(defun impaktor-move-end-of-line ()
  (interactive)
  (skip-syntax-forward "^<" (line-end-position))
  (skip-syntax-backward " " (line-beginning-position)))

How does it work?

(skip-syntax-forward "^<" (line-end-position)) will skip forward up to the end of the line, stopping at a comment start character.

(skip-syntax-backward " " (line-beginning-position)) will skip backward over trailing whitespace.

To install, copy it into your InitFile and add something like the following to your init file:

(add-hook 'emacs-lisp-mode (lambda () (local-set-key (kbd "C-c C-e") 'impaktor-move-end-of-line))

Didn’t know that about skip-syntax for comments. Must be GIT:newcomment.el existed before it was introduced. – AaronHawley

The skip-syntax-forward command shown above works fine for me in Lisp mode, but not in C mode. There, it just moves to end of line. – ChrisLeyon

Yeah, I could not get ‘skip-syntax-forward’ to work on syntax flags – it only works on syntax classes. Bummer! But Aaron pointed in the right direction: use newcomment.el!

(defun impaktor-move-end-of-line ()
  (interactive)
  (when (comment-search-forward (line-end-position) t)
    (goto-char (match-beginning 0))
    (skip-syntax-backward " " (line-beginning-position))))

– Alex


CategoryComments