annotate lisp/modes/lisp-mode.el @ 187:b405438285a2 r20-3b20

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