I've run into some problems with indentation for defclass forms. Here's an example:
(defclass field () ((name :initarg :name :accessor name) (default-value :initarg :default-value :accessor default-value)) (:default-initargs :name nil :default-value nil))
This seems to be caused by the sexp starting with symbols that start with the letters "def"; I don't have a problem if the slot is named "dfault-value", for example.
I'm using the bundled cl-indent from:
GNU Emacs 21.4.1 (i486-pc-linux-gnu, X toolkit, Xaw3d scroll bars) of 2006-09-15 on rothera, modified by Debian
How can I get the indentation to align properly?
Zach
Hi Zach,
On 16 Feb 2007 14:04:31 -0500, Zach Beane xach@xach.com wrote:
I've run into some problems with indentation for defclass forms. Here's an example:
(defclass field () ((name :initarg :name :accessor name) (default-value :initarg :default-value :accessor default-value)) (:default-initargs :name nil :default-value nil))
This seems to be caused by the sexp starting with symbols that start with the letters "def"; I don't have a problem if the slot is named "dfault-value", for example.
I'm using the bundled cl-indent from:
GNU Emacs 21.4.1 (i486-pc-linux-gnu, X toolkit, Xaw3d scroll bars) of 2006-09-15 on rothera, modified by Debian
How can I get the indentation to align properly?
There should be some standard way to override the "def" indentation rules for exceptions in cl-indent. Until someone submits a proper patch, the following yucky patch does seem to work for your scenario:
--- cl-indent-orig.el 2007-02-16 13:49:06.000000000 -0800 +++ cl-indent-mods.el 2007-02-16 13:51:39.000000000 -0800 @@ -214,15 +214,17 @@ ((null method) (when (null (cdr path)) ;; (package prefix was stripped off above) - (cond ((string-match "\`def" - function) + (cond ((and (string-match "\`def" + function) + (not (string-match "\`default-" + function))) (setq tentative-defun t)) ((string-match
"Bill Clementson" billclem@gmail.com writes:
--- cl-indent-orig.el 2007-02-16 13:49:06.000000000 -0800 +++ cl-indent-mods.el 2007-02-16 13:51:39.000000000 -0800 @@ -214,15 +214,17 @@ ((null method) (when (null (cdr path)) ;; (package prefix was stripped off above)
(cond ((string-match "\\`def"
function)
(cond ((and (string-match "\\`def"
function)
(not (string-match "\\`default-"
function))) (setq tentative-defun t)) ((string-match
wouldn't (not (string-match "\[^:]def" function)) be better?
Hi Marco,
On 2/23/07, Marco Baringer mb@bese.it wrote:
"Bill Clementson" billclem@gmail.com writes:
--- cl-indent-orig.el 2007-02-16 13:49:06.000000000 -0800 +++ cl-indent-mods.el 2007-02-16 13:51:39.000000000 -0800 @@ -214,15 +214,17 @@ ((null method) (when (null (cdr path)) ;; (package prefix was stripped off above)
(cond ((string-match "\\`def"
function)
(cond ((and (string-match "\\`def"
function)
(not (string-match "\\`default-"
function))) (setq tentative-defun t)) ((string-match
wouldn't (not (string-match "\[^:]def" function)) be better?
I don't think that works for Zach's specific example. Here is his code (indented with the standard cl-indent):
(defclass field () ((name :initarg :name :accessor name) (default-value :initarg :default-value :accessor default-value)) (:default-initargs :name nil :default-value nil))
Using my modification to cl-indent, the indentation becomes:
(defclass field () ((name :initarg :name :accessor name) (default-value :initarg :default-value :accessor default-value)) (:default-initargs :name nil :default-value nil))
So, the indentation of both the default-value form and the :default-initargs form is adjusted (which is what Zach was after, I think).
I said it was a "yucky patch" because it just fixes the indentation for this particular scenario. Often, indentation of "def..." forms is handled oddly by cl-indent because of the in-built supposition that (unless otherwise defined) anything that begins with "def" is a definition form. A better patch might be to provide a defcustom emacs variable that could be used for any "def..." forms that aren't to be indented as definition forms and to check that variable before indenting code as a definition form.
-- Bill Clementson