Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1821 lines
73 KiB

преди 4 години
  1. ;;; slime-cl-indent.el --- enhanced lisp-indent mode
  2. ;; Copyright (C) 1987, 2000-2011 Free Software Foundation, Inc.
  3. ;; Author: Richard Mlynarik <mly@eddie.mit.edu>
  4. ;; Created: July 1987
  5. ;; Maintainer: FSF
  6. ;; Keywords: lisp, tools
  7. ;; Package: emacs
  8. ;; This file is forked from cl-indent.el, which is part of GNU Emacs.
  9. ;; GNU Emacs is free software: you can redistribute it and/or modify
  10. ;; it under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation, either version 3 of the License, or
  12. ;; (at your option) any later version.
  13. ;; GNU Emacs is distributed in the hope that it will be useful,
  14. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;; GNU General Public License for more details.
  17. ;; You should have received a copy of the GNU General Public License
  18. ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
  19. ;;; Commentary:
  20. ;; This package supplies a single entry point, common-lisp-indent-function,
  21. ;; which performs indentation in the preferred style for Common Lisp code.
  22. ;; To enable it:
  23. ;;
  24. ;; (setq lisp-indent-function 'common-lisp-indent-function)
  25. ;;
  26. ;; This file is substantially patched from original cl-indent.el,
  27. ;; which is in Emacs proper. It does not require SLIME, but is instead
  28. ;; required by one of it's contribs, `slime-indentation'.
  29. ;;
  30. ;; Before making modifications to this file, consider adding them to
  31. ;; Emacs's own `cl-indent' and refactoring this file to be an
  32. ;; extension of Emacs's.
  33. ;;; Code:
  34. (require 'slime) ; only for its cl-lib loading smartness
  35. (require 'cl-lib)
  36. (eval-when-compile (require 'cl))
  37. (defgroup lisp-indent nil
  38. "Indentation in Lisp."
  39. :group 'lisp)
  40. (defcustom lisp-indent-maximum-backtracking 6
  41. "Maximum depth to backtrack out from a sublist for structured indentation.
  42. If this variable is 0, no backtracking will occur and forms such as `flet'
  43. may not be correctly indented if this value is less than 4."
  44. :type 'integer
  45. :group 'lisp-indent)
  46. (defcustom lisp-tag-indentation 1
  47. "Indentation of tags relative to containing list.
  48. This variable is used by the function `lisp-indent-tagbody'."
  49. :type 'integer
  50. :group 'lisp-indent)
  51. (defcustom lisp-tag-body-indentation 3
  52. "Indentation of non-tagged lines relative to containing list.
  53. This variable is used by the function `lisp-indent-tagbody' to indent normal
  54. lines (lines without tags).
  55. The indentation is relative to the indentation of the parenthesis enclosing
  56. the special form. If the value is t, the body of tags will be indented
  57. as a block at the same indentation as the first s-expression following
  58. the tag. In this case, any forms before the first tag are indented
  59. by `lisp-body-indent'."
  60. :type 'integer
  61. :group 'lisp-indent)
  62. (defcustom lisp-backquote-indentation t
  63. "Whether or not to indent backquoted lists as code.
  64. If nil, indent backquoted lists as data, i.e., like quoted lists."
  65. :type 'boolean
  66. :group 'lisp-indent)
  67. (defcustom lisp-loop-indent-subclauses t
  68. "Whether or not to indent loop subclauses."
  69. :type 'boolean
  70. :group 'lisp-indent)
  71. (defcustom lisp-simple-loop-indentation 2
  72. "Indentation of forms in simple loop forms."
  73. :type 'integer
  74. :group 'lisp-indent)
  75. (defcustom lisp-loop-clauses-indentation 2
  76. "Indentation of loop clauses if `loop' is immediately followed by a newline."
  77. :type 'integer
  78. :group 'lisp-indent)
  79. (defcustom lisp-loop-indent-body-forms-relative-to-loop-start nil
  80. "When true, indent loop body clauses relative to the open paren of the loop
  81. form, instead of the keyword position."
  82. :type 'boolean
  83. :group 'lisp-indent)
  84. (defcustom lisp-loop-body-forms-indentation 3
  85. "Indentation of loop body clauses."
  86. :type 'integer
  87. :group 'lisp-indent)
  88. (defcustom lisp-loop-indent-forms-like-keywords nil
  89. "Whether or not to indent loop subforms just like
  90. loop keywords. Only matters when `lisp-loop-indent-subclauses'
  91. is nil."
  92. :type 'boolean
  93. :group 'lisp-indent)
  94. (defcustom lisp-align-keywords-in-calls t
  95. "Whether to align keyword arguments vertically or not.
  96. If t (the default), keywords in contexts where no other
  97. indentation rule takes precedence are aligned like this:
  98. \(make-instance 'foo :bar t
  99. :quux 42)
  100. If nil, they are indented like any other function
  101. call arguments:
  102. \(make-instance 'foo :bar t
  103. :quux 42)"
  104. :type 'boolean
  105. :group 'lisp-indent)
  106. (defcustom lisp-lambda-list-indentation t
  107. "Whether to indent lambda-lists specially. Defaults to t. Setting this to
  108. nil makes `lisp-lambda-list-keyword-alignment',
  109. `lisp-lambda-list-keyword-parameter-alignment', and
  110. `lisp-lambda-list-keyword-parameter-indentation' meaningless, causing
  111. lambda-lists to be indented as if they were data:
  112. \(defun example (a b &optional o1 o2
  113. o3 o4
  114. &rest r
  115. &key k1 k2
  116. k3 k4)
  117. #|...|#)"
  118. :type 'boolean
  119. :group 'lisp-indent)
  120. (defcustom lisp-lambda-list-keyword-alignment nil
  121. "Whether to vertically align lambda-list keywords together.
  122. If nil (the default), keyworded lambda-list parts are aligned
  123. with the initial mandatory arguments, like this:
  124. \(defun foo (arg1 arg2 &rest rest
  125. &key key1 key2)
  126. #|...|#)
  127. If non-nil, alignment is done with the first keyword
  128. \(or falls back to the previous case), as in:
  129. \(defun foo (arg1 arg2 &rest rest
  130. &key key1 key2)
  131. #|...|#)"
  132. :type 'boolean
  133. :group 'lisp-indent)
  134. (defcustom lisp-lambda-list-keyword-parameter-indentation 2
  135. "Indentation of lambda list keyword parameters.
  136. See `lisp-lambda-list-keyword-parameter-alignment'
  137. for more information."
  138. :type 'integer
  139. :group 'lisp-indent)
  140. (defcustom lisp-lambda-list-keyword-parameter-alignment nil
  141. "Whether to vertically align lambda-list keyword parameters together.
  142. If nil (the default), the parameters are aligned
  143. with their corresponding keyword, plus the value of
  144. `lisp-lambda-list-keyword-parameter-indentation', like this:
  145. \(defun foo (arg1 arg2 &key key1 key2
  146. key3 key4)
  147. #|...|#)
  148. If non-nil, alignment is done with the first parameter
  149. \(or falls back to the previous case), as in:
  150. \(defun foo (arg1 arg2 &key key1 key2
  151. key3 key4)
  152. #|...|#)"
  153. :type 'boolean
  154. :group 'lisp-indent)
  155. (defvar lisp-indent-defun-method '(4 &lambda &body)
  156. "Defun-like indentation method.
  157. This applies when the value of the `common-lisp-indent-function' property
  158. is set to `defun'.")
  159. ;;;; Named styles.
  160. ;;;;
  161. ;;;; -*- common-lisp-style: foo -*-
  162. ;;;;
  163. ;;;; sets the style for the buffer.
  164. ;;;;
  165. ;;;; A Common Lisp style is a list of the form:
  166. ;;;;
  167. ;;;; (NAME INHERIT VARIABLES INDENTATION HOOK DOCSTRING)
  168. ;;;;
  169. ;;;; where NAME is a symbol naming the style, INHERIT is the name of the style
  170. ;;;; it inherits from, VARIABLES is an alist specifying buffer local variables
  171. ;;;; for the style, and INDENTATION is an alist specifying non-standard
  172. ;;;; indentations for Common Lisp symbols. HOOK is a function to call when
  173. ;;;; activating the style. DOCSTRING is the documentation for the style.
  174. ;;;;
  175. ;;;; Convenience accessors `common-lisp-style-name', &co exist.
  176. ;;;;
  177. ;;;; `common-lisp-style' stores the name of the current style.
  178. ;;;;
  179. ;;;; `common-lisp-style-default' stores the name of the style to use when none
  180. ;;;; has been specified.
  181. ;;;;
  182. ;;;; `common-lisp-active-style' stores a cons of the list specifying the
  183. ;;;; current style, and a hash-table containing all indentation methods of
  184. ;;;; that style and any styles it inherits from. Whenever we're indenting, we
  185. ;;;; check that this is up to date, and recompute when necessary.
  186. ;;;;
  187. ;;;; Just setting the buffer local common-lisp-style will be enough to have
  188. ;;;; the style take effect. `common-lisp-set-style' can also be called
  189. ;;;; explicitly, however, and offers name completion, etc.
  190. ;;; Convenience accessors
  191. (defun common-lisp-style-name (style) (first style))
  192. (defun common-lisp-style-inherits (style) (second style))
  193. (defun common-lisp-style-variables (style) (third style))
  194. (defun common-lisp-style-indentation (style) (fourth style))
  195. (defun common-lisp-style-hook (style) (fifth style))
  196. (defun common-lisp-style-docstring (style) (sixth style))
  197. (defun common-lisp-make-style (stylename inherits variables indentation hook
  198. documentation)
  199. (list stylename inherits variables indentation hook documentation))
  200. (defvar common-lisp-style nil)
  201. ;;; `define-common-lisp-style' updates the docstring of
  202. ;;; `common-lisp-style', using this as the base.
  203. (put 'common-lisp-style 'common-lisp-style-base-doc
  204. "Name of the Common Lisp indentation style used in the current buffer.
  205. Set this by giving eg.
  206. ;; -*- common-lisp-style: sbcl -*-
  207. in the first line of the file, or by calling `common-lisp-set-style'. If
  208. buffer has no style specified, but `common-lisp-style-default' is set, that
  209. style is used instead. Use `define-common-lisp-style' to define new styles.")
  210. (make-variable-buffer-local 'common-lisp-style)
  211. (set-default 'common-lisp-style nil)
  212. ;;; `lisp-mode' kills all buffer-local variables. Setting the
  213. ;;; `permanent-local' property allows us to retain the style.
  214. (put 'common-lisp-style 'permanent-local t)
  215. ;;; Mark as safe when the style doesn't evaluate arbitrary code.
  216. (put 'common-lisp-style 'safe-local-variable 'common-lisp-safe-style-p)
  217. ;;; Common Lisp indentation style specifications.
  218. (defvar common-lisp-styles (make-hash-table :test 'equal))
  219. (defun common-lisp-delete-style (stylename)
  220. (remhash stylename common-lisp-styles))
  221. (defun common-lisp-find-style (stylename)
  222. (let ((name (if (symbolp stylename)
  223. (symbol-name stylename)
  224. stylename)))
  225. (or (gethash name common-lisp-styles)
  226. (error "Unknown Common Lisp style: %s" name))))
  227. (defun common-lisp-safe-style-p (stylename)
  228. "True for known Common Lisp style without an :EVAL option.
  229. Ie. styles that will not evaluate arbitrary code on activation."
  230. (let* ((style (ignore-errors (common-lisp-find-style stylename)))
  231. (base (common-lisp-style-inherits style)))
  232. (and style
  233. (not (common-lisp-style-hook style))
  234. (or (not base)
  235. (common-lisp-safe-style-p base)))))
  236. (defun common-lisp-add-style (stylename inherits variables indentation hooks
  237. documentation)
  238. ;; Invalidate indentation methods cached in common-lisp-active-style.
  239. (maphash (lambda (k v)
  240. (puthash k (cl-copy-list v) common-lisp-styles))
  241. common-lisp-styles)
  242. ;; Add/Redefine the specified style.
  243. (puthash stylename
  244. (common-lisp-make-style stylename inherits variables indentation
  245. hooks documentation)
  246. common-lisp-styles)
  247. ;; Frob `common-lisp-style' docstring.
  248. (let ((doc (get 'common-lisp-style 'common-lisp-style-base-doc))
  249. (all nil))
  250. (setq doc (concat doc "\n\nAvailable styles are:\n"))
  251. (maphash (lambda (name style)
  252. (push (list name (common-lisp-style-docstring style)) all))
  253. common-lisp-styles)
  254. (dolist (info (sort all (lambda (a b) (string< (car a) (car b)))))
  255. (let ((style-name (first info))
  256. (style-doc (second info)))
  257. (if style-doc
  258. (setq doc (concat doc
  259. "\n " style-name "\n"
  260. " " style-doc "\n"))
  261. (setq doc (concat doc
  262. "\n " style-name " (undocumented)\n")))))
  263. (put 'common-lisp-style 'variable-documentation doc))
  264. stylename)
  265. ;;; Activate STYLENAME, adding its indentation methods to METHODS -- and
  266. ;;; recurse on style inherited from.
  267. (defun common-lisp-activate-style (stylename methods)
  268. (let* ((style (common-lisp-find-style stylename))
  269. (basename (common-lisp-style-inherits style)))
  270. ;; Recurse on parent.
  271. (when basename
  272. (common-lisp-activate-style basename methods))
  273. ;; Copy methods
  274. (dolist (spec (common-lisp-style-indentation style))
  275. (puthash (first spec) (second spec) methods))
  276. ;; Bind variables.
  277. (dolist (var (common-lisp-style-variables style))
  278. (set (make-local-variable (first var)) (second var)))
  279. ;; Run hook.
  280. (let ((hook (common-lisp-style-hook style)))
  281. (when hook
  282. (funcall hook)))))
  283. ;;; When a style is being used, `common-lisp-active-style' holds a cons
  284. ;;;
  285. ;;; (STYLE . METHODS)
  286. ;;;
  287. ;;; where STYLE is the list specifying the currently active style, and
  288. ;;; METHODS is the table of indentation methods -- including inherited
  289. ;;; ones -- for it. `common-lisp-active-style-methods' is reponsible
  290. ;;; for keeping this up to date.
  291. (make-variable-buffer-local (defvar common-lisp-active-style nil))
  292. ;;; Makes sure common-lisp-active-style corresponds to common-lisp-style, and
  293. ;;; pick up redefinitions, etc. Returns the method table for the currently
  294. ;;; active style.
  295. (defun common-lisp-active-style-methods ()
  296. (let* ((name common-lisp-style)
  297. (style (when name (common-lisp-find-style name))))
  298. (if (eq style (car common-lisp-active-style))
  299. (cdr common-lisp-active-style)
  300. (when style
  301. (let ((methods (make-hash-table :test 'equal)))
  302. (common-lisp-activate-style name methods)
  303. (setq common-lisp-active-style (cons style methods))
  304. methods)))))
  305. (defvar common-lisp-set-style-history nil)
  306. (defun common-lisp-style-names ()
  307. (let (names)
  308. (maphash (lambda (k v)
  309. (push (cons k v) names))
  310. common-lisp-styles)
  311. names))
  312. (defun common-lisp-set-style (stylename)
  313. "Set current buffer to use the Common Lisp style STYLENAME.
  314. STYLENAME, a string, must be an existing Common Lisp style. Styles
  315. are added (and updated) using `define-common-lisp-style'.
  316. The buffer-local variable `common-lisp-style' will get set to STYLENAME.
  317. A Common Lisp style is composed of local variables, indentation
  318. specifications, and may also contain arbitrary elisp code to run upon
  319. activation."
  320. (interactive
  321. (list (let ((completion-ignore-case t)
  322. (prompt "Specify Common Lisp indentation style: "))
  323. (completing-read prompt
  324. (common-lisp-style-names) nil t nil
  325. 'common-lisp-set-style-history))))
  326. (setq common-lisp-style (common-lisp-style-name
  327. (common-lisp-find-style stylename))
  328. common-lisp-active-style nil)
  329. ;; Actually activates the style.
  330. (common-lisp-active-style-methods)
  331. stylename)
  332. (defmacro define-common-lisp-style (name documentation &rest options)
  333. "Define a Common Lisp indentation style.
  334. NAME is the name of the style.
  335. DOCUMENTATION is the docstring for the style, automatically added to the
  336. docstring of `common-lisp-style'.
  337. OPTIONS are:
  338. (:variables (name value) ...)
  339. Specifying the buffer local variables associated with the style.
  340. (:indentation (symbol spec) ...)
  341. Specifying custom indentations associated with the style. SPEC is
  342. a normal `common-lisp-indent-function' indentation specification.
  343. (:inherit style)
  344. Inherit variables and indentations from another Common Lisp style.
  345. (:eval form ...)
  346. Lisp code to evaluate when activating the style. This can be used to
  347. eg. activate other modes. It is possible that over the lifetime of
  348. a buffer same style gets activated multiple times, so code in :eval
  349. option should cope with that.
  350. "
  351. (when (consp documentation)
  352. (setq options (cons documentation options)
  353. documentation nil))
  354. `(common-lisp-add-style ,name
  355. ',(cadr (assoc :inherit options))
  356. ',(cdr (assoc :variables options))
  357. ',(cdr (assoc :indentation options))
  358. ,(when (assoc :eval options)
  359. `(lambda ()
  360. ,@(cdr (assoc :eval options))))
  361. ,documentation))
  362. (define-common-lisp-style "basic-common"
  363. (:variables
  364. (lisp-indent-maximum-backtracking 6)
  365. (lisp-tag-indentation 1)
  366. (lisp-tag-body-indentation 3)
  367. (lisp-backquote-indentation t)
  368. (lisp-loop-indent-subclauses t)
  369. (lisp-loop-indent-forms-like-keywords nil)
  370. (lisp-simple-loop-indentation 2)
  371. (lisp-align-keywords-in-calls t)
  372. (lisp-lambda-list-indentation t)
  373. (lisp-lambda-list-keyword-alignment nil)
  374. (lisp-lambda-list-keyword-parameter-indentation 2)
  375. (lisp-lambda-list-keyword-parameter-alignment nil)
  376. (lisp-indent-defun-method (4 &lambda &body))
  377. (lisp-loop-clauses-indentation 2)
  378. (lisp-loop-indent-body-forms-relative-to-loop-start nil)
  379. (lisp-loop-body-forms-indentation 3)))
  380. (define-common-lisp-style "basic-emacs25"
  381. "This style adds a workaround needed for Emacs 25"
  382. (:inherit "basic-common")
  383. (:variables
  384. ;; Without these (;;foo would get a space inserted between
  385. ;; ( and ; by indent-sexp.
  386. (comment-indent-function (lambda () nil))))
  387. (define-common-lisp-style "basic-emacs26"
  388. "This style is the same as basic-common. It doesn't need or
  389. want the workaround used in Emacs 25. In Emacs 26, that
  390. workaround introduces a weird behavior where a single
  391. semicolon breaks the mode and causes the cursor to move to the
  392. start of the line after every character inserted."
  393. (:inherit "basic-common"))
  394. (if (>= emacs-major-version 26)
  395. (define-common-lisp-style "basic"
  396. "This style merely gives all identation variables their default values,
  397. making it easy to create new styles that are proof against user
  398. customizations. It also adjusts comment indentation from default.
  399. All other predefined modes inherit from basic."
  400. (:inherit "basic-emacs26"))
  401. (define-common-lisp-style "basic"
  402. "This style merely gives all identation variables their default values,
  403. making it easy to create new styles that are proof against user
  404. customizations. It also adjusts comment indentation from default.
  405. All other predefined modes inherit from basic."
  406. (:inherit "basic-emacs25")))
  407. (define-common-lisp-style "classic"
  408. "This style of indentation emulates the most striking features of 1995
  409. vintage cl-indent.el once included as part of Slime: IF indented by two
  410. spaces, and CASE clause bodies indentented more deeply than the keys."
  411. (:inherit "basic")
  412. (:variables
  413. (lisp-lambda-list-keyword-parameter-indentation 0))
  414. (:indentation
  415. (case (4 &rest (&whole 2 &rest 3)))
  416. (if (4 2 2))))
  417. (define-common-lisp-style "modern"
  418. "A good general purpose style. Turns on lambda-list keyword and keyword
  419. parameter alignment, and turns subclause aware loop indentation off.
  420. (Loop indentation so because simpler style is more prevalent in existing
  421. sources, not because it is necessarily preferred.)"
  422. (:inherit "basic")
  423. (:variables
  424. (lisp-lambda-list-keyword-alignment t)
  425. (lisp-lambda-list-keyword-parameter-alignment t)
  426. (lisp-lambda-list-keyword-parameter-indentation 0)
  427. (lisp-loop-indent-subclauses nil)))
  428. (define-common-lisp-style "sbcl"
  429. "Style used in SBCL sources. A good if somewhat intrusive general purpose
  430. style based on the \"modern\" style. Adds indentation for a few SBCL
  431. specific constructs, sets indentation to use spaces instead of tabs,
  432. fill-column to 78, and activates whitespace-mode to show tabs and trailing
  433. whitespace."
  434. (:inherit "modern")
  435. (:eval
  436. (whitespace-mode 1))
  437. (:variables
  438. (whitespace-style (tabs trailing))
  439. (indent-tabs-mode nil)
  440. (comment-fill-column nil)
  441. (fill-column 78))
  442. (:indentation
  443. (def!constant (as defconstant))
  444. (def!macro (as defmacro))
  445. (def!method (as defmethod))
  446. (def!struct (as defstruct))
  447. (def!type (as deftype))
  448. (defmacro-mundanely (as defmacro))
  449. (define-source-transform (as defun))
  450. (!def-type-translator (as defun))
  451. (!def-debug-command (as defun))))
  452. (defcustom common-lisp-style-default nil
  453. "Name of the Common Lisp indentation style to use in lisp-mode buffers if
  454. none has been specified."
  455. :type `(choice (const :tag "None" nil)
  456. ,@(mapcar (lambda (spec)
  457. `(const :tag ,(car spec) ,(car spec)))
  458. (common-lisp-style-names))
  459. (string :tag "Other"))
  460. :group 'lisp-indent)
  461. ;;; If style is being used, that's a sufficient invitation to snag
  462. ;;; the indentation function.
  463. (defun common-lisp-lisp-mode-hook ()
  464. (let ((style (or common-lisp-style common-lisp-style-default)))
  465. (when style
  466. (set (make-local-variable 'lisp-indent-function)
  467. 'common-lisp-indent-function)
  468. (common-lisp-set-style style))))
  469. (add-hook 'lisp-mode-hook 'common-lisp-lisp-mode-hook)
  470. ;;;; The indentation specs are stored at three levels. In order of priority:
  471. ;;;;
  472. ;;;; 1. Indentation as set by current style, from the indentation table
  473. ;;;; in the current style.
  474. ;;;;
  475. ;;;; 2. Globally set indentation, from the `common-lisp-indent-function'
  476. ;;;; property of the symbol.
  477. ;;;;
  478. ;;;; 3. Per-package indentation derived by the system. A live Common Lisp
  479. ;;;; system may (via Slime, eg.) add indentation specs to
  480. ;;;; common-lisp-system-indentation, where they are associated with
  481. ;;;; the package of the symbol. Then we run some lossy heuristics and
  482. ;;;; find something that looks promising.
  483. ;;;;
  484. ;;;; FIXME: for non-system packages the derived indentation should probably
  485. ;;;; take precedence.
  486. ;;; This maps symbols into lists of (INDENT . PACKAGES) where INDENT is
  487. ;;; an indentation spec, and PACKAGES are the names of packages where this
  488. ;;; applies.
  489. ;;;
  490. ;;; We never add stuff here by ourselves: this is for things like Slime to
  491. ;;; fill.
  492. (defvar common-lisp-system-indentation (make-hash-table :test 'equal))
  493. (defun common-lisp-guess-current-package ()
  494. (let (pkg)
  495. (save-excursion
  496. (ignore-errors
  497. (when (let ((case-fold-search t))
  498. (search-backward "(in-package "))
  499. (re-search-forward "[ :\"]+")
  500. (let ((start (point)))
  501. (re-search-forward "[\":)]")
  502. (setf pkg (upcase (buffer-substring-no-properties
  503. start (1- (point)))))))))
  504. pkg))
  505. (defvar common-lisp-current-package-function 'common-lisp-guess-current-package
  506. "Used to derive the package name to use for indentation at a
  507. given point. Defaults to `common-lisp-guess-current-package'.")
  508. (defun common-lisp-symbol-package (string)
  509. (if (and (stringp string) (string-match ":" string))
  510. (let ((p (match-beginning 0)))
  511. (if (eql 0 p)
  512. "KEYWORD"
  513. (upcase (substring string 0 p))))
  514. (funcall common-lisp-current-package-function)))
  515. (defun common-lisp-get-indentation (name &optional full)
  516. "Retrieves the indentation information for NAME."
  517. (let ((method
  518. (or
  519. ;; From style
  520. (when common-lisp-style
  521. (gethash name (common-lisp-active-style-methods)))
  522. ;; From global settings.
  523. (get name 'common-lisp-indent-function)
  524. ;; From system derived information.
  525. (let ((system-info (gethash name common-lisp-system-indentation)))
  526. (if (not (cdr system-info))
  527. (caar system-info)
  528. (let ((guess nil)
  529. (guess-n 0)
  530. (package (common-lisp-symbol-package full)))
  531. (dolist (info system-info guess)
  532. (let* ((pkgs (cdr info))
  533. (n (length pkgs)))
  534. (cond ((member package pkgs)
  535. ;; This is it.
  536. (return (car info)))
  537. ((> n guess-n)
  538. ;; If we can't find the real thing, go with the one
  539. ;; accessible in most packages.
  540. (setf guess (car info)
  541. guess-n n)))))))))))
  542. (if (and (consp method) (eq 'as (car method)))
  543. (common-lisp-get-indentation (cadr method))
  544. method)))
  545. ;;;; LOOP indentation, the simple version
  546. (defun common-lisp-loop-type (loop-start)
  547. "Returns the type of the loop form at LOOP-START.
  548. Possible types are SIMPLE, SIMPLE/SPLIT, EXTENDED, and EXTENDED/SPLIT. */SPLIT
  549. refers to extended loops whose body does not start on the same line as the
  550. opening parenthesis of the loop."
  551. (let (comment-split)
  552. (condition-case ()
  553. (save-excursion
  554. (goto-char loop-start)
  555. (let ((line (line-number-at-pos))
  556. (maybe-split t))
  557. (forward-char 1)
  558. (forward-sexp 1)
  559. (save-excursion
  560. (when (looking-at "\\s-*\\\n*;")
  561. (search-forward ";")
  562. (backward-char 1)
  563. (if (= line (line-number-at-pos))
  564. (setq maybe-split nil)
  565. (setq comment-split t))))
  566. (forward-sexp 1)
  567. (backward-sexp 1)
  568. (if (eql (char-after) ?\()
  569. (if (or (not maybe-split) (= line (line-number-at-pos)))
  570. 'simple
  571. 'simple/split)
  572. (if (or (not maybe-split) (= line (line-number-at-pos)))
  573. 'extended
  574. 'extended/split))))
  575. (error
  576. (if comment-split
  577. 'simple/split
  578. 'simple)))))
  579. (defun common-lisp-trailing-comment ()
  580. (ignore-errors
  581. ;; If we had a trailing comment just before this, find it.
  582. (save-excursion
  583. (backward-sexp)
  584. (forward-sexp)
  585. (when (looking-at "\\s-*;")
  586. (search-forward ";")
  587. (1- (current-column))))))
  588. ;;;###autoload
  589. (defun common-lisp-indent-function (indent-point state)
  590. "Function to indent the arguments of a Lisp function call.
  591. This is suitable for use as the value of the variable
  592. `lisp-indent-function'. INDENT-POINT is the point at which the
  593. indentation function is called, and STATE is the
  594. `parse-partial-sexp' state at that position. Browse the
  595. `lisp-indent' customize group for options affecting the behavior
  596. of this function.
  597. If the indentation point is in a call to a Lisp function, that
  598. function's common-lisp-indent-function property specifies how
  599. this function should indent it. Possible values for this
  600. property are:
  601. * defun, meaning indent according to `lisp-indent-defun-method';
  602. i.e., like (4 &lambda &body), as explained below.
  603. * any other symbol, meaning a function to call. The function should
  604. take the arguments: PATH STATE INDENT-POINT SEXP-COLUMN NORMAL-INDENT.
  605. PATH is a list of integers describing the position of point in terms of
  606. list-structure with respect to the containing lists. For example, in
  607. ((a b c (d foo) f) g), foo has a path of (0 3 1). In other words,
  608. to reach foo take the 0th element of the outermost list, then
  609. the 3rd element of the next list, and finally the 1st element.
  610. STATE and INDENT-POINT are as in the arguments to
  611. `common-lisp-indent-function'. SEXP-COLUMN is the column of
  612. the open parenthesis of the innermost containing list.
  613. NORMAL-INDENT is the column the indentation point was
  614. originally in. This function should behave like `lisp-indent-259'.
  615. * an integer N, meaning indent the first N arguments like
  616. function arguments, and any further arguments like a body.
  617. This is equivalent to (4 4 ... &body).
  618. * a list starting with `as' specifies an indirection: indentation is done as
  619. if the form being indented had started with the second element of the list.
  620. * any other list. The list element in position M specifies how to indent the
  621. Mth function argument. If there are fewer elements than function arguments,
  622. the last list element applies to all remaining arguments. The accepted list
  623. elements are:
  624. * nil, meaning the default indentation.
  625. * an integer, specifying an explicit indentation.
  626. * &lambda. Indent the argument (which may be a list) by 4.
  627. * &rest. When used, this must be the penultimate element. The
  628. element after this one applies to all remaining arguments.
  629. * &body. This is equivalent to &rest lisp-body-indent, i.e., indent
  630. all remaining elements by `lisp-body-indent'.
  631. * &whole. This must be followed by nil, an integer, or a
  632. function symbol. This indentation is applied to the
  633. associated argument, and as a base indent for all remaining
  634. arguments. For example, an integer P means indent this
  635. argument by P, and all remaining arguments by P, plus the
  636. value specified by their associated list element.
  637. * a symbol. A function to call, with the 6 arguments specified above.
  638. * a list, with elements as described above. This applies when the
  639. associated function argument is itself a list. Each element of the list
  640. specifies how to indent the associated argument.
  641. For example, the function `case' has an indent property
  642. \(4 &rest (&whole 2 &rest 1)), meaning:
  643. * indent the first argument by 4.
  644. * arguments after the first should be lists, and there may be any number
  645. of them. The first list element has an offset of 2, all the rest
  646. have an offset of 2+1=3."
  647. (common-lisp-indent-function-1 indent-point state))
  648. ;;; XEmacs doesn't have looking-back, so we define a simple one. Faster to
  649. ;;; boot, and sufficient for our needs.
  650. (defun common-lisp-looking-back (string)
  651. (let ((len (length string)))
  652. (dotimes (i len t)
  653. (unless (eql (elt string (- len i 1)) (char-before (- (point) i)))
  654. (return nil)))))
  655. (defvar common-lisp-feature-expr-regexp "#!?\\(+\\|-\\)")
  656. ;;; Semi-feature-expression aware keyword check.
  657. (defun common-lisp-looking-at-keyword ()
  658. (or (looking-at ":")
  659. (and (looking-at common-lisp-feature-expr-regexp)
  660. (save-excursion
  661. (forward-sexp)
  662. (skip-chars-forward " \t\n")
  663. (common-lisp-looking-at-keyword)))))
  664. ;;; Semi-feature-expression aware backwards movement for keyword
  665. ;;; argument pairs.
  666. (defun common-lisp-backward-keyword-argument ()
  667. (ignore-errors
  668. (backward-sexp 2)
  669. (when (looking-at common-lisp-feature-expr-regexp)
  670. (cond ((ignore-errors
  671. (save-excursion
  672. (backward-sexp 2)
  673. (looking-at common-lisp-feature-expr-regexp)))
  674. (common-lisp-backward-keyword-argument))
  675. ((ignore-errors
  676. (save-excursion
  677. (backward-sexp 1)
  678. (looking-at ":")))
  679. (backward-sexp))))
  680. t))
  681. (defun common-lisp-indent-function-1 (indent-point state)
  682. ;; If we're looking at a splice, move to the first comma.
  683. (when (or (common-lisp-looking-back ",") (common-lisp-looking-back ",@"))
  684. (when (re-search-backward "[^,@'],")
  685. (forward-char 1)))
  686. (let ((normal-indent (current-column)))
  687. ;; Walk up list levels until we see something
  688. ;; which does special things with subforms.
  689. (let ((depth 0)
  690. ;; Path describes the position of point in terms of
  691. ;; list-structure with respect to containing lists.
  692. ;; `foo' has a path of (0 3 1) in `((a b c (d foo) f) g)'.
  693. (path ())
  694. ;; set non-nil when somebody works out the indentation to use
  695. calculated
  696. ;; If non-nil, this is an indentation to use
  697. ;; if nothing else specifies it more firmly.
  698. tentative-calculated
  699. (last-point indent-point)
  700. ;; the position of the open-paren of the innermost containing list
  701. (containing-form-start (common-lisp-indent-parse-state-start state))
  702. ;; the column of the above
  703. sexp-column)
  704. ;; Move to start of innermost containing list
  705. (goto-char containing-form-start)
  706. (setq sexp-column (current-column))
  707. ;; Look over successively less-deep containing forms
  708. (while (and (not calculated)
  709. (< depth lisp-indent-maximum-backtracking))
  710. (let ((containing-sexp (point)))
  711. (forward-char 1)
  712. (parse-partial-sexp (point) indent-point 1 t)
  713. ;; Move to the car of the relevant containing form
  714. (let (tem full function method tentative-defun)
  715. (if (not (looking-at "\\sw\\|\\s_"))
  716. ;; This form doesn't seem to start with a symbol
  717. (setq function nil method nil full nil)
  718. (setq tem (point))
  719. (forward-sexp 1)
  720. (setq full (downcase (buffer-substring-no-properties
  721. tem (point)))
  722. function full)
  723. (goto-char tem)
  724. (setq tem (intern-soft function)
  725. method (common-lisp-get-indentation tem))
  726. (cond ((and (null method)
  727. (string-match ":[^:]+" function))
  728. ;; The pleblisp package feature
  729. (setq function (substring function
  730. (1+ (match-beginning 0)))
  731. method (common-lisp-get-indentation
  732. (intern-soft function) full)))
  733. ((and (null method))
  734. ;; backwards compatibility
  735. (setq method (common-lisp-get-indentation tem)))))
  736. (let ((n 0))
  737. ;; How far into the containing form is the current form?
  738. (if (< (point) indent-point)
  739. (while (condition-case ()
  740. (progn
  741. (forward-sexp 1)
  742. (if (>= (point) indent-point)
  743. nil
  744. (parse-partial-sexp (point)
  745. indent-point 1 t)
  746. (setq n (1+ n))
  747. t))
  748. (error nil))))
  749. (setq path (cons n path)))
  750. ;; Guess.
  751. (when (and (not method) function (null (cdr path)))
  752. ;; (package prefix was stripped off above)
  753. (cond ((and (string-match "\\`def" function)
  754. (not (string-match "\\`default" function))
  755. (not (string-match "\\`definition" function))
  756. (not (string-match "\\`definer" function)))
  757. (setq tentative-defun t))
  758. ((string-match
  759. (eval-when-compile
  760. (concat "\\`\\("
  761. (regexp-opt '("with" "without" "do"))
  762. "\\)-"))
  763. function)
  764. (setq method '(&lambda &body)))))
  765. ;; #+ and #- cleverness.
  766. (save-excursion
  767. (goto-char indent-point)
  768. (backward-sexp)
  769. (let ((indent (current-column)))
  770. (when (or (looking-at common-lisp-feature-expr-regexp)
  771. (ignore-errors
  772. (backward-sexp)
  773. (when (looking-at
  774. common-lisp-feature-expr-regexp)
  775. (setq indent (current-column))
  776. (let ((line (line-number-at-pos)))
  777. (while
  778. (ignore-errors
  779. (backward-sexp 2)
  780. (and
  781. (= line (line-number-at-pos))
  782. (looking-at
  783. common-lisp-feature-expr-regexp)))
  784. (setq indent (current-column))))
  785. t)))
  786. (setq calculated (list indent containing-form-start)))))
  787. (cond ((and (or (eq (char-after (1- containing-sexp)) ?\')
  788. (and (not lisp-backquote-indentation)
  789. (eq (char-after (1- containing-sexp)) ?\`)))
  790. (not (eq (char-after (- containing-sexp 2)) ?\#)))
  791. ;; No indentation for "'(...)" elements
  792. (setq calculated (1+ sexp-column)))
  793. ((eq (char-after (1- containing-sexp)) ?\#)
  794. ;; "#(...)"
  795. (setq calculated (1+ sexp-column)))
  796. ((null method)
  797. ;; If this looks like a call to a `def...' form,
  798. ;; think about indenting it as one, but do it
  799. ;; tentatively for cases like
  800. ;; (flet ((defunp ()
  801. ;; nil)))
  802. ;; Set both normal-indent and tentative-calculated.
  803. ;; The latter ensures this value gets used
  804. ;; if there are no relevant containing constructs.
  805. ;; The former ensures this value gets used
  806. ;; if there is a relevant containing construct
  807. ;; but we are nested within the structure levels
  808. ;; that it specifies indentation for.
  809. (if tentative-defun
  810. (setq tentative-calculated
  811. (common-lisp-indent-call-method
  812. function lisp-indent-defun-method
  813. path state indent-point
  814. sexp-column normal-indent)
  815. normal-indent tentative-calculated)
  816. (when lisp-align-keywords-in-calls
  817. ;; No method so far. If we're looking at a keyword,
  818. ;; align with the first keyword in this expression.
  819. ;; This gives a reasonable indentation to most things
  820. ;; with keyword arguments.
  821. (save-excursion
  822. (goto-char indent-point)
  823. (back-to-indentation)
  824. (when (common-lisp-looking-at-keyword)
  825. (while (common-lisp-backward-keyword-argument)
  826. (when (common-lisp-looking-at-keyword)
  827. (setq calculated
  828. (list (current-column)
  829. containing-form-start)))))))))
  830. ((integerp method)
  831. ;; convenient top-level hack.
  832. ;; (also compatible with lisp-indent-function)
  833. ;; The number specifies how many `distinguished'
  834. ;; forms there are before the body starts
  835. ;; Equivalent to (4 4 ... &body)
  836. (setq calculated (cond ((cdr path)
  837. normal-indent)
  838. ((<= (car path) method)
  839. ;; `distinguished' form
  840. (list (+ sexp-column 4)
  841. containing-form-start))
  842. ((= (car path) (1+ method))
  843. ;; first body form.
  844. (+ sexp-column lisp-body-indent))
  845. (t
  846. ;; other body form
  847. normal-indent))))
  848. (t
  849. (setq calculated
  850. (common-lisp-indent-call-method
  851. function method path state indent-point
  852. sexp-column normal-indent)))))
  853. (goto-char containing-sexp)
  854. (setq last-point containing-sexp)
  855. (unless calculated
  856. (condition-case ()
  857. (progn (backward-up-list 1)
  858. (setq depth (1+ depth)))
  859. (error
  860. (setq depth lisp-indent-maximum-backtracking))))))
  861. (or calculated tentative-calculated
  862. ;; Fallback.
  863. ;;
  864. ;; Instead of punting directly to calculate-lisp-indent we
  865. ;; handle a few of cases it doesn't deal with:
  866. ;;
  867. ;; A: (foo (
  868. ;; bar zot
  869. ;; quux))
  870. ;;
  871. ;; would align QUUX with ZOT.
  872. ;;
  873. ;; B:
  874. ;; (foo (or x
  875. ;; y) t
  876. ;; z)
  877. ;;
  878. ;; would align the Z with Y.
  879. ;;
  880. ;; C:
  881. ;; (foo ;; Comment
  882. ;; (bar)
  883. ;; ;; Comment 2
  884. ;; (quux))
  885. ;;
  886. ;; would indent BAR and QUUX by one.
  887. (ignore-errors
  888. (save-excursion
  889. (goto-char indent-point)
  890. (back-to-indentation)
  891. (let ((p (point)))
  892. (goto-char containing-form-start)
  893. (down-list)
  894. (let ((one (current-column)))
  895. (skip-chars-forward " \t")
  896. (if (or (eolp) (looking-at ";"))
  897. ;; A.
  898. (list one containing-form-start)
  899. (forward-sexp 2)
  900. (backward-sexp)
  901. (if (/= p (point))
  902. ;; B.
  903. (list (current-column) containing-form-start)
  904. (backward-sexp)
  905. (forward-sexp)
  906. (let ((tmp (+ (current-column) 1)))
  907. (skip-chars-forward " \t")
  908. (if (looking-at ";")
  909. ;; C.
  910. (list tmp containing-form-start)))))))))))))
  911. (defun common-lisp-indent-call-method (function method path state indent-point
  912. sexp-column normal-indent)
  913. (let ((lisp-indent-error-function function))
  914. (if (symbolp method)
  915. (funcall method
  916. path state indent-point
  917. sexp-column normal-indent)
  918. (lisp-indent-259 method path state indent-point
  919. sexp-column normal-indent))))
  920. ;; Dynamically bound in common-lisp-indent-call-method.
  921. (defvar lisp-indent-error-function)
  922. (defun lisp-indent-report-bad-format (m)
  923. (error "%s has a badly-formed %s property: %s"
  924. ;; Love those free variable references!!
  925. lisp-indent-error-function 'common-lisp-indent-function m))
  926. ;; Lambda-list indentation is now done in LISP-INDENT-LAMBDA-LIST.
  927. ;; See also `lisp-lambda-list-keyword-alignment',
  928. ;; `lisp-lambda-list-keyword-parameter-alignment' and
  929. ;; `lisp-lambda-list-keyword-parameter-indentation' -- dvl
  930. (defvar lisp-indent-lambda-list-keywords-regexp
  931. "&\\(\
  932. optional\\|rest\\|key\\|allow-other-keys\\|aux\\|whole\\|body\\|\
  933. environment\\|more\
  934. \\)\\>"
  935. "Regular expression matching lambda-list keywords.")
  936. (defun lisp-indent-lambda-list
  937. (indent-point sexp-column containing-form-start)
  938. (if (not lisp-lambda-list-indentation)
  939. (1+ sexp-column)
  940. (lisp-properly-indent-lambda-list
  941. indent-point sexp-column containing-form-start)))
  942. (defun lisp-properly-indent-lambda-list
  943. (indent-point sexp-column containing-form-start)
  944. (let (limit)
  945. (cond
  946. ((save-excursion
  947. (goto-char indent-point)
  948. (back-to-indentation)
  949. (setq limit (point))
  950. (looking-at lisp-indent-lambda-list-keywords-regexp))
  951. ;; We're facing a lambda-list keyword.
  952. (if lisp-lambda-list-keyword-alignment
  953. ;; Align to the first keyword if any, or to the beginning of
  954. ;; the lambda-list.
  955. (save-excursion
  956. (goto-char containing-form-start)
  957. (down-list)
  958. (let ((key-indent nil)
  959. (next t))
  960. (while (and next (< (point) indent-point))
  961. (if (looking-at lisp-indent-lambda-list-keywords-regexp)
  962. (setq key-indent (current-column)
  963. next nil)
  964. (setq next (ignore-errors (forward-sexp) t))
  965. (if next
  966. (ignore-errors
  967. (forward-sexp)
  968. (backward-sexp)))))
  969. (or key-indent
  970. (1+ sexp-column))))
  971. ;; Align to the beginning of the lambda-list.
  972. (1+ sexp-column)))
  973. (t
  974. ;; Otherwise, align to the first argument of the last lambda-list
  975. ;; keyword, the keyword itself, or the beginning of the
  976. ;; lambda-list.
  977. (save-excursion
  978. (goto-char indent-point)
  979. (let ((indent nil)
  980. (next t))
  981. (while (and next (> (point) containing-form-start))
  982. (setq next (ignore-errors (backward-sexp) t))
  983. (let* ((col (current-column))
  984. (pos
  985. (save-excursion
  986. (ignore-errors (forward-sexp))
  987. (skip-chars-forward " \t")
  988. (if (eolp)
  989. (+ col
  990. lisp-lambda-list-keyword-parameter-indentation)
  991. col))))
  992. (if (looking-at lisp-indent-lambda-list-keywords-regexp)
  993. (setq indent
  994. (if lisp-lambda-list-keyword-parameter-alignment
  995. (or indent pos)
  996. (+ col
  997. lisp-lambda-list-keyword-parameter-indentation))
  998. next nil)
  999. (setq indent col))))
  1000. (or indent (1+ sexp-column))))))))
  1001. (defun common-lisp-lambda-list-initial-value-form-p (point)
  1002. (let ((state 'x)
  1003. (point (save-excursion
  1004. (goto-char point)
  1005. (back-to-indentation)
  1006. (point))))
  1007. (save-excursion
  1008. (backward-sexp)
  1009. (ignore-errors (down-list 1))
  1010. (while (and point (< (point) point))
  1011. (cond ((or (looking-at "&key") (looking-at "&optional")
  1012. (looking-at "&aux"))
  1013. (setq state 'key))
  1014. ((looking-at lisp-indent-lambda-list-keywords-regexp)
  1015. (setq state 'x)))
  1016. (if (not (ignore-errors (forward-sexp) t))
  1017. (setq point nil)
  1018. (ignore-errors
  1019. (forward-sexp)
  1020. (backward-sexp))
  1021. (cond ((> (point) point)
  1022. (backward-sexp)
  1023. (when (eq state 'var)
  1024. (setq state 'x))
  1025. (or (ignore-errors
  1026. (down-list 1)
  1027. (cond ((> (point) point)
  1028. (backward-up-list))
  1029. ((eq 'key state)
  1030. (setq state 'var)))
  1031. t)
  1032. (setq point nil)))
  1033. ((eq state 'var)
  1034. (setq state 'form))))))
  1035. (eq 'form state)))
  1036. ;; Blame the crufty control structure on dynamic scoping
  1037. ;; -- not on me!
  1038. (defun lisp-indent-259
  1039. (method path state indent-point sexp-column normal-indent)
  1040. (catch 'exit
  1041. (let* ((p (cdr path))
  1042. (containing-form-start (elt state 1))
  1043. (n (1- (car path)))
  1044. tem tail)
  1045. (if (not (consp method))
  1046. (lisp-indent-report-bad-format method))
  1047. (while n
  1048. ;; This while loop is for advancing along a method
  1049. ;; until the relevant (possibly &rest/&body) pattern
  1050. ;; is reached.
  1051. ;; n is set to (1- n) and method to (cdr method)
  1052. ;; each iteration.
  1053. (setq tem (car method))
  1054. (or (eq tem 'nil) ;default indentation
  1055. (eq tem '&lambda) ;lambda list
  1056. (and (eq tem '&body) (null (cdr method)))
  1057. (and (eq tem '&rest)
  1058. (consp (cdr method))
  1059. (null (cddr method)))
  1060. (integerp tem) ;explicit indentation specified
  1061. (and (consp tem) ;destructuring
  1062. (or (consp (car tem))
  1063. (and (eq (car tem) '&whole)
  1064. (or (symbolp (cadr tem))
  1065. (integerp (cadr tem))))))
  1066. (and (symbolp tem) ;a function to call to do the work.
  1067. (null (cdr method)))
  1068. (lisp-indent-report-bad-format method))
  1069. (cond ((eq tem '&body)
  1070. ;; &body means (&rest <lisp-body-indent>)
  1071. (throw 'exit
  1072. (if (null p)
  1073. (+ sexp-column lisp-body-indent)
  1074. normal-indent)))
  1075. ((eq tem '&rest)
  1076. ;; this pattern holds for all remaining forms
  1077. (setq tail (> n 0)
  1078. n 0
  1079. method (cdr method)))
  1080. ((> n 0)
  1081. ;; try next element of pattern
  1082. (setq n (1- n)
  1083. method (cdr method))
  1084. (if (< n 0)
  1085. ;; Too few elements in pattern.
  1086. (throw 'exit normal-indent)))
  1087. ((eq tem 'nil)
  1088. (throw 'exit (if (consp normal-indent)
  1089. normal-indent
  1090. (list normal-indent containing-form-start))))
  1091. ((eq tem '&lambda)
  1092. (throw 'exit
  1093. (cond ((not (common-lisp-looking-back ")"))
  1094. ;; If it's not a list at all, indent it
  1095. ;; like body instead.
  1096. (if (null p)
  1097. (+ sexp-column lisp-body-indent)
  1098. normal-indent))
  1099. ((common-lisp-lambda-list-initial-value-form-p
  1100. indent-point)
  1101. (if (consp normal-indent)
  1102. normal-indent
  1103. (list normal-indent containing-form-start)))
  1104. ((null p)
  1105. (list (+ sexp-column 4) containing-form-start))
  1106. (t
  1107. ;; Indentation within a lambda-list. -- dvl
  1108. (list (lisp-indent-lambda-list
  1109. indent-point
  1110. sexp-column
  1111. containing-form-start)
  1112. containing-form-start)))))
  1113. ((integerp tem)
  1114. (throw 'exit
  1115. (if (null p) ;not in subforms
  1116. (list (+ sexp-column tem) containing-form-start)
  1117. normal-indent)))
  1118. ((symbolp tem) ;a function to call
  1119. (throw 'exit
  1120. (funcall tem path state indent-point
  1121. sexp-column normal-indent)))
  1122. (t
  1123. ;; must be a destructing frob
  1124. (if p
  1125. ;; descend
  1126. (setq method (cddr tem)
  1127. n (car p)
  1128. p (cdr p)
  1129. tail nil)
  1130. (let ((wholep (eq '&whole (car tem))))
  1131. (setq tem (cadr tem))
  1132. (throw 'exit
  1133. (cond (tail
  1134. (if (and wholep (integerp tem)
  1135. (save-excursion
  1136. (goto-char indent-point)
  1137. (back-to-indentation)
  1138. (looking-at "\\sw")))
  1139. ;; There's a further level of
  1140. ;; destructuring, but we're looking at a
  1141. ;; word -- indent to sexp.
  1142. (+ sexp-column tem)
  1143. normal-indent))
  1144. ((not tem)
  1145. (list normal-indent
  1146. containing-form-start))
  1147. ((integerp tem)
  1148. (list (+ sexp-column tem)
  1149. containing-form-start))
  1150. (t
  1151. (funcall tem path state indent-point
  1152. sexp-column normal-indent))))))))))))
  1153. (defun lisp-indent-tagbody (path state indent-point sexp-column normal-indent)
  1154. (if (not (null (cdr path)))
  1155. normal-indent
  1156. (save-excursion
  1157. (goto-char indent-point)
  1158. (back-to-indentation)
  1159. (list (cond ((looking-at "\\sw\\|\\s_")
  1160. ;; a tagbody tag
  1161. (+ sexp-column lisp-tag-indentation))
  1162. ((integerp lisp-tag-body-indentation)
  1163. (+ sexp-column lisp-tag-body-indentation))
  1164. ((eq lisp-tag-body-indentation 't)
  1165. (condition-case ()
  1166. (progn (backward-sexp 1) (current-column))
  1167. (error (1+ sexp-column))))
  1168. (t (+ sexp-column lisp-body-indent)))
  1169. ; (cond ((integerp lisp-tag-body-indentation)
  1170. ; (+ sexp-column lisp-tag-body-indentation))
  1171. ; ((eq lisp-tag-body-indentation 't)
  1172. ; normal-indent)
  1173. ; (t
  1174. ; (+ sexp-column lisp-body-indent)))
  1175. (elt state 1)
  1176. ))))
  1177. (defun lisp-indent-do (path state indent-point sexp-column normal-indent)
  1178. (if (>= (car path) 3)
  1179. (let ((lisp-tag-body-indentation lisp-body-indent))
  1180. (funcall (function lisp-indent-tagbody)
  1181. path state indent-point sexp-column normal-indent))
  1182. (funcall (function lisp-indent-259)
  1183. '((&whole nil &rest
  1184. ;; the following causes weird indentation
  1185. ;;(&whole 1 1 2 nil)
  1186. )
  1187. (&whole nil &rest 1))
  1188. path state indent-point sexp-column normal-indent)))
  1189. (defun lisp-indent-defsetf
  1190. (path state indent-point sexp-column normal-indent)
  1191. (list
  1192. (cond
  1193. ;; Inside the lambda-list in a long-form defsetf.
  1194. ((and (eql 2 (car path)) (cdr path))
  1195. (lisp-indent-lambda-list indent-point sexp-column (elt state 1)))
  1196. ;; Long form: has a lambda-list.
  1197. ((or (cdr path)
  1198. (save-excursion
  1199. (goto-char (elt state 1))
  1200. (ignore-errors
  1201. (down-list)
  1202. (forward-sexp 3)
  1203. (backward-sexp)
  1204. (looking-at "nil\\|("))))
  1205. (+ sexp-column
  1206. (case (car path)
  1207. ((1 3) 4)
  1208. (2 4)
  1209. (t 2))))
  1210. ;; Short form.
  1211. (t
  1212. (+ sexp-column
  1213. (case (car path)
  1214. (1 4)
  1215. (2 4)
  1216. (t 2)))))
  1217. (elt state 1)))
  1218. (defun lisp-beginning-of-defmethod-qualifiers ()
  1219. (let ((regexp-1 "(defmethod\\|(DEFMETHOD")
  1220. (regexp-2 "(:method\\|(:METHOD"))
  1221. (while (and (not (or (looking-at regexp-1)
  1222. (looking-at regexp-2)))
  1223. (ignore-errors (backward-up-list) t)))
  1224. (cond ((looking-at regexp-1)
  1225. (forward-char)
  1226. ;; Skip name.
  1227. (forward-sexp 2)
  1228. 1)
  1229. ((looking-at regexp-2)
  1230. (forward-char)
  1231. (forward-sexp 1)
  1232. 0))))
  1233. ;; LISP-INDENT-DEFMETHOD now supports the presence of more than one method
  1234. ;; qualifier and indents the method's lambda list properly. -- dvl
  1235. (defun lisp-indent-defmethod
  1236. (path state indent-point sexp-column normal-indent)
  1237. (lisp-indent-259
  1238. (let ((nskip nil))
  1239. (if (save-excursion
  1240. (when (setq nskip (lisp-beginning-of-defmethod-qualifiers))
  1241. (skip-chars-forward " \t\n")
  1242. (while (looking-at "\\sw\\|\\s_")
  1243. (incf nskip)
  1244. (forward-sexp)
  1245. (skip-chars-forward " \t\n"))
  1246. t))
  1247. (append (make-list nskip 4) '(&lambda &body))
  1248. (common-lisp-get-indentation 'defun)))
  1249. path state indent-point sexp-column normal-indent))
  1250. (defun lisp-indent-function-lambda-hack (path state indent-point
  1251. sexp-column normal-indent)
  1252. ;; indent (function (lambda () <newline> <body-forms>)) kludgily.
  1253. (if (or (cdr path) ; wtf?
  1254. (> (car path) 3))
  1255. ;; line up under previous body form
  1256. normal-indent
  1257. ;; line up under function rather than under lambda in order to
  1258. ;; conserve horizontal space. (Which is what #' is for.)
  1259. (condition-case ()
  1260. (save-excursion
  1261. (backward-up-list 2)
  1262. (forward-char 1)
  1263. (if (looking-at "\\(lisp:+\\)?function\\(\\Sw\\|\\S_\\)")
  1264. (+ lisp-body-indent -1 (current-column))
  1265. (+ sexp-column lisp-body-indent)))
  1266. (error (+ sexp-column lisp-body-indent)))))
  1267. (defun lisp-indent-loop (path state indent-point sexp-column normal-indent)
  1268. (if (cdr path)
  1269. normal-indent
  1270. (let* ((loop-start (elt state 1))
  1271. (type (common-lisp-loop-type loop-start)))
  1272. (cond ((and lisp-loop-indent-subclauses
  1273. (member type '(extended extended/split)))
  1274. (list (common-lisp-indent-loop-macro-1 state indent-point)
  1275. (common-lisp-indent-parse-state-start state)))
  1276. (t
  1277. (common-lisp-loop-part-indentation indent-point state type))))))
  1278. ;;;; LOOP indentation, the complex version -- handles subclause indentation
  1279. ;; Regexps matching various varieties of loop macro keyword ...
  1280. (defvar common-lisp-body-introducing-loop-macro-keyword
  1281. "\\(#?:\\)?\\(do\\(ing\\)?\\|finally\\|initially\\)"
  1282. "Regexp matching loop macro keywords which introduce body forms.")
  1283. ;; Not currenctly used
  1284. (defvar common-lisp-accumlation-loop-macro-keyword
  1285. "\\(#?:\\)?\\(collect\\(ing\\)?\\|append\\(ing\\)?\\|nconc\\(ing\\)?\\|\
  1286. count\\(ing\\)?\\|sum\\(ming\\)?\\|maximiz\\(e\\|ing\\)\\|\
  1287. minimiz\\(e\\|ing\\)\\)"
  1288. "Regexp matching loop macro keywords which introduce accumulation clauses.")
  1289. ;; This is so "and when" and "else when" get handled right
  1290. ;; (not to mention "else do" !!!)
  1291. (defvar common-lisp-prefix-loop-macro-keyword
  1292. "\\(#?:\\)?\\(and\\|else\\)"
  1293. "Regexp matching loop macro keywords which are prefixes.")
  1294. (defvar common-lisp-indent-clause-joining-loop-macro-keyword
  1295. "\\(#?:\\)?and"
  1296. "Regexp matching 'and', and anything else there ever comes to be like it.")
  1297. (defvar common-lisp-indent-indented-loop-macro-keyword
  1298. "\\(#?:\\)?\\(\\(up\\|down\\)?(from\\|to)\\|below\\|above\\|in\\(to\\)?\\|\
  1299. on\\|=\\|then\\|across\\|being\\|each\\|the\\|of\\|using\\|\
  1300. \\(present-\\|external-\\)?symbols?\\|fixnum\\|float\\|t\\|nil\\|of-type\\)"
  1301. "Regexp matching keywords introducing loop subclauses.
  1302. Always indented two.")
  1303. (defvar common-lisp-indenting-loop-macro-keyword
  1304. "\\(#?:\\)?\\(when\\|unless\\|if\\)"
  1305. "Regexp matching keywords introducing conditional clauses.
  1306. Cause subsequent clauses to be indented.")
  1307. (defvar common-lisp-loop-macro-else-keyword "\\(#?:\\)?else")
  1308. ;;; Attempt to indent the loop macro ...
  1309. (defun common-lisp-indent-parse-state-depth (parse-state)
  1310. (car parse-state))
  1311. (defun common-lisp-indent-parse-state-start (parse-state)
  1312. (car (cdr parse-state)))
  1313. (defun common-lisp-indent-parse-state-prev (parse-state)
  1314. (car (cdr (cdr parse-state))))
  1315. (defun common-lisp-loop-part-indentation (indent-point state type)
  1316. "Compute the indentation of loop form constituents."
  1317. (let* ((loop-start (elt state 1))
  1318. (loop-indentation (save-excursion
  1319. (goto-char loop-start)
  1320. (if (eq type 'extended/split)
  1321. (- (current-column) 4)
  1322. (current-column))))
  1323. (indent nil)
  1324. (re "\\(\\(#?:\\)?\\sw+\\|)\\|\n\\)"))
  1325. (goto-char indent-point)
  1326. (back-to-indentation)
  1327. (cond ((eq type 'simple/split)
  1328. (+ loop-indentation lisp-simple-loop-indentation))
  1329. ((eq type 'simple)
  1330. (+ loop-indentation 6))
  1331. ;; We are already in a body, with forms in it.
  1332. ((and (not (looking-at re))
  1333. (save-excursion
  1334. (while (and (ignore-errors (backward-sexp) t)
  1335. (not (looking-at re)))
  1336. (setq indent (current-column)))
  1337. (when (and indent
  1338. (looking-at
  1339. common-lisp-body-introducing-loop-macro-keyword))
  1340. t)))
  1341. (list indent loop-start))
  1342. ;; Keyword-style or comment outside body
  1343. ((or lisp-loop-indent-forms-like-keywords
  1344. (looking-at re)
  1345. (looking-at ";"))
  1346. (if (and (looking-at ";")
  1347. (let ((p (common-lisp-trailing-comment)))
  1348. (when p
  1349. (setq loop-indentation p))))
  1350. (list loop-indentation loop-start)
  1351. (list (+ loop-indentation 6) loop-start)))
  1352. ;; Form-style
  1353. (t
  1354. (list (+ loop-indentation 9) loop-start)))))
  1355. (defun common-lisp-indent-loop-macro-1 (parse-state indent-point)
  1356. (catch 'return-indentation
  1357. (save-excursion
  1358. ;; Find first clause of loop macro, and use it to establish
  1359. ;; base column for indentation
  1360. (goto-char (common-lisp-indent-parse-state-start parse-state))
  1361. (let ((loop-start-column (current-column)))
  1362. (common-lisp-loop-advance-past-keyword-on-line)
  1363. (when (eolp)
  1364. (forward-line 1)
  1365. (end-of-line)
  1366. ;; If indenting first line after "(loop <newline>"
  1367. ;; cop out ...
  1368. (if (<= indent-point (point))
  1369. (throw 'return-indentation (+ lisp-loop-clauses-indentation
  1370. loop-start-column)))
  1371. (back-to-indentation))
  1372. (let* ((case-fold-search t)
  1373. (loop-macro-first-clause (point))
  1374. (previous-expression-start
  1375. (common-lisp-indent-parse-state-prev parse-state))
  1376. (default-value (current-column))
  1377. (loop-body-p nil)
  1378. (loop-body-indentation nil)
  1379. (indented-clause-indentation (+ 2 default-value)))
  1380. ;; Determine context of this loop clause, starting with the
  1381. ;; expression immediately preceding the line we're trying to indent
  1382. (goto-char previous-expression-start)
  1383. ;; Handle a body-introducing-clause which ends a line specially.
  1384. (if (looking-at common-lisp-body-introducing-loop-macro-keyword)
  1385. (let ((keyword-position (current-column)))
  1386. (setq loop-body-p t)
  1387. (setq loop-body-indentation
  1388. (if (common-lisp-loop-advance-past-keyword-on-line)
  1389. (current-column)
  1390. (back-to-indentation)
  1391. (if (/= (current-column) keyword-position)
  1392. (+ 2 (current-column))
  1393. (+ lisp-loop-body-forms-indentation
  1394. (if lisp-loop-indent-body-forms-relative-to-loop-start
  1395. loop-start-column
  1396. keyword-position))))))
  1397. (back-to-indentation)
  1398. (if (< (point) loop-macro-first-clause)
  1399. (goto-char loop-macro-first-clause))
  1400. ;; If there's an "and" or "else," advance over it.
  1401. ;; If it is alone on the line, the next "cond" will treat it
  1402. ;; as if there were a "when" and indent under it ...
  1403. (let ((exit nil))
  1404. (while (and (null exit)
  1405. (looking-at common-lisp-prefix-loop-macro-keyword))
  1406. (if (null (common-lisp-loop-advance-past-keyword-on-line))
  1407. (progn (setq exit t)
  1408. (back-to-indentation)))))
  1409. ;; Found start of loop clause preceding the one we're
  1410. ;; trying to indent. Glean context ...
  1411. (cond
  1412. ((looking-at "(")
  1413. ;; We're in the middle of a clause body ...
  1414. (setq loop-body-p t)
  1415. (setq loop-body-indentation (current-column)))
  1416. ((looking-at common-lisp-body-introducing-loop-macro-keyword)
  1417. (setq loop-body-p t)
  1418. ;; Know there's something else on the line (or would
  1419. ;; have been caught above)
  1420. (common-lisp-loop-advance-past-keyword-on-line)
  1421. (setq loop-body-indentation (current-column)))
  1422. (t
  1423. (setq loop-body-p nil)
  1424. (if (or (looking-at common-lisp-indenting-loop-macro-keyword)
  1425. (looking-at common-lisp-prefix-loop-macro-keyword))
  1426. (setq default-value (+ 2 (current-column))))
  1427. (setq indented-clause-indentation (+ 2 (current-column)))
  1428. ;; We still need loop-body-indentation for "syntax errors" ...
  1429. (goto-char previous-expression-start)
  1430. (setq loop-body-indentation (current-column)))))
  1431. ;; Go to first non-blank character of the line we're trying
  1432. ;; to indent. (if none, wind up poised on the new-line ...)
  1433. (goto-char indent-point)
  1434. (back-to-indentation)
  1435. (cond
  1436. ((looking-at "(")
  1437. ;; Clause body ...
  1438. loop-body-indentation)
  1439. ((or (eolp) (looking-at ";"))
  1440. ;; Blank line. If body-p, indent as body, else indent as
  1441. ;; vanilla clause.
  1442. (if loop-body-p
  1443. loop-body-indentation
  1444. (or (and (looking-at ";") (common-lisp-trailing-comment))
  1445. default-value)))
  1446. ((looking-at common-lisp-indent-indented-loop-macro-keyword)
  1447. indented-clause-indentation)
  1448. ((looking-at common-lisp-indent-clause-joining-loop-macro-keyword)
  1449. (let ((stolen-indent-column nil))
  1450. (forward-line -1)
  1451. (while (and (null stolen-indent-column)
  1452. (> (point) loop-macro-first-clause))
  1453. (back-to-indentation)
  1454. (if (and (< (current-column) loop-body-indentation)
  1455. (looking-at "\\(#?:\\)?\\sw"))
  1456. (progn
  1457. (if (looking-at common-lisp-loop-macro-else-keyword)
  1458. (common-lisp-loop-advance-past-keyword-on-line))
  1459. (setq stolen-indent-column
  1460. (current-column)))
  1461. (forward-line -1)))
  1462. (if stolen-indent-column
  1463. stolen-indent-column
  1464. default-value)))
  1465. (t default-value)))))))
  1466. (defun common-lisp-loop-advance-past-keyword-on-line ()
  1467. (forward-word 1)
  1468. (while (and (looking-at "\\s-") (not (eolp)))
  1469. (forward-char 1))
  1470. (if (eolp)
  1471. nil
  1472. (current-column)))
  1473. ;;;; IF* is not standard, but a plague upon the land
  1474. ;;;; ...let's at least try to indent it.
  1475. (defvar common-lisp-indent-if*-keyword
  1476. "threnret\\|elseif\\|then\\|else"
  1477. "Regexp matching if* keywords")
  1478. (defun common-lisp-indent-if*
  1479. (path parse-state indent-point sexp-column normal-indent)
  1480. (list (common-lisp-indent-if*-1 parse-state indent-point)
  1481. (common-lisp-indent-parse-state-start parse-state)))
  1482. (defun common-lisp-indent-if*-1 (parse-state indent-point)
  1483. (catch 'return-indentation
  1484. (save-excursion
  1485. ;; Find first clause of if* macro, and use it to establish
  1486. ;; base column for indentation
  1487. (goto-char (common-lisp-indent-parse-state-start parse-state))
  1488. (let ((if*-start-column (current-column)))
  1489. (common-lisp-indent-if*-advance-past-keyword-on-line)
  1490. (let* ((case-fold-search t)
  1491. (if*-first-clause (point))
  1492. (previous-expression-start
  1493. (common-lisp-indent-parse-state-prev parse-state))
  1494. (default-value (current-column))
  1495. (if*-body-p nil)
  1496. (if*-body-indentation nil))
  1497. ;; Determine context of this if* clause, starting with the
  1498. ;; expression immediately preceding the line we're trying to indent
  1499. (goto-char previous-expression-start)
  1500. ;; Handle a body-introducing-clause which ends a line specially.
  1501. (back-to-indentation)
  1502. (if (< (point) if*-first-clause)
  1503. (goto-char if*-first-clause))
  1504. ;; Found start of if* clause preceding the one we're trying
  1505. ;; to indent. Glean context ...
  1506. (cond
  1507. ((looking-at common-lisp-indent-if*-keyword)
  1508. (setq if*-body-p t)
  1509. ;; Know there's something else on the line (or would
  1510. ;; have been caught above)
  1511. (common-lisp-indent-if*-advance-past-keyword-on-line)
  1512. (setq if*-body-indentation (current-column)))
  1513. ((looking-at "#'\\|'\\|(")
  1514. ;; We're in the middle of a clause body ...
  1515. (setq if*-body-p t)
  1516. (setq if*-body-indentation (current-column)))
  1517. (t
  1518. (setq if*-body-p nil)
  1519. ;; We still need if*-body-indentation for "syntax errors" ...
  1520. (goto-char previous-expression-start)
  1521. (setq if*-body-indentation (current-column))))
  1522. ;; Go to first non-blank character of the line we're trying
  1523. ;; to indent. (if none, wind up poised on the new-line ...)
  1524. (goto-char indent-point)
  1525. (back-to-indentation)
  1526. (cond
  1527. ((or (eolp) (looking-at ";"))
  1528. ;; Blank line. If body-p, indent as body, else indent as
  1529. ;; vanilla clause.
  1530. (if if*-body-p
  1531. if*-body-indentation
  1532. default-value))
  1533. ((not (looking-at common-lisp-indent-if*-keyword))
  1534. ;; Clause body ...
  1535. if*-body-indentation)
  1536. (t
  1537. (- (+ 7 if*-start-column)
  1538. (- (match-end 0) (match-beginning 0))))))))))
  1539. (defun common-lisp-indent-if*-advance-past-keyword-on-line ()
  1540. (forward-word 1)
  1541. (block move-forward
  1542. (while (and (looking-at "\\s-") (not (eolp)))
  1543. (forward-char 1)))
  1544. (if (eolp)
  1545. nil
  1546. (current-column)))
  1547. ;;;; Indentation specs for standard symbols, and a few semistandard ones.
  1548. (defun common-lisp-init-standard-indentation ()
  1549. (let ((l '((block 1)
  1550. (case (4 &rest (&whole 2 &rest 1)))
  1551. (ccase (as case))
  1552. (ecase (as case))
  1553. (typecase (as case))
  1554. (etypecase (as case))
  1555. (ctypecase (as case))
  1556. (catch 1)
  1557. (cond (&rest (&whole 2 &rest nil)))
  1558. ;; for DEFSTRUCT
  1559. (:constructor (4 &lambda))
  1560. (defvar (4 2 2))
  1561. (defclass (6 (&whole 4 &rest 1)
  1562. (&whole 2 &rest 1)
  1563. (&whole 2 &rest 1)))
  1564. (defconstant (as defvar))
  1565. (defcustom (4 2 2 2))
  1566. (defparameter (as defvar))
  1567. (defconst (as defcustom))
  1568. (define-condition (as defclass))
  1569. (define-modify-macro (4 &lambda &body))
  1570. (defsetf lisp-indent-defsetf)
  1571. (defun (4 &lambda &body))
  1572. (defgeneric (4 &lambda &body))
  1573. (define-setf-method (as defun))
  1574. (define-setf-expander (as defun))
  1575. (defmacro (as defun))
  1576. (defsubst (as defun))
  1577. (deftype (as defun))
  1578. (defmethod lisp-indent-defmethod)
  1579. (defpackage (4 2))
  1580. (defstruct ((&whole 4 &rest (&whole 2 &rest 1))
  1581. &rest (&whole 2 &rest 1)))
  1582. (destructuring-bind (&lambda 4 &body))
  1583. (do lisp-indent-do)
  1584. (do* (as do))
  1585. (dolist ((&whole 4 2 1) &body))
  1586. (dotimes (as dolist))
  1587. (eval-when 1)
  1588. (flet ((&whole 4 &rest (&whole 1 4 &lambda &body)) &body))
  1589. (labels (as flet))
  1590. (macrolet (as flet))
  1591. (generic-flet (as flet))
  1592. (generic-labels (as flet))
  1593. (handler-case (4 &rest (&whole 2 &lambda &body)))
  1594. (restart-case (as handler-case))
  1595. ;; single-else style (then and else equally indented)
  1596. (if (&rest nil))
  1597. (if* common-lisp-indent-if*)
  1598. (lambda (&lambda &rest lisp-indent-function-lambda-hack))
  1599. (let ((&whole 4 &rest (&whole 1 1 2)) &body))
  1600. (let* (as let))
  1601. (compiler-let (as let))
  1602. (handler-bind (as let))
  1603. (restart-bind (as let))
  1604. (locally 1)
  1605. (loop lisp-indent-loop)
  1606. (:method lisp-indent-defmethod) ; in `defgeneric'
  1607. (multiple-value-bind ((&whole 6 &rest 1) 4 &body))
  1608. (multiple-value-call (4 &body))
  1609. (multiple-value-prog1 1)
  1610. (multiple-value-setq (4 2))
  1611. (multiple-value-setf (as multiple-value-setq))
  1612. (named-lambda (4 &lambda &rest lisp-indent-function-lambda-hack))
  1613. (pprint-logical-block (4 2))
  1614. (print-unreadable-object ((&whole 4 1 &rest 1) &body))
  1615. ;; Combines the worst features of BLOCK, LET and TAGBODY
  1616. (prog (&lambda &rest lisp-indent-tagbody))
  1617. (prog* (as prog))
  1618. (prog1 1)
  1619. (prog2 2)
  1620. (progn 0)
  1621. (progv (4 4 &body))
  1622. (return 0)
  1623. (return-from (nil &body))
  1624. (symbol-macrolet (as let))
  1625. (tagbody lisp-indent-tagbody)
  1626. (throw 1)
  1627. (unless 1)
  1628. (unwind-protect (5 &body))
  1629. (when 1)
  1630. (with-accessors (as multiple-value-bind))
  1631. (with-compilation-unit ((&whole 4 &rest 1) &body))
  1632. (with-condition-restarts (as multiple-value-bind))
  1633. (with-output-to-string (4 2))
  1634. (with-slots (as multiple-value-bind))
  1635. (with-standard-io-syntax (2)))))
  1636. (dolist (el l)
  1637. (let* ((name (car el))
  1638. (spec (cdr el))
  1639. (indentation
  1640. (if (symbolp spec)
  1641. (error "Old style indirect indentation spec: %s" el)
  1642. (when (cdr spec)
  1643. (error "Malformed indentation specification: %s" el))
  1644. (car spec))))
  1645. (unless (symbolp name)
  1646. (error "Cannot set Common Lisp indentation of a non-symbol: %s"
  1647. name))
  1648. (put name 'common-lisp-indent-function indentation)))))
  1649. (common-lisp-init-standard-indentation)
  1650. (provide 'cl-indent)
  1651. (provide 'slime-cl-indent)
  1652. ;;; slime-cl-indent.el ends here