annotate lisp/modes/lisp-mode.el @ 172:a38aed19690b

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