[slime-cvs] CVS slime/contrib

mbaringer mbaringer at common-lisp.net
Sun Feb 3 18:45:14 UTC 2008


Update of /project/slime/cvsroot/slime/contrib
In directory clnet:/tmp/cvs-serv648/contrib

Modified Files:
	ChangeLog 
Added Files:
	swank-indentation.lisp slime-indentation.el 
Log Message:
cl-indent integration


--- /project/slime/cvsroot/slime/contrib/ChangeLog	2008/02/03 18:39:23	1.83
+++ /project/slime/cvsroot/slime/contrib/ChangeLog	2008/02/03 18:45:14	1.84
@@ -3,10 +3,16 @@
 	* swank-motd.lisp, slime-motd.el: Message Of The Day printing for
 	slime.
 
+	* slime-indentation.el: Integrate cl-indent.el into slime's
+	contrib infrastructure. Fix bug in &rest.
+
+	* swank-indentation.lisp: Allow an application runnig under slime
+	to update emacs' indentation notes.
+
 2008-01-27  Helmut Eller  <heller at common-lisp.net>
 
 	Make autodoc use the correct width of the typeout-window.
-	
+
 	* slime-autodoc.el (slime-autodoc-dimensions-function): New
 	variable.
 	(slime-autodoc-message-dimensions): Use it.
@@ -18,7 +24,7 @@
 2008-01-27  Helmut Eller  <heller at common-lisp.net>
 
 	Use slime-require instead of a connected-hook.
-	
+
 	* slime-autodoc.el (slime-autodoc-on-connect): Deleted.
 
 2008-01-20  Matthias Koeppe  <mkoeppe at mail.math.uni-magdeburg.de>

--- /project/slime/cvsroot/slime/contrib/swank-indentation.lisp	2008/02/03 18:45:14	NONE
+++ /project/slime/cvsroot/slime/contrib/swank-indentation.lisp	2008/02/03 18:45:14	1.1
(in-package :swank)

(defvar *application-hints-tables* '()
  "A list of hash tables mapping symbols to indentation hints (lists 
of symbols and numbers as per cl-indent.el). Applications can add hash 
tables to the list to change the auto indentation slime sends to 
emacs.")

(defun has-application-indentation-hint-p (symbol)
  (let ((default (load-time-value (gensym))))
    (dolist (table *application-hints-tables*)
      (let ((indentation (gethash symbol table default)))
        (unless (eq default indentation)
          (return-from has-application-indentation-hint-p
            (values indentation t))))))
  (values nil nil))

(defun application-indentation-hint (symbol)
  (let ((indentation (has-application-indentation-hint-p symbol)))
    (labels ((walk (indentation-spec)
               (etypecase indentation-spec
                 (null nil)
                 (number indentation-spec)
                 (symbol (symbol-name indentation-spec))
                 (cons (cons (walk (car indentation-spec))
                             (walk (cdr indentation-spec)))))))
      (walk indentation))))

