annotate lisp/modes/lisp-mode.el @ 153:25f70ba0133c r20-3b3

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