annotate lisp/lisp-mode.el @ 225:12579d965149 r20-4b11

Import from CVS: tag r20-4b11
author cvs
date Mon, 13 Aug 2007 10:11:40 +0200
parents 262b8bb4a523
children 0e522484dd2a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1 ;;; lisp-mode.el --- Lisp mode, and its idiosyncratic commands.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1996, 1997 Free Software Foundation, Inc.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995 Tinker Systems
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
5
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
6 ;; Maintainer: FSF
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
7 ;; Keywords: lisp, languages, dumped
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
8
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
10
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
14 ;; any later version.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
15
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
19 ;; General Public License for more details.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
20
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
24 ;; 02111-1307, USA.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
25
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
26 ;;; Synched up with: FSF 19.34 (but starting to diverge).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
27
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
28 ;;; Commentary:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
29
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
30 ;; This file is dumped with XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
31
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
32 ;; The base major mode for editing Lisp code (used also for Emacs Lisp).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
33 ;; This mode is documented in the Emacs manual
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
34
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
35 ;; July/05/97 slb Converted to use easymenu.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
36
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
37 ;;; Code:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
38
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
39 (defvar lisp-mode-syntax-table nil "")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
40 (defvar emacs-lisp-mode-syntax-table nil "")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
41 (defvar lisp-mode-abbrev-table nil "")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
42
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
43 ;; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
44 (defvar lisp-interaction-mode-popup-menu nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
45 (defvar lisp-interaction-mode-popup-menu-1
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
46 (purecopy '("Lisp-Interaction"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
47 ["Evaluate Last S-expression" eval-last-sexp t]
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
48 ["Evaluate Entire Buffer" eval-current-buffer t]
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
49 ["Evaluate Region" eval-region (region-exists-p)]
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
50 "---"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
51 ["Evaluate This Defun" eval-defun t]
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
52 ;; FSF says "Instrument Function for Debugging"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
53 ["Debug This Defun" edebug-defun t]
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
54 "---"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
55 ["Trace a Function" trace-function-background t]
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
56 ["Untrace All Functions" untrace-all (fboundp 'untrace-all)]
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
57 "---"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
58 ["Comment Out Region" comment-region (region-exists-p)]
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
59 ["Indent Region" indent-region (region-exists-p)]
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
60 ["Indent Line" lisp-indent-line t]
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
61 "---"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
62 ["Debug On Error" (setq debug-on-error (not debug-on-error))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
63 :style toggle :selected debug-on-error]
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
64 ["Debug On Quit" (setq debug-on-quit (not debug-on-quit))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
65 :style toggle :selected debug-on-quit]
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
66 ["Debug on Signal" (setq debug-on-signal (not debug-on-signal))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
67 :style toggle :selected debug-on-signal]
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
68 )))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
69
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
70 (defvar emacs-lisp-mode-popup-menu nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
71 (defvar emacs-lisp-mode-popup-menu-1
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
72 (purecopy
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
73 (nconc
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
74 '("Emacs-Lisp"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
75 ["Byte-compile This File" emacs-lisp-byte-compile t]
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
76 ["Byte-recompile Directory..." byte-recompile-directory t]
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
77 "---")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
78 (cdr lisp-interaction-mode-popup-menu-1))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
79
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
80 ;Don't have a menubar entry in Lisp Interaction mode. Otherwise, the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
81 ;*scratch* buffer has a Lisp menubar item! Very confusing.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
82 ;(defvar lisp-interaction-mode-menubar-menu
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
83 ; (purecopy (cons "Lisp" (cdr lisp-interaction-mode-popup-menu))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
84
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
85 (defvar emacs-lisp-mode-menubar-menu nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
86 (defvar emacs-lisp-mode-menubar-menu-1
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
87 (purecopy (cons "Lisp" (cdr emacs-lisp-mode-popup-menu-1))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
88
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
89 (if (not emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
90 (let ((i 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
91 (setq emacs-lisp-mode-syntax-table (make-syntax-table))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
92 (while (< i ?0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
93 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
94 (setq i (1+ i)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
95 (setq i (1+ ?9))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
96 (while (< i ?A)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
97 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
98 (setq i (1+ i)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
99 (setq i (1+ ?Z))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
100 (while (< i ?a)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
101 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
102 (setq i (1+ i)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
103 (setq i (1+ ?z))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
104 (while (< i 128)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
105 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
106 (setq i (1+ i)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
107 (modify-syntax-entry ? " " emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
108 (modify-syntax-entry ?\t " " emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
109 (modify-syntax-entry ?\n "> " emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
110 ;; Give CR the same syntax as newline, for selective-display.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
111 (modify-syntax-entry ?\^m "> " emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
112 ;; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
113 ;; Treat ^L as whitespace.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
114 (modify-syntax-entry ?\f " " emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
115 (modify-syntax-entry ?\; "< " emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
116 (modify-syntax-entry ?` "' " emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
117 (modify-syntax-entry ?' "' " emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
118 (modify-syntax-entry ?, "' " emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
119 ;; Used to be singlequote; changed for flonums.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
120 (modify-syntax-entry ?. "_ " emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
121 (modify-syntax-entry ?# "' " emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
122 (modify-syntax-entry ?\" "\" " emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
123 (modify-syntax-entry ?\\ "\\ " emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
124 (modify-syntax-entry ?\( "() " emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
125 (modify-syntax-entry ?\) ")( " emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
126 (modify-syntax-entry ?\[ "(] " emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
127 (modify-syntax-entry ?\] ")[ " emacs-lisp-mode-syntax-table)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
128
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
129 (if (not lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
130 (progn (setq lisp-mode-syntax-table
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
131 (copy-syntax-table emacs-lisp-mode-syntax-table))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
132 (modify-syntax-entry ?\| "\" " lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
133 (modify-syntax-entry ?\[ "_ " lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
134 ;; XEmacs changes
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
135 (modify-syntax-entry ?\] "_ " lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
136 ;;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
137 ;; If emacs was compiled with NEW_SYNTAX, then do
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
138 ;; CL's #| |# block comments.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
139 (if (= 8 (length (parse-partial-sexp (point) (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
140 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
141 (modify-syntax-entry ?# "' 58" lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
142 (modify-syntax-entry ?| ". 67" lisp-mode-syntax-table))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
143 ;; else, old style
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
144 (modify-syntax-entry ?\| "\" " lisp-mode-syntax-table))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
145
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
146 (define-abbrev-table 'lisp-mode-abbrev-table ())
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
147
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
148 ;(defvar lisp-imenu-generic-expression
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
149 ; '(
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
150 ; (nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
151 ; "^\\s-*(def\\(un\\|subst\\|macro\\|advice\\)\\s-+\\([-A-Za-z0-9+]+\\)" 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
152 ; ("Variables"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
153 ; "^\\s-*(def\\(var\\|const\\)\\s-+\\([-A-Za-z0-9+]+\\)" 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
154 ; ("Types"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
155 ; "^\\s-*(def\\(type\\|struct\\|class\\|ine-condition\\)\\s-+\\([-A-Za-z0-9+]+\\)"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
156 ; 2))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
157 ;
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
158 ; "Imenu generic expression for Lisp mode. See `imenu-generic-expression'.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
159
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
160 (defun lisp-mode-variables (lisp-syntax)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
161 (cond (lisp-syntax
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
162 (set-syntax-table lisp-mode-syntax-table)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
163 (setq local-abbrev-table lisp-mode-abbrev-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
164 (make-local-variable 'paragraph-start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
165 (setq paragraph-start (concat page-delimiter "\\|$" ))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
166 (make-local-variable 'paragraph-separate)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
167 (setq paragraph-separate paragraph-start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
168 (make-local-variable 'paragraph-ignore-fill-prefix)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
169 (setq paragraph-ignore-fill-prefix t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
170 (make-local-variable 'fill-paragraph-function)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
171 (setq fill-paragraph-function 'lisp-fill-paragraph)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
172 ;; Adaptive fill mode gets in the way of auto-fill,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
173 ;; and should make no difference for explicit fill
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
174 ;; because lisp-fill-paragraph should do the job.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
175 (make-local-variable 'adaptive-fill-mode)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
176 (setq adaptive-fill-mode nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
177 (make-local-variable 'indent-line-function)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
178 (setq indent-line-function 'lisp-indent-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
179 (make-local-variable 'indent-region-function)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
180 (setq indent-region-function 'lisp-indent-region)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
181 (make-local-variable 'parse-sexp-ignore-comments)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
182 (setq parse-sexp-ignore-comments t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
183 (make-local-variable 'outline-regexp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
184 (setq outline-regexp ";;; \\|(....")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
185 (make-local-variable 'comment-start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
186 (setq comment-start ";")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
187 ;; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
188 (set (make-local-variable 'block-comment-start) ";;")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
189 (make-local-variable 'comment-start-skip)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
190 ;; Look within the line for a ; following an even number of backslashes
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
191 ;; after either a non-backslash or the line beginning.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
192 (setq comment-start-skip "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\);+ *")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
193 (make-local-variable 'comment-column)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
194 (setq comment-column 40)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
195 (make-local-variable 'comment-indent-function)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
196 (setq comment-indent-function 'lisp-comment-indent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
197 ;; XEmacs changes
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
198 ; (make-local-variable 'imenu-generic-expression)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
199 ; (setq imenu-generic-expression lisp-imenu-generic-expression)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
200 (set (make-local-variable 'dabbrev-case-fold-search) nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
201 (set (make-local-variable 'dabbrev-case-replace) nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
202 )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
203
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
204
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
205 (defvar shared-lisp-mode-map ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
206 "Keymap for commands shared by all sorts of Lisp modes.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
207
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
208 (if shared-lisp-mode-map
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
209 ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
210 (setq shared-lisp-mode-map (make-sparse-keymap))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
211 ;; XEmacs changes
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
212 (set-keymap-name shared-lisp-mode-map 'shared-lisp-mode-map)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
213 (define-key shared-lisp-mode-map "\M-;" 'lisp-indent-for-comment)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
214 (define-key shared-lisp-mode-map "\e\C-q" 'indent-sexp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
215
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
216 (defvar emacs-lisp-mode-map ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
217 "Keymap for Emacs Lisp mode.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
218 All commands in `shared-lisp-mode-map' are inherited by this map.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
219
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
220 (if emacs-lisp-mode-map
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
221 ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
222 ;; XEmacs: Ignore FSF nconc stuff
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
223 (setq emacs-lisp-mode-map (make-sparse-keymap))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
224 (set-keymap-name emacs-lisp-mode-map 'emacs-lisp-mode-map)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
225 (set-keymap-parents emacs-lisp-mode-map (list shared-lisp-mode-map))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
226 (define-key emacs-lisp-mode-map "\e\t" 'lisp-complete-symbol)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
227 (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
228 ;; XEmacs: Not sure what the FSF menu bindings are. I hope XEmacs
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
229 ;; doesn't need them.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
230 )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
231
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
232 (defun emacs-lisp-byte-compile ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
233 "Byte compile the file containing the current buffer."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
234 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
235 (if buffer-file-name
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
236 ;; XEmacs change. Force buffer save first
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
237 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
238 (save-buffer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
239 (byte-compile-file buffer-file-name))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
240 (error "The buffer must be saved in a file first.")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
241
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
242 (defun emacs-lisp-byte-compile-and-load ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
243 "Byte-compile the current file (if it has changed), then load compiled code."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
244 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
245 (or buffer-file-name
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
246 (error "The buffer must be saved in a file first"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
247 (require 'bytecomp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
248 ;; Recompile if file or buffer has changed since last compilation.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
249 (if (and (buffer-modified-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
250 (y-or-n-p (format "save buffer %s first? " (buffer-name))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
251 (save-buffer))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
252 (let ((compiled-file-name (byte-compile-dest-file buffer-file-name)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
253 (if (file-newer-than-file-p compiled-file-name buffer-file-name)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
254 (load-file compiled-file-name)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
255 (byte-compile-file buffer-file-name t))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
256
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
257 (defun emacs-lisp-mode ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
258 "Major mode for editing Lisp code to run in Emacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
259 Commands:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
260 Delete converts tabs to spaces as it moves back.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
261 Blank lines separate paragraphs. Semicolons start comments.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
262 \\{emacs-lisp-mode-map}
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
263 Entry to this mode calls the value of `emacs-lisp-mode-hook'
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
264 if that value is non-nil."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
265 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
266 (kill-all-local-variables)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
267 (use-local-map emacs-lisp-mode-map)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
268 (set-syntax-table emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
269 ;; XEmacs changes
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
270 (setq major-mode 'emacs-lisp-mode
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
271 ;; mode-popup-menu emacs-lisp-mode-popup-menu
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
272 mode-name "Emacs-Lisp")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
273 ;; (if (and (featurep 'menubar)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
274 ;; current-menubar)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
275 ;; (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
276 ;; make a local copy of the menubar, so our modes don't
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
277 ;; change the global menubar
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
278 ;; (set-buffer-menubar current-menubar)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
279 ;; (add-submenu nil emacs-lisp-mode-menubar-menu)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
280 (unless emacs-lisp-mode-popup-menu
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
281 (easy-menu-define emacs-lisp-mode-popup-menu emacs-lisp-mode-map ""
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
282 emacs-lisp-mode-popup-menu-1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
283 (easy-menu-add emacs-lisp-mode-popup-menu)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
284 (lisp-mode-variables nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
285 (run-hooks 'emacs-lisp-mode-hook))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
286
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
287 (defvar lisp-mode-map ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
288 "Keymap for ordinary Lisp mode.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
289 All commands in `shared-lisp-mode-map' are inherited by this map.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
290
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
291 (if lisp-mode-map
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
292 ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
293 ;; XEmacs changes
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
294 (setq lisp-mode-map (make-sparse-keymap))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
295 (set-keymap-name lisp-mode-map 'lisp-mode-map)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
296 (set-keymap-parents lisp-mode-map (list shared-lisp-mode-map))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
297 (define-key lisp-mode-map "\e\C-x" 'lisp-send-defun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
298 ;; gag, no. use ilisp. -jwz
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
299 ;; (define-key lisp-mode-map "\C-c\C-z" 'run-lisp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
300 )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
301
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
302 (defun lisp-mode ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
303 "Major mode for editing Lisp code for Lisps other than GNU Emacs Lisp.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
304 Commands:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
305 Delete converts tabs to spaces as it moves back.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
306 Blank lines separate paragraphs. Semicolons start comments.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
307 \\{lisp-mode-map}
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
308 Note that `run-lisp' may be used either to start an inferior Lisp job
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
309 or to switch back to an existing one.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
310
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
311 Entry to this mode calls the value of `lisp-mode-hook'
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
312 if that value is non-nil."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
313 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
314 (kill-all-local-variables)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
315 (use-local-map lisp-mode-map)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
316 (setq major-mode 'lisp-mode)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
317 (setq mode-name "Lisp")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
318 (lisp-mode-variables t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
319 (set-syntax-table lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
320 (run-hooks 'lisp-mode-hook))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
321
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
322 ;; This will do unless shell.el is loaded.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
323 ;; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
324 (defun lisp-send-defun ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
325 "Send the current defun to the Lisp process made by \\[run-lisp]."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
326 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
327 (error "Process lisp does not exist"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
328
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
329 ;; XEmacs change: emacs-lisp-mode-map is a more appropriate parent.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
330 (defvar lisp-interaction-mode-map ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
331 "Keymap for Lisp Interaction mode.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
332 All commands in `shared-lisp-mode-map' are inherited by this map.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
333
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
334 (if lisp-interaction-mode-map
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
335 ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
336 ;; XEmacs set keymap our way
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
337 (setq lisp-interaction-mode-map (make-sparse-keymap))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
338 (set-keymap-name lisp-interaction-mode-map 'lisp-interaction-mode-map)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
339 (set-keymap-parents lisp-interaction-mode-map (list emacs-lisp-mode-map))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
340 (define-key lisp-interaction-mode-map "\e\C-x" 'eval-defun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
341 (define-key lisp-interaction-mode-map "\e\t" 'lisp-complete-symbol)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
342 (define-key lisp-interaction-mode-map "\n" 'eval-print-last-sexp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
343
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
344 (defun lisp-interaction-mode ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
345 "Major mode for typing and evaluating Lisp forms.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
346 Like Lisp mode except that \\[eval-print-last-sexp] evals the Lisp expression
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
347 before point, and prints its value into the buffer, advancing point.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
348
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
349 Commands:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
350 Delete converts tabs to spaces as it moves back.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
351 Paragraphs are separated only by blank lines.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
352 Semicolons start comments.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
353 \\{lisp-interaction-mode-map}
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
354 Entry to this mode calls the value of `lisp-interaction-mode-hook'
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
355 if that value is non-nil."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
356 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
357 (kill-all-local-variables)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
358 (use-local-map lisp-interaction-mode-map)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
359 (setq major-mode 'lisp-interaction-mode)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
360 (setq mode-name "Lisp Interaction")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
361 ;; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
362 ;; (setq mode-popup-menu lisp-interaction-mode-popup-menu)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
363 (unless lisp-interaction-mode-popup-menu
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
364 (easy-menu-define lisp-interaction-mode-popup-menu
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
365 lisp-interaction-mode-map
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
366 ""
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
367 lisp-interaction-mode-popup-menu-1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
368 (easy-menu-add lisp-interaction-mode-popup-menu)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
369
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
370 (set-syntax-table emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
371 (lisp-mode-variables nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
372 (run-hooks 'lisp-interaction-mode-hook))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
373
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
374 (defun eval-print-last-sexp ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
375 "Evaluate sexp before point; print value into current buffer."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
376 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
377 (let ((standard-output (current-buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
378 (terpri)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
379 (eval-last-sexp t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
380 (terpri)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
381
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
382 ;; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
383 (defcustom eval-interactive-verbose t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
384 "*Non-nil means that interactive evaluation can print messages.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
385 The messages are printed when the expression is treated differently
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
386 using `\\[eval-last-sexp]' and `\\[eval-defun]' than it than it would have been
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
387 treated noninteractively.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
388
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
389 The printed messages are \"defvar treated as defconst\" and \"defcustom
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
390 evaluation forced\". See `eval-interactive' for more details."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
391 :type 'boolean
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
392 :group 'lisp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
393
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
394 (defun eval-interactive (expr)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
395 "Like `eval' except that it transforms defvars to defconsts.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
396 The evaluation of defcustom forms is forced."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
397 (cond ((and (consp expr)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
398 (eq (car expr) 'defvar)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
399 (> (length expr) 2))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
400 (eval (cons 'defconst (cdr expr)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
401 (and eval-interactive-verbose
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
402 (message "defvar treated as defconst"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
403 (sit-for 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
404 (message "")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
405 (nth 1 expr))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
406 ((and (consp expr)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
407 (eq (car expr) 'defcustom)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
408 (> (length expr) 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
409 (default-boundp (nth 1 expr)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
410 ;; Force variable to be bound
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
411 (set-default (nth 1 expr) (eval (nth 2 expr)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
412 ;; And evaluate the defcustom
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
413 (eval expr)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
414 (and eval-interactive-verbose
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
415 (message "defcustom evaluation forced"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
416 (sit-for 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
417 (message "")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
418 (nth 1 expr))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
419 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
420 (eval expr))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
421
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
422 ;; XEmacs change, based on Bob Weiner suggestion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
423 (defun eval-last-sexp (eval-last-sexp-arg-internal) ;dynamic scoping wonderment
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
424 "Evaluate sexp before point; print value in minibuffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
425 With argument, print output into current buffer."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
426 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
427 (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
428 (opoint (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
429 (prin1 (let ((stab (syntax-table))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
430 expr)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
431 (eval-interactive
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
432 (unwind-protect
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
433 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
434 (set-syntax-table emacs-lisp-mode-syntax-table)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
435 (forward-sexp -1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
436 (save-restriction
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
437 (narrow-to-region (point-min) opoint)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
438 (setq expr (read (current-buffer)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
439 (if (and (consp expr)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
440 (eq (car expr) 'interactive))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
441 (list 'quote
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
442 (call-interactively
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
443 (eval (` (lambda (&rest args)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
444 (, expr) args)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
445 expr)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
446 (set-syntax-table stab)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
447
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
448 (defun eval-defun (eval-defun-arg-internal)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
449 "Evaluate defun that point is in or before.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
450 Print value in minibuffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
451 With argument, insert value in current buffer after the defun."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
452 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
453 (let ((standard-output (if eval-defun-arg-internal (current-buffer) t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
454 (prin1 (eval-interactive (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
455 (end-of-defun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
456 (beginning-of-defun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
457 (read (current-buffer)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
458
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
459
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
460 (defun lisp-comment-indent ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
461 (if (looking-at "\\s<\\s<\\s<")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
462 (current-column)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
463 (if (looking-at "\\s<\\s<")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
464 (let ((tem (calculate-lisp-indent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
465 (if (listp tem) (car tem) tem))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
466 (skip-chars-backward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
467 (max (if (bolp) 0 (1+ (current-column)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
468 comment-column))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
469
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
470 ;; XEmacs change
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
471 (defun lisp-indent-for-comment ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
472 "Indent this line's comment appropriately, or insert an empty comment.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
473 If adding a new comment on a blank line, use `block-comment-start' instead
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
474 of `comment-start' to open the comment."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
475 ;; by Stig@hackvan.com
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
476 ;; #### - This functionality, the recognition of block-comment-{start,end},
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
477 ;; will perhaps be standardized across modes and move to indent-for-comment.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
478 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
479 (if (and block-comment-start
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
480 (save-excursion (beginning-of-line) (looking-at "^[ \t]*$")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
481 (insert block-comment-start))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
482 (indent-for-comment))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
483
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
484 (defconst lisp-indent-offset nil "")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
485 (defconst lisp-indent-function 'lisp-indent-function "")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
486
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
487 (defun lisp-indent-line (&optional whole-exp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
488 "Indent current line as Lisp code.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
489 With argument, indent any additional lines of the same expression
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
490 rigidly along with this one."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
491 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
492 (let ((indent (calculate-lisp-indent)) shift-amt beg end
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
493 (pos (- (point-max) (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
494 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
495 (setq beg (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
496 (skip-chars-forward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
497 (if (looking-at "\\s<\\s<\\s<")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
498 ;; Don't alter indentation of a ;;; comment line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
499 (goto-char (- (point-max) pos))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
500 (if (and (looking-at "\\s<") (not (looking-at "\\s<\\s<")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
501 ;; Single-semicolon comment lines should be indented
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
502 ;; as comment lines, not as code.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
503 (progn (indent-for-comment) (forward-char -1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
504 (if (listp indent) (setq indent (car indent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
505 (setq shift-amt (- indent (current-column)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
506 (if (zerop shift-amt)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
507 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
508 (delete-region beg (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
509 (indent-to indent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
510 ;; If initial point was within line's indentation,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
511 ;; position after the indentation. Else stay at same point in text.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
512 (if (> (- (point-max) pos) (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
513 (goto-char (- (point-max) pos)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
514 ;; If desired, shift remaining lines of expression the same amount.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
515 (and whole-exp (not (zerop shift-amt))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
516 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
517 (goto-char beg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
518 (forward-sexp 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
519 (setq end (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
520 (goto-char beg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
521 (forward-line 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
522 (setq beg (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
523 (> end beg))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
524 (indent-code-rigidly beg end shift-amt)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
525
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
526 (defvar calculate-lisp-indent-last-sexp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
527
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
528 (defun calculate-lisp-indent (&optional parse-start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
529 "Return appropriate indentation for current line as Lisp code.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
530 In usual case returns an integer: the column to indent to.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
531 Can instead return a list, whose car is the column to indent to.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
532 This means that following lines at the same level of indentation
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
533 should not necessarily be indented the same way.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
534 The second element of the list is the buffer position
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
535 of the start of the containing expression."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
536 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
537 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
538 (let ((indent-point (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
539 ;; XEmacs change (remove paren-depth)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
540 state ;;paren-depth
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
541 ;; setting this to a number inhibits calling hook
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
542 (desired-indent nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
543 (retry t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
544 calculate-lisp-indent-last-sexp containing-sexp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
545 (if parse-start
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
546 (goto-char parse-start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
547 (beginning-of-defun))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
548 ;; Find outermost containing sexp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
549 (while (< (point) indent-point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
550 (setq state (parse-partial-sexp (point) indent-point 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
551 ;; Find innermost containing sexp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
552 (while (and retry
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
553 state
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
554 ;; XEmacs change (remove paren-depth)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
555 (> ;;(setq paren-depth (elt state 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
556 (elt state 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
557 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
558 (setq retry nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
559 (setq calculate-lisp-indent-last-sexp (elt state 2))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
560 (setq containing-sexp (elt state 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
561 ;; Position following last unclosed open.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
562 (goto-char (1+ containing-sexp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
563 ;; Is there a complete sexp since then?
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
564 (if (and calculate-lisp-indent-last-sexp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
565 (> calculate-lisp-indent-last-sexp (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
566 ;; Yes, but is there a containing sexp after that?
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
567 (let ((peek (parse-partial-sexp calculate-lisp-indent-last-sexp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
568 indent-point 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
569 (if (setq retry (car (cdr peek))) (setq state peek)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
570 (if retry
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
571 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
572 ;; Innermost containing sexp found
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
573 (goto-char (1+ containing-sexp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
574 (if (not calculate-lisp-indent-last-sexp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
575 ;; indent-point immediately follows open paren.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
576 ;; Don't call hook.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
577 (setq desired-indent (current-column))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
578 ;; Find the start of first element of containing sexp.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
579 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
580 (cond ((looking-at "\\s(")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
581 ;; First element of containing sexp is a list.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
582 ;; Indent under that list.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
583 )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
584 ((> (save-excursion (forward-line 1) (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
585 calculate-lisp-indent-last-sexp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
586 ;; This is the first line to start within the containing sexp.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
587 ;; It's almost certainly a function call.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
588 (if (= (point) calculate-lisp-indent-last-sexp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
589 ;; Containing sexp has nothing before this line
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
590 ;; except the first element. Indent under that element.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
591 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
592 ;; Skip the first element, find start of second (the first
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
593 ;; argument of the function call) and indent under.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
594 (progn (forward-sexp 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
595 (parse-partial-sexp (point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
596 calculate-lisp-indent-last-sexp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
597 0 t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
598 (backward-prefix-chars))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
599 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
600 ;; Indent beneath first sexp on same line as
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
601 ;; calculate-lisp-indent-last-sexp. Again, it's
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
602 ;; almost certainly a function call.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
603 (goto-char calculate-lisp-indent-last-sexp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
604 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
605 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
606 0 t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
607 (backward-prefix-chars)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
608 ;; Point is at the point to indent under unless we are inside a string.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
609 ;; Call indentation hook except when overridden by lisp-indent-offset
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
610 ;; or if the desired indentation has already been computed.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
611 (let ((normal-indent (current-column)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
612 (cond ((elt state 3)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
613 ;; Inside a string, don't change indentation.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
614 (goto-char indent-point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
615 (skip-chars-forward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
616 (current-column))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
617 (desired-indent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
618 ((and (boundp 'lisp-indent-function)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
619 lisp-indent-function
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
620 (not retry))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
621 (or (funcall lisp-indent-function indent-point state)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
622 normal-indent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
623 ;; XEmacs change:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
624 ;; lisp-indent-offset shouldn't override lisp-indent-function !
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
625 ((and (integerp lisp-indent-offset) containing-sexp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
626 ;; Indent by constant offset
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
627 (goto-char containing-sexp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
628 (+ normal-indent lisp-indent-offset))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
629 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
630 normal-indent))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
631
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
632 (defun lisp-indent-function (indent-point state)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
633 ;; free reference to `calculate-lisp-indent-last-sexp'
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
634 ;; in #'calculate-lisp-indent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
635 (let ((normal-indent (current-column)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
636 (goto-char (1+ (elt state 1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
637 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
638 (if (and (elt state 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
639 (not (looking-at "\\sw\\|\\s_")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
640 ;; car of form doesn't seem to be a a symbol
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
641 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
642 (if (not (> (save-excursion (forward-line 1) (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
643 calculate-lisp-indent-last-sexp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
644 (progn (goto-char calculate-lisp-indent-last-sexp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
645 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
646 (parse-partial-sexp (point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
647 calculate-lisp-indent-last-sexp 0 t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
648 ;; Indent under the list or under the first sexp on the same
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
649 ;; line as calculate-lisp-indent-last-sexp. Note that first
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
650 ;; thing on that line has to be complete sexp since we are
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
651 ;; inside the innermost containing sexp.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
652 (backward-prefix-chars)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
653 (current-column))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
654 (let ((function (buffer-substring (point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
655 (progn (forward-sexp 1) (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
656 method)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
657 (setq method (or (get (intern-soft function) 'lisp-indent-function)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
658 (get (intern-soft function) 'lisp-indent-hook)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
659 (cond ((or (eq method 'defun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
660 (and (null method)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
661 (> (length function) 3)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
662 (string-match "\\`def" function)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
663 (lisp-indent-defform state indent-point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
664 ((integerp method)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
665 (lisp-indent-specform method state
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
666 indent-point normal-indent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
667 (method
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
668 (funcall method state indent-point)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
669
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
670 (defconst lisp-body-indent 2
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
671 "Number of columns to indent the second line of a `(def...)' form.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
672
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
673 (defun lisp-indent-specform (count state indent-point normal-indent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
674 (let ((containing-form-start (elt state 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
675 (i count)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
676 body-indent containing-form-column)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
677 ;; Move to the start of containing form, calculate indentation
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
678 ;; to use for non-distinguished forms (> count), and move past the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
679 ;; function symbol. lisp-indent-function guarantees that there is at
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
680 ;; least one word or symbol character following open paren of containing
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
681 ;; form.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
682 (goto-char containing-form-start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
683 (setq containing-form-column (current-column))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
684 (setq body-indent (+ lisp-body-indent containing-form-column))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
685 (forward-char 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
686 (forward-sexp 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
687 ;; Now find the start of the last form.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
688 (parse-partial-sexp (point) indent-point 1 t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
689 (while (and (< (point) indent-point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
690 (condition-case ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
691 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
692 (setq count (1- count))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
693 (forward-sexp 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
694 (parse-partial-sexp (point) indent-point 1 t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
695 (error nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
696 ;; Point is sitting on first character of last (or count) sexp.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
697 (if (> count 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
698 ;; A distinguished form. If it is the first or second form use double
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
699 ;; lisp-body-indent, else normal indent. With lisp-body-indent bound
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
700 ;; to 2 (the default), this just happens to work the same with if as
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
701 ;; the older code, but it makes unwind-protect, condition-case,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
702 ;; with-output-to-temp-buffer, et. al. much more tasteful. The older,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
703 ;; less hacked, behavior can be obtained by replacing below with
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
704 ;; (list normal-indent containing-form-start).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
705 (if (<= (- i count) 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
706 (list (+ containing-form-column (* 2 lisp-body-indent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
707 containing-form-start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
708 (list normal-indent containing-form-start))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
709 ;; A non-distinguished form. Use body-indent if there are no
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
710 ;; distinguished forms and this is the first undistinguished form,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
711 ;; or if this is the first undistinguished form and the preceding
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
712 ;; distinguished form has indentation at least as great as body-indent.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
713 (if (or (and (= i 0) (= count 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
714 (and (= count 0) (<= body-indent normal-indent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
715 body-indent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
716 normal-indent))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
717
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
718 (defun lisp-indent-defform (state indent-point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
719 (goto-char (car (cdr state)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
720 (forward-line 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
721 (if (> (point) (car (cdr (cdr state))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
722 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
723 (goto-char (car (cdr state)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
724 (+ lisp-body-indent (current-column)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
725
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
726
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
727 ;; (put 'progn 'lisp-indent-function 0), say, causes progn to be indented
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
728 ;; like defun if the first form is placed on the next line, otherwise
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
729 ;; it is indented like any other form (i.e. forms line up under first).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
730
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
731 (put 'lambda 'lisp-indent-function 'defun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
732 (put 'autoload 'lisp-indent-function 'defun)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
733 (put 'progn 'lisp-indent-function 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
734 (put 'prog1 'lisp-indent-function 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
735 (put 'prog2 'lisp-indent-function 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
736 (put 'save-excursion 'lisp-indent-function 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
737 (put 'save-window-excursion 'lisp-indent-function 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
738 (put 'save-selected-window 'lisp-indent-function 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
739 (put 'save-restriction 'lisp-indent-function 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
740 (put 'save-match-data 'lisp-indent-function 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
741 (put 'let 'lisp-indent-function 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
742 (put 'let* 'lisp-indent-function 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
743 (put 'while 'lisp-indent-function 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
744 (put 'if 'lisp-indent-function 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
745 (put 'catch 'lisp-indent-function 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
746 (put 'condition-case 'lisp-indent-function 2)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
747 (put 'unwind-protect 'lisp-indent-function 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
748 (put 'save-current-buffer 'lisp-indent-function 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
749 (put 'with-current-buffer 'lisp-indent-function 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
750 (put 'with-temp-file 'lisp-indent-function 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
751 (put 'with-temp-buffer 'lisp-indent-function 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
752 (put 'with-output-to-string 'lisp-indent-function 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
753 (put 'with-output-to-temp-buffer 'lisp-indent-function 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
754 (put 'display-message 'lisp-indent-function 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
755 (put 'display-warning 'lisp-indent-function 1)
219
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
756 (put 'lmessage 'lisp-indent-function 2)
262b8bb4a523 Import from CVS: tag r20-4b8
cvs
parents: 209
diff changeset
757 (put 'lwarn 'lisp-indent-function 2)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
758 (put 'global-set-key 'lisp-indent-function 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
759
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
760 (defun indent-sexp (&optional endpos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
761 "Indent each line of the list starting just after point.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
762 If optional arg ENDPOS is given, indent each line, stopping when
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
763 ENDPOS is encountered."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
764 (interactive)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
765 (let ((indent-stack (list nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
766 (next-depth 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
767 ;; If ENDPOS is non-nil, use nil as STARTING-POINT
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
768 ;; so that calculate-lisp-indent will find the beginning of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
769 ;; the defun we are in.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
770 ;; If ENDPOS is nil, it is safe not to scan before point
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
771 ;; since every line we indent is more deeply nested than point is.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
772 (starting-point (if endpos nil (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
773 (last-point (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
774 last-depth bol outer-loop-done inner-loop-done state this-indent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
775 (or endpos
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
776 ;; Get error now if we don't have a complete sexp after point.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
777 (save-excursion (forward-sexp 1)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
778 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
779 (setq outer-loop-done nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
780 (while (if endpos (< (point) endpos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
781 (not outer-loop-done))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
782 (setq last-depth next-depth
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
783 inner-loop-done nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
784 ;; Parse this line so we can learn the state
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
785 ;; to indent the next line.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
786 ;; This inner loop goes through only once
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
787 ;; unless a line ends inside a string.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
788 (while (and (not inner-loop-done)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
789 (not (setq outer-loop-done (eobp))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
790 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
791 nil nil state))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
792 (setq next-depth (car state))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
793 ;; If the line contains a comment other than the sort
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
794 ;; that is indented like code,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
795 ;; indent it now with indent-for-comment.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
796 ;; Comments indented like code are right already.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
797 ;; In any case clear the in-comment flag in the state
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
798 ;; because parse-partial-sexp never sees the newlines.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
799 (if (car (nthcdr 4 state))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
800 (progn (indent-for-comment)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
801 (end-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
802 (setcar (nthcdr 4 state) nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
803 ;; If this line ends inside a string,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
804 ;; go straight to next line, remaining within the inner loop,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
805 ;; and turn off the \-flag.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
806 (if (car (nthcdr 3 state))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
807 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
808 (forward-line 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
809 (setcar (nthcdr 5 state) nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
810 (setq inner-loop-done t)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
811 (and endpos
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
812 (<= next-depth 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
813 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
814 (setq indent-stack (append indent-stack
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
815 (make-list (- next-depth) nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
816 last-depth (- last-depth next-depth)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
817 next-depth 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
818 (or outer-loop-done endpos
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
819 (setq outer-loop-done (<= next-depth 0)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
820 (if outer-loop-done
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
821 (forward-line 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
822 (while (> last-depth next-depth)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
823 (setq indent-stack (cdr indent-stack)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
824 last-depth (1- last-depth)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
825 (while (< last-depth next-depth)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
826 (setq indent-stack (cons nil indent-stack)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
827 last-depth (1+ last-depth)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
828 ;; Now go to the next line and indent it according
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
829 ;; to what we learned from parsing the previous one.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
830 (forward-line 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
831 (setq bol (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
832 (skip-chars-forward " \t")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
833 ;; But not if the line is blank, or just a comment
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
834 ;; (except for double-semi comments; indent them as usual).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
835 (if (or (eobp) (looking-at "\\s<\\|\n"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
836 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
837 (if (and (car indent-stack)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
838 (>= (car indent-stack) 0))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
839 (setq this-indent (car indent-stack))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
840 (let ((val (calculate-lisp-indent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
841 (if (car indent-stack) (- (car indent-stack))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
842 starting-point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
843 (if (integerp val)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
844 (setcar indent-stack
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
845 (setq this-indent val))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
846 (setcar indent-stack (- (car (cdr val))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
847 (setq this-indent (car val)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
848 (if (/= (current-column) this-indent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
849 (progn (delete-region bol (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
850 (indent-to this-indent)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
851 (or outer-loop-done
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
852 (setq outer-loop-done (= (point) last-point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
853 (setq last-point (point)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
854
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
855 ;; Indent every line whose first char is between START and END inclusive.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
856 (defun lisp-indent-region (start end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
857 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
858 (let ((endmark (copy-marker end)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
859 (goto-char start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
860 (and (bolp) (not (eolp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
861 (lisp-indent-line))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
862 (indent-sexp endmark)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
863 (set-marker endmark nil))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
864
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
865 ;;;; Lisp paragraph filling commands.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
866
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
867 (defun lisp-fill-paragraph (&optional justify)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
868 "Like \\[fill-paragraph], but handle Emacs Lisp comments.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
869 If any of the current line is a comment, fill the comment or the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
870 paragraph of it that point is in, preserving the comment's indentation
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
871 and initial semicolons."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
872 (interactive "P")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
873 (let (
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
874 ;; Non-nil if the current line contains a comment.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
875 has-comment
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
876
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
877 ;; Non-nil if the current line contains code and a comment.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
878 has-code-and-comment
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
879
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
880 ;; If has-comment, the appropriate fill-prefix for the comment.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
881 comment-fill-prefix
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
882 )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
883
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
884 ;; Figure out what kind of comment we are looking at.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
885 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
886 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
887 (cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
888
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
889 ;; A line with nothing but a comment on it?
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
890 ((looking-at "[ \t]*;[; \t]*")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
891 (setq has-comment t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
892 comment-fill-prefix (buffer-substring (match-beginning 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
893 (match-end 0))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
894
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
895 ;; A line with some code, followed by a comment? Remember that the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
896 ;; semi which starts the comment shouldn't be part of a string or
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
897 ;; character.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
898 ;; XEmacs Try this the FSF and see if it works.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
899 ; ((progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
900 ; (while (not (looking-at ";\\|$"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
901 ; (skip-chars-forward "^;\n\"\\\\?")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
902 ; (cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
903 ; ((eq (char-after (point)) ?\\) (forward-char 2))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
904 ; ((memq (char-after (point)) '(?\" ??)) (forward-sexp 1))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
905 ; (looking-at ";+[\t ]*"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
906 ; (setq has-comment t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
907 ((condition-case nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
908 (save-restriction
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
909 (narrow-to-region (point-min)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
910 (save-excursion (end-of-line) (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
911 (while (not (looking-at ";\\|$"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
912 (skip-chars-forward "^;\n\"\\\\?")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
913 (cond
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
914 ((eq (char-after (point)) ?\\) (forward-char 2))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
915 ((memq (char-after (point)) '(?\" ??)) (forward-sexp 1))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
916 (looking-at ";+[\t ]*"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
917 (error nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
918 (setq has-comment t has-code-and-comment t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
919 (setq comment-fill-prefix
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
920 (concat (make-string (/ (current-column) 8) ?\t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
921 (make-string (% (current-column) 8) ?\ )
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
922 (buffer-substring (match-beginning 0) (match-end 0)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
923
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
924 (if (not has-comment)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
925 (fill-paragraph justify)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
926
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
927 ;; Narrow to include only the comment, and then fill the region.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
928 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
929 (save-restriction
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
930 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
931 (narrow-to-region
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
932 ;; Find the first line we should include in the region to fill.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
933 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
934 (while (and (zerop (forward-line -1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
935 (looking-at "^[ \t]*;")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
936 ;; We may have gone too far. Go forward again.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
937 (or (looking-at ".*;")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
938 (forward-line 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
939 (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
940 ;; Find the beginning of the first line past the region to fill.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
941 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
942 (while (progn (forward-line 1)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
943 (looking-at "^[ \t]*;")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
944 (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
945
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
946 ;; Lines with only semicolons on them can be paragraph boundaries.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
947 (let* ((paragraph-start (concat paragraph-start "\\|[ \t;]*$"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
948 (paragraph-separate (concat paragraph-start "\\|[ \t;]*$"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
949 (paragraph-ignore-fill-prefix nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
950 (fill-prefix comment-fill-prefix)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
951 (after-line (if has-code-and-comment
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
952 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
953 (forward-line 1) (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
954 (end (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
955 (forward-paragraph)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
956 (or (bolp) (newline 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
957 (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
958 ;; If this comment starts on a line with code,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
959 ;; include that like in the filling.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
960 (beg (progn (backward-paragraph)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
961 (if (eq (point) after-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
962 (forward-line -1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
963 (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
964 (fill-region-as-paragraph beg end
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
965 justify nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
966 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
967 (goto-char beg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
968 (if (looking-at fill-prefix)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
969 nil
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
970 (re-search-forward comment-start-skip)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
971 (point))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
972 t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
973
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
974 (defun indent-code-rigidly (start end arg &optional nochange-regexp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
975 "Indent all lines of code, starting in the region, sideways by ARG columns.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
976 Does not affect lines starting inside comments or strings, assuming that
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
977 the start of the region is not inside them.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
978
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
979 Called from a program, takes args START, END, COLUMNS and NOCHANGE-REGEXP.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
980 The last is a regexp which, if matched at the beginning of a line,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
981 means don't indent that line."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
982 (interactive "r\np")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
983 (let (state)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
984 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
985 (goto-char end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
986 (setq end (point-marker))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
987 (goto-char start)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
988 (or (bolp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
989 (setq state (parse-partial-sexp (point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
990 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
991 (forward-line 1) (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
992 nil nil state)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
993 (while (< (point) end)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
994 (or (car (nthcdr 3 state))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
995 (and nochange-regexp
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
996 (looking-at nochange-regexp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
997 ;; If line does not start in string, indent it
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
998 (let ((indent (current-indentation)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
999 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1000 (or (eolp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1001 (indent-to (max 0 (+ indent arg)) 0))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1002 (setq state (parse-partial-sexp (point)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1003 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1004 (forward-line 1) (point))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1005 nil nil state))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1006
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1007 (provide 'lisp-mode)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1008
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1009 ;;; lisp-mode.el ends here