annotate lisp/lisp-mode.el @ 265:8efd647ea9ca r20-5b31

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