all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Common Lisp DEF Macro Indentation
@ 2008-07-14 13:03 Volkan YAZICI
  2008-07-16 19:07 ` Volkan YAZICI
  0 siblings, 1 reply; 2+ messages in thread
From: Volkan YAZICI @ 2008-07-14 13:03 UTC (permalink / raw
  To: help-gnu-emacs

Hi,

I'm trying to write indentation routines for DEF macro of Common Lisp
-- specifically designed for demacs[1]. Below is the code I use at the
moment.

(defmacro concatenate-symbols-for-regexp (&rest symbols)
  (with-output-to-string
    (let (not-first)
      (while symbols
        (if not-first
            (princ "\\|")
          (setq not-first t))
        (princ (pop symbols))))))

(setq lisp-indent-def-function-regexp
      (concatenate-symbols-for-regexp
       function macro compiler-macro method generic
       type print-object class condition))

(defcustom lisp-indent-def-function-regexp
  (concatenate-symbols-for-regexp
   function macro compiler-macro method generic type
   print-object class condition)
  "Definer types will be indented like a function definition form."
  :type 'string
  :group 'lisp-indent)

(defcustom lisp-indent-def-variable-regexp
  (concatenate-symbols-for-regexp
   variable constant load-time-constant special-variable
   symbol-macro struct)
  "Definer types will be indented like a variable definition form."
  :type 'string
  :group 'lisp-indent)

(defcustom lisp-indent-def-setf-regexp
  (concatenate-symbols-for-regexp setf)
  "Definer types will be indented like a setf definition form."
  :type 'string
  :group 'lisp-indent)

(defmacro with-position-at-def-type (position &rest body)
  `(save-excursion
     (goto-char ,position)
     (forward-char 1)
     (forward-sexp 2)
     (backward-sexp)
     (when (looking-at "(")
       (forward-char 1))
     ,@body))

(defun lisp-indent-def (path state indent-point sexp-column normal-
indent)
  (lisp-indent-259
   (with-position-at-def-type (elt state 1)
    (cond ((looking-at lisp-indent-def-function-regexp)
           '(4 4 &lambda &body))
          ((looking-at lisp-indent-def-variable-regexp)
           '(4 4 &body))
          ((looking-at lisp-indent-def-setf-regexp)
           '(4 4 &lambda &body))
          (t
           (error "No available indentation for definer of type `%s'."
                  (current-word)))))
   path state indent-point sexp-column normal-indent))

(put 'def 'common-lisp-indent-function 'lisp-indent-def)

The problem is if I'd start the &body part of the related s-
expressions with a list, emacs complains that ``forward-sexp: Scan
error: "Unbalanced parentheses", 201, 361''. For instance, consider
below case:

;; Indents without a problem.
(def function foo (bar)
  "baz"
  moo)

;; Using `(moo)' instead of `moo' messes up the indentation routine.
(def function foo (bar)
  "baz"
  (moo
...

What might be causing the problem? Are there any mistakes with forms I
supplied to LISP-INDENT-259? Any kind of help will be appreciated.


Regards.

[1] http://cliki.net/demacs


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-07-16 19:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-14 13:03 Common Lisp DEF Macro Indentation Volkan YAZICI
2008-07-16 19:07 ` Volkan YAZICI

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.