Alexander Shukaev
Alexander Shukaev

Reputation: 17021

Emacs Lisp Built-In Indentation Issue with Keywords

Original


Say, I have a function like this:

(defun my-function ()
  "This is my function."
  :his-keyword xxx
  :her-keyword yyy
  (his-function)
  (her-function))

After applying Emacs built-in indentation for Emacs Lisp, I get:

(defun my-function ()
  "This is my function."
  :his-keyword xxx
   :her-keyword yyy
    (his-function)
    (her-function))

Of course I expected it to stay as it was, so looks like a bug to me. Does anyone know how to intercept this behavior? Or should I file a bug report? I'm on Emacs 24.3.

Update


I figured it out.

I've been extending the emacs-lisp-mode with my elisp-mode in order to add more syntax highlighting:

...

(define-derived-mode elisp-mode
  fundamental-mode
  "EL"
  "A major mode for Emacs Lisp."
  (emacs-lisp-mode)
  ...)

(provide 'elisp)

And then somewhere:

(require 'elisp)

(add-to-list
 'auto-mode-alist
 '("\\.el" . elisp-mode))

While elisp-mode was loading successfully, it turned out that emacs-lisp-mode did not load even though I've put (emacs-lisp-mode) into elisp-mode initialization (see above).

After changing to:

(define-derived-mode elisp-mode
  emacs-lisp-mode
  "EL"
  "A major mode for Emacs Lisp."
  ...)

emacs-lisp-mode turns on properly and the indentation finally behaves as expected. That was pretty subtle.

Although, the 2nd variant seems more natural and right, can anyone give me a clue why the 1st variant didn't work?

Upvotes: 0

Views: 258

Answers (1)

sds
sds

Reputation: 60004

original question

I cannot reproduce this with emacs -q and emacs-lisp-mode, so something is wrong with your setup.

You will have to figure out what in your .emacs triggers this behavior, and then report the bug (if it contradicts the documented behavior).

reply to your edit

I think the difference is, more or less, similar to a class inheriting from another class:

(defclass c1 (c2))

and having a field of that class:

(defclass c1 () ((a :type c2)))

See also

  1. Defining Derived Modes
  2. Create new mode in emacs

You might also want to ask a separate question.

Upvotes: 1

Related Questions