;;; override swank version of this function
(defun symbol-indentation (symbol)
  "Return a form describing the indentation of SYMBOL. 

The form is to be used as the `common-lisp-indent-function' property 
in Emacs."
  (cond
    ((has-application-indentation-hint-p symbol)
     (application-indentation-hint symbol))
    ((and (macro-function symbol)
             (not (known-to-emacs-p symbol)))
     (let ((arglist (arglist symbol)))
       (etypecase arglist
         ((member :not-available)
          nil)
         (list
          (macro-indentation arglist)))))
    (t nil)))
--- /project/slime/cvsroot/slime/contrib/slime-indentation.el	2008/02/03 18:45:14	NONE
+++ /project/slime/cvsroot/slime/contrib/slime-indentation.el	2008/02/03 18:45:14	1.1
;;;; slime-indentation.el - cl-indent.el as a slime-contrib module

(defun slime-indentation-install ()
  (slime-eval-async '(swank:swank-require :swank-indentation)))

(defun slime-indentation-init ()
  (add-hook 'slime-connected-hook 'slime-indentation-install))

;; redefine this for cl-indent:method
(defun slime-handle-indentation-update (alist)
  "Update Lisp indent information for slime-indentation.el.

ALIST is a list of (SYMBOL-NAME . INDENT-SPEC) of proposed indentation
settings for `common-lisp-indent-function'. The appropriate property
is setup, unless the user already set one explicitly."
  (dolist (info alist)
    (let ((symbol (intern (car info)))
          (indent (cdr info)))
      (define-cl-indent (cons symbol
                              (etypecase indent
                                (number (list indent))
                                (cons (labels ((walk (indent)
                                                 (etypecase indent
                                                   ((or number null) indent)
                                                   (cons (cons (walk (car indent))
                                                               (walk (cdr indent))))
                                                   (string (intern (downcase indent))))))
                                        (list (walk indent))))
                                (string (intern (downcase indent))))))
      (run-hook-with-args 'slime-indentation-update-hooks symbol indent))))

;; $ITI: cl-indent.el,v 1.6 1995/09/10 14:13:34 schrod Exp $
;; ----------------------------------------------------------------------
;; Copyright (C) 1987, 1993 Free Software Foundation, Inc.
;; Written by Richard Mlynarik July 1987
;; Merged with cl-indent-patches.el by Marco Baringer (2007-11-14)
;; Documented and intensively modified by Joachim Schrod
;; <jschrod at acm.org>, history at end.
;; Send bug reports, gripes, patches to me.

;;
;; cl-indent.el  ---  highly configurable indentation for Lisp modes
;;

;; This file is part of GNU Emacs.

;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to
;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.


;; ----------------------------------------------------------------------

;; USAGE:

;; This file delivers highly configurable indentation of Lisp code.
;; Eval (cl-indent) to use this indentation for a specific file,
;; (setq lisp-indent-function 'cl-indent:function) to use it for all
;; Lisp files.

;; The indentation for a specific form may be defined by
;; (define-cl-indent SPEC &optional MODE-METHODS). Indentation specs
;; for Common Lisp constructs are given already. Check the on-line
;; documentation of this function for more information.

;; Actually, the whole (`real') documentation of this source is stored
;; as the documentation strings of respective functions. Start with
;; #'define-cl-indent, you'll find references to all other relevant
;; functions.

;; It's also possible to specify specific indentations for a mode
;; (e.g., some special Lisp-mode) and even specific ones for a file.
;; File specific indentations are taken from the alist bound to
;; cl-indent:local-methods, you can set it in your `Local Variables'
;; section. Mode-specific methods are stored in hash tables, the mode
;; setup must bind cl-indent:mode-methods to the name of that hash
;; table.

;; You may want to override my global indentation specs. If you load
;; this file immediately, just issue some #'define-cl-indent calls. If
;; you use autoload, add an appropriate hook function to
;; 'cl-indent:load-hook.

;; I'm interested in feedback on this module. Do you use it, was it
;; useful to you? (Further development depends on the amount of people
;; who send feedback. :-)
;; Send email to <jschrod at acm.org>.



;; ------------------------------------------------------------

;;>> TODO

;; Urgently need better user documentation, it's hard to get a grasp
;; for the overall strategy how this package may be customized. One
;; has to look at too many function documentation strings.

;; Have to check if the usage of hash tables makes this package XEmacs
;; specific. If FSF Emacs doesn't have them, they might be emulated by
;; alists or obarrays. (I don't have FSF Emacs available, may somebody
;; please check this, maybe even send patches?)

;; Realize `parent method tables', to be able to inherit an indentation
;; method table. `(make-method-table &optional size parent)' ?! That's
;; needed before the CL specific indentation is moved to an own table,
;; as some modes (e.g., stil-mode) may inherit their indentation from
;; CL definitions.

;; Common Lisp specific indentation methods should be moved to a
;; method table, it's not good to have them globally for all kinds of
;; Lisp modes. How about a table for Elisp indentations as well?

;; special handling of keywords in forms, e.g.,
;;
;; :foo
;;   bar
;; :baz
;;   zap
;;
;; &key (like &body)??

;; &rest 1 in lambda-lists doesn't work, really want
;;
;;     (foo bar
;;      baz)
;;
;; not
;;
;;     (foo bar
;;          baz)
;;
;; Need something better than &rest for such cases. Perhaps a function
;; that just returns normal-point? Might work...


;;; ------------------------------------------------------------
;;;
;;; USER TOP-LEVEL FUNCTION
;;;

;;;###autoload
(defun cl-indent ()
  "Switch on Common Lisp indentation for the current buffer.
May also be used as hook function, e.g., in lisp-mode-hook.
If you want to do use this indentation for all Lisp buffers, incl.
Emacs Lisp code, simply eval
	(setq lisp-indent-function 'cl-indent:function)
You might want to do this in some setup file, e.g., in ~/.emacs ."
  (interactive)
  (make-local-variable 'lisp-indent-function)
  (setq lisp-indent-function 'cl-indent:function))



;;; ------------------------------------------------------------
;;;
;;; Configuration:
;;;

(defvar cl-indent::maximum-backtracking 3
  "Maximum depth to backtrack out from a sublist for structured indentation.
If this variable is 0, no backtracking will occur and forms such as flet
may not be correctly indented.")

(defvar cl-indent:tag-indentation 1
  "*Indentation of tags relative to containing list.
This variable is used by the function cl-indent:tagbody.")

(defvar cl-indent:tag-body-indentation 3
  "*Indentation of non-tagged lines relative to containing list.
This variable is used by the function cl-indent:tagbody to indent normal
lines (lines without tags).
The indentation is relative to the indentation of the parenthesis enclosing
he special form.  If the value is t, the body of tags will be indented
as a block at the same indentation as the first s-expression following
the tag.  In this case, any forms before the first tag are indented
by lisp-body-indent.")



;;; ============================================================
;;;
;;; compute the indentation of the current line
;;;


;;;###autoload
(defun common-lisp-indent-function (indent-point state)
  "Old name of #'cl-indent:function."
  (cl-indent:function indent-point state))

(make-obsolete #'common-lisp-indent-function #'cl-indent:function)


;;;###autoload
(defun cl-indent:function (indent-point state)
  "Compute the indentation of the current line of Common Lisp code.
INDENT-POINT is the current point. STATE is the result of a
#'parse-partial-sexp from the start of the current function to the
start of the line this function was called.

The indentation is determined by the expressions point is in.

When this function is called, the column of point may be used as the
normal indentation. Therefore we call this position _normal
point_. Actually, if the first element of the current expression is a
list, it's at the start of this element. Otherwise it's at the start
of first expression on the same line as the last complete expression.

Within a quoted list or a non-form list, all subsequent lines are
indented to the column directly after the opening parenthesis. Quoted
lists are those that are prefixed with ?\`, ?\', or ?\#. Note that the
quote must be immediately in front of the opening parenthesis. I.e.,
if you want to use automatic code indentation in a macro expansion
formulated with a backquoted list, add a blank between the backquote
and the expansion form.

Within a list form, the indentation is determined by the indentation
method associated to the form symbol. (See #'cl-indent::method.)

** If the indentation method is nil, the form is assumed to be a
function call, arguments are aligned beneath each other if the first
argument was written behind the function symbol, otherwise they're
aligned below the function symbol.

** If the indentation method is a symbol, a function must be bound to
that symbol that will compute the current indentation. Such a function
is named an _indentation function_ and is called with 5 arguments:

 (1) PATH is a list of numbers, the path from the top-level form to
     the current structural element (the first element is number 0).
     E.g., `foo' has a path of (0 3 1) in `((a b c (d foo) f) g)'.
 (2) STATE is passed.
 (3) INDENT-POINT is passed.
 (4) SEXP-COLUMN is the column where the innermost form starts.
 (5) NORMAL-INDENT is the column of normal point.

** If the indentation method is a list, this list specifies the form
structure and the indentation of each substructure. The possible list
structure and elements are described in #'cl-indent::form-method.

** If the indentation method is the number $n$, the first $n$
arguments are _distinguished arguments_; they are indented by 4
spaces. Further arguments are indented by lisp-body-indent. That's
roughly equivalent to '(4 4 ... &body)' with $n$ 4s.

** Furthermore values as described for #'lisp-indent-function may be
used for upward compatibility."
  (let ((normal-indent (current-column)))
    ;; Walk up list levels until we see something
    ;;  which does special things with subforms.
    (let ((depth 0)
          ;; Path describes the position of point in terms of
          ;;  list-structure with respect to contining lists.
          ;; `foo' has a path of (0 4 1) in `((a b c (d foo) f) g)'
          (path ())
          ;; set non-nil when somebody works out the indentation to use
          calculated
          (last-point indent-point)
          ;; the position of the open-paren of the innermost containing list
          (containing-form-start (elt state 1))
          ;; the column of the above
          sexp-column)
      ;; Move to start of innermost containing list
      (goto-char containing-form-start)
      (setq sexp-column (current-column))
      ;; Look over successively less-deep containing forms
      (while (and (not calculated)
                  (< depth cl-indent::maximum-backtracking))
        (let ((containing-sexp (point)))
          (forward-char 1)
          (parse-partial-sexp (point) indent-point 1 t)
          ;; Move to the car of the relevant containing form
          (let (tem function method)
            (if (not (looking-at "\\sw\\|\\s_"))
                ;; This form doesn't seem to start with a symbol
                (setq function nil method nil)
              (setq tem (point))
              (forward-sexp 1)
              (setq function (downcase (buffer-substring tem (point))))
              (goto-char tem)
              (setq tem (intern-soft function)
                    method (get tem 'cl-indent:method))
              (cond ((and (null method)
                          (string-match ":[^:]+" function))
                     ;; The pleblisp package feature
                     (setq function (substring function
                                               (1+ (match-beginning 0)))
                           method (get (intern-soft function)
                                       'cl-indent:method)))
                    ((and (null method))
                     ;; backwards compatibility
                     (setq method (get tem 'lisp-indent-function)))))
            (let ((n 0))
              ;; How far into the containing form is the current form?
              (if (< (point) indent-point)
                  (while (condition-case ()
                             (progn
                               (forward-sexp 1)
                               (if (>= (point) indent-point)
                                   nil
                                 (parse-partial-sexp (point)
                                                     indent-point 1 t)
                                 (setq n (1+ n))
                                 t))
                           (error nil))))
              (setq path (cons n path)))

            ;; backwards compatibility.
            (cond ((null function))
                  ((null method)
                   (if (null (cdr path))
                       ;; (package prefix was stripped off above)
                       (setq method (cond ((string-match "\\`def"

[774 lines skipped]



More information about the slime-cvs mailing list