* declare indent for common lisp?
@ 2008-08-01 17:51 Joost Kremers
2008-08-01 21:59 ` Pascal J. Bourguignon
0 siblings, 1 reply; 4+ messages in thread
From: Joost Kremers @ 2008-08-01 17:51 UTC (permalink / raw)
To: help-gnu-emacs
hi all,
in emacs lisp, if i define a macro that is going to take a body of code as
argument, i generally include a statement such as (declare (indent defun))
in the macro definition, so that the indentation looks better.
is there a way to get emacs to do the same thing for macros in common lisp
code?
TIA
--
Joost Kremers joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: declare indent for common lisp?
2008-08-01 17:51 declare indent for common lisp? Joost Kremers
@ 2008-08-01 21:59 ` Pascal J. Bourguignon
2008-08-02 11:16 ` Joost Kremers
0 siblings, 1 reply; 4+ messages in thread
From: Pascal J. Bourguignon @ 2008-08-01 21:59 UTC (permalink / raw)
To: help-gnu-emacs
Joost Kremers <joostkremers@yahoo.com> writes:
> hi all,
>
> in emacs lisp, if i define a macro that is going to take a body of code as
> argument, i generally include a statement such as (declare (indent defun))
> in the macro definition, so that the indentation looks better.
>
> is there a way to get emacs to do the same thing for macros in common lisp
> code?
(defmacro example (a b c &body d) nil)
(example a
b
c
d
d
d
d)
You could evaluate in emacs: (put 'example 'lisp-indent-function 3)
You could put these forms in the local variable section in your source files,
;; Local Variables:
;; eval: (put 'example 'lisp-indent-function 3)
;; End:
but this is not convenient.
Insteadn for my Common Lisp symbols, I keep the indentation parameters
in files named lisp.indentations, and I have the following functions
in ~/.emacs to load all the lisp.indentations found in the file system
hierarchy from the current directory up.
(require 'cl)
(defun cl-indent (symbol num-forms)
"
Put on the SYMBOL and its lower case and upper case variants
a 'lisp-indent-function property set to NUM-FORMS.
"
(dolist (property '(lisp-indent-function common-lisp-indent-function))
(put symbol property num-forms)
(put (intern (string-downcase (symbol-name symbol))) property num-forms)
(put (intern (string-upcase (symbol-name symbol))) property num-forms)))
(defun* read* (stream &optional (eof-error-p t) eof-value ignored)
(handler-case (read stream)
(end-of-file (err) (if eof-error-p
(error err)
eof-value))))
(defun %batch-cl-indent (&rest indent-symbols-list)
(dolist (item indent-symbols-list)
(let ((indent (car item)))
(dolist (sym (cdr item))
(cl-indent sym indent)
(let ((p (position (character ":") (symbol-name sym))))
(when p
(cl-indent (intern (subseq (symbol-name sym) (1+ p)))
indent)))))))
(defmacro* do-directories-up ((var dir-path &optional result) &body body)
"
DO: Evaluates body with var bound to dir-path, then dir-path's parent,
and so on up to the root directory.
RETURN: The evaluation of the result form.
"
`(do ((,var ,dir-path
(if (string-match "^\\(.*/\\)[^/]+/$" ,var)
(match-string 1 ,var)
"")))
((string-equal "" ,var) ,result)
,@body))
(defun load-lisp-indentations ()
"Processes a lisp.indentations file,
in the current directory, or in a parent."
(interactive)
(do-directories-up (dir default-directory)
(let ((file (concat dir "lisp.indentations")))
;; (message "file = %S" file)
(when (file-exists-p file)
(save-excursion
(let ((count (length (buffer-list)))) ; is there a better way?
(find-file file)
(goto-char (point-min))
(let ((killp (/= count (length (buffer-list)))))
(unwind-protect
(loop
for clause = (read* (current-buffer) nil (current-buffer))
until (eql clause (current-buffer))
do (message "(%%batch-cl-indent '%S)" clause)
do (%batch-cl-indent clause))
(when killp (kill-buffer (current-buffer)))))))))))
--------------------------(~/lisp.indentations)-------------------------
;;; -*- mode:lisp -*-
;;; This file is processed by batch-cl-indent
(defun lambda macrolet)
(((&whole 4 &rest (&whole 1 &lambda &body)) &body)
flet labels)
(((&whole 6 1 1 1 1 1 1) (&whole 4 1 1 1 1 1 1) &body)
destructuring-bind)
(0 progn)
;; (put 'progn 'lisp-indent-function 0), say, causes progn to be indented
;; like defun if the first form is placed on the next line, otherwise
;; it is indented like any other form (i.e. forms line up under first).
(1 block case catch ccase concatenate
do-all-symbols do-external-symbols do-symbols
dolist dotimes ecase eval-when
format
handler-case
if let let*
logical-pathname-translations make-instance
print-unreadable-object
typecase ctypecase etypecase
prog1 rename-package run-program struct unless
unwind-protect when while with-accessors
with-compilation-unit with-condition-restarts
with-gensyms with-hash-table-iterator with-input-from-string
with-open-file with-open-stream with-output-to-string
with-package-iterator with-simple-restart
with-standard-io-syntax with-temp-file without-package-lock)
(2 condition-case destructuring-bind do do* multiple-value-bind
multiple-value-setq prog2 with-slots set-dispatch-macro-character
cl:defmacro)
--
__Pascal Bourguignon__ http://www.informatimago.com/
Cats meow out of angst
"Thumbs! If only we had thumbs!
We could break so much!"
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: declare indent for common lisp?
2008-08-01 21:59 ` Pascal J. Bourguignon
@ 2008-08-02 11:16 ` Joost Kremers
2008-08-03 11:27 ` Rupert Swarbrick
0 siblings, 1 reply; 4+ messages in thread
From: Joost Kremers @ 2008-08-02 11:16 UTC (permalink / raw)
To: help-gnu-emacs
Pascal J. Bourguignon wrote:
> You could evaluate in emacs: (put 'example 'lisp-indent-function 3)
thanks, that appears to work. (btw, i use slime, and i just now found in
the slime docs that you can also set the property common-lisp-indent-function.)
> You could put these forms in the local variable section in your source files,
> ;; Local Variables:
> ;; eval: (put 'example 'lisp-indent-function 3)
> ;; End:
> but this is not convenient.
it may be enough for my purpose, though, ATM there's just a couple of
macros i want to do this for. but i'll save your code and check it out if i
find it's really not convenient.
thanks!
--
Joost Kremers joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: declare indent for common lisp?
2008-08-02 11:16 ` Joost Kremers
@ 2008-08-03 11:27 ` Rupert Swarbrick
0 siblings, 0 replies; 4+ messages in thread
From: Rupert Swarbrick @ 2008-08-03 11:27 UTC (permalink / raw)
To: help-gnu-emacs
Joost Kremers <joostkremers@yahoo.com> writes:
> Pascal J. Bourguignon wrote:
>> You could put these forms in the local variable section in your
>> source files,
>> ;; Local Variables:
>> ;; eval: (put 'example 'lisp-indent-function 3)
>> ;; End:
>> but this is not convenient.
>
> it may be enough for my purpose, though, ATM there's just a couple of
> macros i want to do this for. but i'll save your code and check it out if i
> find it's really not convenient.
>
The only problem I can see with this is when you have a macro defined in
one file which is used somewhere else in your lisp application. This
property won't be set until you've opened a buffer with the file with
your local variable in...
Perhaps it's worth having a global .lispyindents or whatever as Pascal
suggested?
Rupert
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-08-03 11:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-01 17:51 declare indent for common lisp? Joost Kremers
2008-08-01 21:59 ` Pascal J. Bourguignon
2008-08-02 11:16 ` Joost Kremers
2008-08-03 11:27 ` Rupert Swarbrick
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.