annotate lisp/lisp-mode.el @ 5142:f965e31a35f0

reduce lcrecord headers to 2 words, rename printing_unreadable_object -------------------- ChangeLog entries follow: -------------------- man/ChangeLog addition: 2010-03-13 Ben Wing <ben@xemacs.org> * internals/internals.texi (Working with Lisp Objects): * internals/internals.texi (Writing Macros): * internals/internals.texi (lrecords): More rewriting to correspond with changes from *LRECORD* to *LISP_OBJECT*. modules/ChangeLog addition: 2010-03-13 Ben Wing <ben@xemacs.org> * postgresql/postgresql.c (print_pgconn): * postgresql/postgresql.c (print_pgresult): printing_unreadable_object -> printing_unreadable_object_fmt. 2010-03-13 Ben Wing <ben@xemacs.org> * ldap/eldap.c (print_ldap): printing_unreadable_object -> printing_unreadable_object_fmt. src/ChangeLog addition: 2010-03-13 Ben Wing <ben@xemacs.org> * alloc.c (alloc_sized_lrecord_1): * alloc.c (alloc_sized_lrecord_array): * alloc.c (old_alloc_sized_lcrecord): * alloc.c (disksave_object_finalization_1): * alloc.c (mark_lcrecord_list): * alloc.c (alloc_managed_lcrecord): * alloc.c (free_managed_lcrecord): * alloc.c (tick_lcrecord_stats): * alloc.c (sweep_lcrecords_1): * buffer.c (print_buffer): * buffer.c (DEFVAR_BUFFER_LOCAL_1): * casetab.c: * casetab.c (print_case_table): * console.c (print_console): * console.c (DEFVAR_CONSOLE_LOCAL_1): * data.c (print_weak_list): * data.c (print_weak_box): * data.c (print_ephemeron): * data.c (ephemeron_equal): * database.c (print_database): * database.c (finalize_database): * device-msw.c (sync_printer_with_devmode): * device-msw.c (print_devmode): * device-msw.c (finalize_devmode): * device.c: * device.c (print_device): * elhash.c: * elhash.c (print_hash_table): * eval.c (print_subr): * eval.c (print_multiple_value): * event-stream.c (event_stream_resignal_wakeup): * events.c (clear_event_resource): * events.c (zero_event): * events.c (print_event): * extents.c: * extents.c (print_extent): * file-coding.c (print_coding_system): * font-mgr.c: * font-mgr.c (Ffc_init): * frame.c: * frame.c (print_frame): * gc.c: * gc.c (GC_CHECK_NOT_FREE): * glyphs.c: * glyphs.c (print_image_instance): * glyphs.c (print_glyph): * gui.c (print_gui_item): * gui.c (copy_gui_item): * keymap.c (print_keymap): * keymap.c (MARKED_SLOT): * lisp.h: * lisp.h (struct Lisp_String): * lisp.h (DEFUN): * lisp.h (DEFUN_NORETURN): * lrecord.h: * lrecord.h (NORMAL_LISP_OBJECT_UID): * lrecord.h (struct lrecord_header): * lrecord.h (set_lheader_implementation): * lrecord.h (struct old_lcrecord_header): * lrecord.h (struct free_lcrecord_header): * marker.c (print_marker): * mule-charset.c: * mule-charset.c (print_charset): * objects.c (print_color_instance): * objects.c (print_font_instance): * objects.c (finalize_font_instance): * print.c (print_cons): * print.c (printing_unreadable_object_fmt): * print.c (printing_unreadable_lisp_object): * print.c (external_object_printer): * print.c (internal_object_printer): * print.c (debug_p4): * print.c (ext_print_begin): * process.c (print_process): * rangetab.c (print_range_table): * rangetab.c (range_table_equal): * scrollbar.c (free_scrollbar_instance): * specifier.c (print_specifier): * specifier.c (finalize_specifier): * symbols.c (guts_of_unbound_marker): * symeval.h: * symeval.h (DEFVAR_SYMVAL_FWD): * tooltalk.c: * tooltalk.c (print_tooltalk_message): * tooltalk.c (print_tooltalk_pattern): * ui-gtk.c (ffi_object_printer): * ui-gtk.c (emacs_gtk_object_printer): * ui-gtk.c (emacs_gtk_boxed_printer): * window.c (print_window): * window.c (free_window_mirror): * window.c (debug_print_window): * xemacs.def.in.in: (1) printing_unreadable_object -> printing_unreadable_object_fmt. (2) printing_unreadable_lcrecord -> printing_unreadable_lisp_object and fix up so it no longer requires an lcrecord. These previous changes eliminate most of the remaining places where the terms `lcrecord' and `lrecord' occurred outside of specialized code. (3) Fairly major change: Reduce the number of words in an lcrecord from 3 to 2. The third word consisted of a uid that duplicated the lrecord uid, and a single free bit, which was moved into the lrecord structure. This reduces the size of the `uid' slot from 21 bits to 20 bits. Arguably this isn't enough -- we could easily have more than 1,000,000 or so objects created in a session. The answer is (a) It doesn't really matter if we overflow the uid field because it's only used for debugging, to identify an object uniquely (or pretty much so). (b) If we cared about it overflowing and wanted to reduce this, we could make it so that cons, string, float and certain other frob-block types that never print out the uid simply don't store a uid in them and don't increment the lrecord_uid_counter. (4) In conjunction with (3), create new macro NORMAL_LISP_OBJECT_UID() and use it to abstract out the differences between NEWGC and old-GC in accessing the `uid' value from a "normal Lisp Object pointer". (5) In events.c, use zero_nonsized_lisp_object() in place of custom- written equivalent. In font-mgr.c use external_object_printer() in place of custom-written equivalents.
author Ben Wing <ben@xemacs.org>
date Sat, 13 Mar 2010 05:38:08 -0600
parents e4bbe5622a80
children 77907bd57d25
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; lisp-mode.el --- Lisp mode, and its idiosyncratic commands.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1996, 1997 Free Software Foundation, Inc.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
4 ;; Copyright (C) 1995 Tinker Systems.
4942
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
5 ;; Copyright (C) 2002, 2010 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; Maintainer: FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 ;; Keywords: lisp, languages, dumped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ;; XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ;; under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 ;; any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 ;; XEmacs is distributed in the hope that it will be useful, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 ;; General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 ;; along with XEmacs; see the file COPYING. If not, write to the Free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 ;; 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 ;;; Synched up with: FSF 19.34 (but starting to diverge).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 ;; This file is dumped with XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 ;; The base major mode for editing Lisp code (used also for Emacs Lisp).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 ;; This mode is documented in the Emacs manual
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 (defgroup lisp nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 "Lisp support, including Emacs Lisp."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 :group 'languages
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 :group 'development)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 (defvar lisp-mode-syntax-table nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 (defvar emacs-lisp-mode-syntax-table nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 (defvar lisp-mode-abbrev-table nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
47 (defun construct-lisp-mode-menu (popup-p emacs-lisp-p)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
48 (flet ((popup-wrap (form)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
49 (if popup-p `(menu-call-at-event ',form) form)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
50 `(,@(if emacs-lisp-p
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
51 `(["%_Byte-Compile This File" ,(popup-wrap
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
52 'emacs-lisp-byte-compile)]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
53 ["B%_yte-Compile/Load This File"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
54 ,(popup-wrap 'emacs-lisp-byte-compile-and-load)]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
55 ["Byte-%_Recompile Directory..."
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
56 ,(popup-wrap 'byte-recompile-directory)]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
57 "---"))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
58 ["%_Evaluate Region or Defun"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
59 ,(popup-wrap '(if (region-exists-p)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
60 (call-interactively 'eval-region)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
61 (call-interactively 'eval-defun)))]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
62 ["Evaluate %_Whole Buffer" ,(popup-wrap 'eval-current-buffer)]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
63 ["Evaluate Last %_S-expression" ,(popup-wrap 'eval-last-sexp)]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
64 "---"
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 776
diff changeset
65 ["%_Indent Region or Balanced Expression"
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 776
diff changeset
66 ,(popup-wrap '(if (region-exists-p)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 776
diff changeset
67 (call-interactively 'indent-region)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 776
diff changeset
68 (call-interactively 'indent-sexp)))]
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 776
diff changeset
69 ["I%_ndent Defun"
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 776
diff changeset
70 ,(popup-wrap '(progn
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 776
diff changeset
71 (beginning-of-defun)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 776
diff changeset
72 (indent-sexp)))]
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 776
diff changeset
73 "---"
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 776
diff changeset
74 ["%_Comment Out Region" comment-region :active (region-exists-p)]
1333
1b0339b048ce [xemacs-hg @ 2003-03-02 09:38:37 by ben]
ben
parents: 872
diff changeset
75 ["Unc%_omment Region" uncomment-region :active (region-exists-p)]
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 776
diff changeset
76 "---"
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
77 ,@(if popup-p
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
78 '(["%_Find Function"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
79 (find-function (menu-call-at-event '(function-at-point)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
80 :suffix (let ((fun (menu-call-at-event '(function-at-point))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
81 (if fun (symbol-name fun) ""))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
82 :active (and (fboundp 'find-function)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
83 (menu-call-at-event '(function-at-point)))]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
84 ["%_Find Variable"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
85 (find-variable (menu-call-at-event '(variable-at-point)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
86 :suffix (let ((fun (menu-call-at-event '(variable-at-point))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
87 (if fun (symbol-name fun) ""))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
88 :active (and (fboundp 'find-variable)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
89 (menu-call-at-event '(variable-at-point)))]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
90 ["%_Help on Function"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
91 (describe-function (menu-call-at-event '(function-at-point)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
92 :suffix (let ((fun (menu-call-at-event '(function-at-point))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
93 (if fun (symbol-name fun) ""))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
94 :active (and (fboundp 'describe-function)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
95 (menu-call-at-event '(function-at-point)))]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
96 ["%_Help on Variable"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
97 (describe-variable (menu-call-at-event '(variable-at-point)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
98 :suffix (let ((fun (menu-call-at-event '(variable-at-point))))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
99 (if fun (symbol-name fun) ""))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
100 :active (and (fboundp 'describe-variable)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
101 (menu-call-at-event '(variable-at-point)))])
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
102 '(["Find %_Function..." find-function
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
103 :active (fboundp 'find-function)]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
104 ["Find %_Variable..." find-variable
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
105 :active (fboundp 'find-variable)]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
106 ["%_Help on Function..." describe-function
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
107 :active (fboundp 'describe-function)]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
108 ["Hel%_p on Variable..." describe-variable
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
109 :active (fboundp 'describe-variable)]))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
110 "---"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
111 ["Instrument This Defun for %_Debugging" ,(popup-wrap 'edebug-defun)]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
112 ["%_Trace Function..." trace-function-background]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
113 ["%_Untrace All Functions" untrace-all
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
114 :active (fboundp 'untrace-all)]
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
115 "---"
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 776
diff changeset
116 ["Display %_Macro Expansion of Balanced Expression"
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 776
diff changeset
117 ,(popup-wrap 'macroexpand-sexp)]
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 776
diff changeset
118 ["Display Recursive Macro E%_xpansion of Balanced Expression"
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 776
diff changeset
119 ,(popup-wrap 'macroexpand-all-sexp)]
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
120 "---"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
121 "Look for debug-on-error under Options->Troubleshooting"
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
122 )))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
124 (defvar lisp-interaction-mode-popup-menu
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
125 (cons "Lisp-Interaction" (construct-lisp-mode-menu t nil)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
126
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
127 (defvar emacs-lisp-mode-popup-menu
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
128 (cons "Emacs-Lisp" (construct-lisp-mode-menu t t)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 ;Don't have a menubar entry in Lisp Interaction mode. Otherwise, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 ;*scratch* buffer has a Lisp menubar item! Very confusing.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
132 ;Jan Vroonhof really wants this, so it's back. --ben
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
133 (defvar lisp-interaction-mode-menubar-menu
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
134 (cons "%_Lisp" (construct-lisp-mode-menu nil nil)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
136 (defvar emacs-lisp-mode-menubar-menu
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
137 (cons "%_Lisp" (construct-lisp-mode-menu nil t)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 (if (not emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 (let ((i 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 (setq emacs-lisp-mode-syntax-table (make-syntax-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 (while (< i ?0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 (setq i (1+ i)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 (setq i (1+ ?9))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 (while (< i ?A)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 (setq i (1+ i)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 (setq i (1+ ?Z))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 (while (< i ?a)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 (setq i (1+ i)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 (setq i (1+ ?z))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 (while (< i 128)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 (setq i (1+ i)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 (modify-syntax-entry ? " " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 (modify-syntax-entry ?\t " " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 (modify-syntax-entry ?\f " " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 (modify-syntax-entry ?\n "> " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 ;; Give CR the same syntax as newline, for selective-display.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 (modify-syntax-entry ?\^m "> " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 (modify-syntax-entry ?\; "< " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 (modify-syntax-entry ?` "' " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 (modify-syntax-entry ?' "' " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 (modify-syntax-entry ?, "' " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 ;; Used to be singlequote; changed for flonums.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 (modify-syntax-entry ?. "_ " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 (modify-syntax-entry ?# "' " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 (modify-syntax-entry ?\" "\" " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 (modify-syntax-entry ?\\ "\\ " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 (modify-syntax-entry ?\( "() " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 (modify-syntax-entry ?\) ")( " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 (modify-syntax-entry ?\[ "(] " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 (modify-syntax-entry ?\] ")[ " emacs-lisp-mode-syntax-table)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 (if (not lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 (progn (setq lisp-mode-syntax-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 (copy-syntax-table emacs-lisp-mode-syntax-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 (modify-syntax-entry ?\[ "_ " lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 ;; XEmacs changes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 (modify-syntax-entry ?\] "_ " lisp-mode-syntax-table)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
183 (modify-syntax-entry ?# "' 58" lisp-mode-syntax-table)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
184 (modify-syntax-entry ?| "\" 67" lisp-mode-syntax-table)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 (define-abbrev-table 'lisp-mode-abbrev-table ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 (defvar lisp-imenu-generic-expression
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 '(
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 (nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 "^\\s-*(def\\(un\\|subst\\|macro\\|advice\\)\\s-+\\([-A-Za-z0-9+*|:]+\\)" 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 ("Variables"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 "^\\s-*(def\\(var\\|const\\|custom\\)\\s-+\\([-A-Za-z0-9+*|:]+\\)" 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 ("Types"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 "^\\s-*(def\\(group\\|type\\|struct\\|class\\|ine-condition\\)\\s-+\\([-A-Za-z0-9+*|:]+\\)"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 "Imenu generic expression for Lisp mode. See `imenu-generic-expression'.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 (defun lisp-mode-variables (lisp-syntax)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 (cond (lisp-syntax
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 (set-syntax-table lisp-mode-syntax-table)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 (setq local-abbrev-table lisp-mode-abbrev-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 (make-local-variable 'paragraph-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 (setq paragraph-start (concat page-delimiter "\\|$" ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 (make-local-variable 'paragraph-separate)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 (setq paragraph-separate paragraph-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 (make-local-variable 'paragraph-ignore-fill-prefix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 (setq paragraph-ignore-fill-prefix t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 (make-local-variable 'fill-paragraph-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 (setq fill-paragraph-function 'lisp-fill-paragraph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 ;; Adaptive fill mode gets in the way of auto-fill,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 ;; and should make no difference for explicit fill
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 ;; because lisp-fill-paragraph should do the job.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 (make-local-variable 'adaptive-fill-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 (setq adaptive-fill-mode nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 (make-local-variable 'indent-line-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 (setq indent-line-function 'lisp-indent-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 (make-local-variable 'indent-region-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 (setq indent-region-function 'lisp-indent-region)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 (make-local-variable 'parse-sexp-ignore-comments)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 (setq parse-sexp-ignore-comments t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 (make-local-variable 'outline-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 (setq outline-regexp ";;; \\|(....")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 (make-local-variable 'comment-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 (setq comment-start ";")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 (set (make-local-variable 'block-comment-start) ";;")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 (make-local-variable 'comment-start-skip)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 ;; Look within the line for a ; following an even number of backslashes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 ;; after either a non-backslash or the line beginning.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 (setq comment-start-skip "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\);+ *")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 (make-local-variable 'comment-column)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 (setq comment-column 40)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 (make-local-variable 'comment-indent-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 (setq comment-indent-function 'lisp-comment-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 (set (make-local-variable 'dabbrev-case-fold-search) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 (set (make-local-variable 'dabbrev-case-replace) nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (make-local-variable 'imenu-generic-expression)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 (setq imenu-generic-expression lisp-imenu-generic-expression))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 (defvar shared-lisp-mode-map ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 "Keymap for commands shared by all sorts of Lisp modes.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 (if shared-lisp-mode-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 (setq shared-lisp-mode-map (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 ;; XEmacs changes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 (set-keymap-name shared-lisp-mode-map 'shared-lisp-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 (define-key shared-lisp-mode-map "\M-;" 'lisp-indent-for-comment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 (define-key shared-lisp-mode-map "\e\C-q" 'indent-sexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 (defvar emacs-lisp-mode-map ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 "Keymap for Emacs Lisp mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 All commands in `shared-lisp-mode-map' are inherited by this map.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 (if emacs-lisp-mode-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 ;; XEmacs: Ignore FSF nconc stuff
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 (setq emacs-lisp-mode-map (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 (set-keymap-name emacs-lisp-mode-map 'emacs-lisp-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 (set-keymap-parents emacs-lisp-mode-map (list shared-lisp-mode-map))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 (define-key emacs-lisp-mode-map "\e\t" 'lisp-complete-symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 ;; XEmacs: Not sure what the FSF menu bindings are. I hope XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 ;; doesn't need them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269
1428
10738b72057d [xemacs-hg @ 2003-04-24 05:29:11 by youngs]
youngs
parents: 1333
diff changeset
270 ;; XEmacs: add docstrings to the hooks
10738b72057d [xemacs-hg @ 2003-04-24 05:29:11 by youngs]
youngs
parents: 1333
diff changeset
271 (defvar emacs-lisp-mode-hook nil
10738b72057d [xemacs-hg @ 2003-04-24 05:29:11 by youngs]
youngs
parents: 1333
diff changeset
272 "Hook to run when entering emacs-lisp-mode.")
10738b72057d [xemacs-hg @ 2003-04-24 05:29:11 by youngs]
youngs
parents: 1333
diff changeset
273
10738b72057d [xemacs-hg @ 2003-04-24 05:29:11 by youngs]
youngs
parents: 1333
diff changeset
274 (defvar lisp-mode-hook nil
10738b72057d [xemacs-hg @ 2003-04-24 05:29:11 by youngs]
youngs
parents: 1333
diff changeset
275 "Hook to run when entering lisp-mode.")
10738b72057d [xemacs-hg @ 2003-04-24 05:29:11 by youngs]
youngs
parents: 1333
diff changeset
276
10738b72057d [xemacs-hg @ 2003-04-24 05:29:11 by youngs]
youngs
parents: 1333
diff changeset
277 (defvar lisp-interaction-mode-hook nil
10738b72057d [xemacs-hg @ 2003-04-24 05:29:11 by youngs]
youngs
parents: 1333
diff changeset
278 "Hook to run when entering lisp-interaction-mode.")
10738b72057d [xemacs-hg @ 2003-04-24 05:29:11 by youngs]
youngs
parents: 1333
diff changeset
279
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 (defun emacs-lisp-byte-compile ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 "Byte compile the file containing the current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 (if buffer-file-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 ;; XEmacs change. Force buffer save first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 (save-buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 (byte-compile-file buffer-file-name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 (error "The buffer must be saved in a file first.")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 (defun emacs-lisp-byte-compile-and-load ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 "Byte-compile the current file (if it has changed), then load compiled code."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 (or buffer-file-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 (error "The buffer must be saved in a file first"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 (require 'bytecomp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 ;; Recompile if file or buffer has changed since last compilation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 (if (and (buffer-modified-p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 (y-or-n-p (format "save buffer %s first? " (buffer-name))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 (save-buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 (let ((compiled-file-name (byte-compile-dest-file buffer-file-name)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 (if (file-newer-than-file-p compiled-file-name buffer-file-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 (load-file compiled-file-name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 (byte-compile-file buffer-file-name t))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 (defun emacs-lisp-mode ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 "Major mode for editing Lisp code to run in Emacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 Commands:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 Delete converts tabs to spaces as it moves back.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 Blank lines separate paragraphs. Semicolons start comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 \\{emacs-lisp-mode-map}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 Entry to this mode calls the value of `emacs-lisp-mode-hook'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 if that value is non-nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 (kill-all-local-variables)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 (use-local-map emacs-lisp-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 (set-syntax-table emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 ;; XEmacs changes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 (setq major-mode 'emacs-lisp-mode
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
319 mode-popup-menu emacs-lisp-mode-popup-menu
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 mode-name "Emacs-Lisp")
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
321 (if (and (featurep 'menubar)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
322 current-menubar)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
323 (progn
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 ;; make a local copy of the menubar, so our modes don't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 ;; change the global menubar
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
326 (set-buffer-menubar current-menubar)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
327 (add-submenu nil emacs-lisp-mode-menubar-menu)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 (lisp-mode-variables nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 (run-hooks 'emacs-lisp-mode-hook))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330
430
a5df635868b2 Import from CVS: tag r21-2-23
cvs
parents: 428
diff changeset
331 (put 'emacs-lisp-mode 'font-lock-lisp-like t)
a5df635868b2 Import from CVS: tag r21-2-23
cvs
parents: 428
diff changeset
332
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 (defvar lisp-mode-map ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 "Keymap for ordinary Lisp mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 All commands in `shared-lisp-mode-map' are inherited by this map.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 (if lisp-mode-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 ;; XEmacs changes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 (setq lisp-mode-map (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 (set-keymap-name lisp-mode-map 'lisp-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 (set-keymap-parents lisp-mode-map (list shared-lisp-mode-map))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 ;; gag, no. use ilisp. -jwz
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 ;; (define-key lisp-mode-map "\C-c\C-z" 'run-lisp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 (defun lisp-mode ()
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 502
diff changeset
348 "Major mode for editing Lisp code for Lisps other than Emacs Lisp.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 Commands:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 Delete converts tabs to spaces as it moves back.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 Blank lines separate paragraphs. Semicolons start comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 \\{lisp-mode-map}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 Note that `run-lisp' may be used either to start an inferior Lisp job
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 or to switch back to an existing one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 Entry to this mode calls the value of `lisp-mode-hook'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 if that value is non-nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 (kill-all-local-variables)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 (use-local-map lisp-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 (setq major-mode 'lisp-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 (setq mode-name "Lisp")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 (lisp-mode-variables t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 (set-syntax-table lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 (run-hooks 'lisp-mode-hook))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 ;; XEmacs change: emacs-lisp-mode-map is a more appropriate parent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 (defvar lisp-interaction-mode-map ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 "Keymap for Lisp Interaction mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 All commands in `shared-lisp-mode-map' are inherited by this map.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 (if lisp-interaction-mode-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 ;; XEmacs set keymap our way
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 (setq lisp-interaction-mode-map (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 (set-keymap-name lisp-interaction-mode-map 'lisp-interaction-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 (set-keymap-parents lisp-interaction-mode-map (list emacs-lisp-mode-map))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 (define-key lisp-interaction-mode-map "\e\C-x" 'eval-defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 (define-key lisp-interaction-mode-map "\e\t" 'lisp-complete-symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 (define-key lisp-interaction-mode-map "\n" 'eval-print-last-sexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 (defun lisp-interaction-mode ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 "Major mode for typing and evaluating Lisp forms.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 Like Lisp mode except that \\[eval-print-last-sexp] evals the Lisp expression
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 before point, and prints its value into the buffer, advancing point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 Commands:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 Delete converts tabs to spaces as it moves back.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 Paragraphs are separated only by blank lines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 Semicolons start comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 \\{lisp-interaction-mode-map}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 Entry to this mode calls the value of `lisp-interaction-mode-hook'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 if that value is non-nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 (kill-all-local-variables)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 (use-local-map lisp-interaction-mode-map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 (setq major-mode 'lisp-interaction-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 (setq mode-name "Lisp Interaction")
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
399 (setq mode-popup-menu lisp-interaction-mode-popup-menu)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
400 (if (and (featurep 'menubar)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
401 current-menubar)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
402 (progn
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
403 ;; make a local copy of the menubar, so our modes don't
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
404 ;; change the global menubar
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
405 (set-buffer-menubar current-menubar)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
406 (add-submenu nil lisp-interaction-mode-menubar-menu)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 (set-syntax-table emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 (lisp-mode-variables nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 (run-hooks 'lisp-interaction-mode-hook))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 (defun eval-print-last-sexp ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 "Evaluate sexp before point; print value into current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 (let ((standard-output (current-buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 (terpri)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 (eval-last-sexp t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 (terpri)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 (defcustom eval-interactive-verbose t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 "*Non-nil means that interactive evaluation can print messages.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 The messages are printed when the expression is treated differently
2116
ce294639d321 [xemacs-hg @ 2004-06-06 23:58:40 by adrian]
adrian
parents: 1428
diff changeset
423 using `\\[eval-last-sexp]' and `\\[eval-defun]' than it would have
ce294639d321 [xemacs-hg @ 2004-06-06 23:58:40 by adrian]
adrian
parents: 1428
diff changeset
424 been treated noninteractively.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 The printed messages are \"defvar treated as defconst\" and \"defcustom
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
427 evaluation forced\". See `eval-interactive' for more details."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 :group 'lisp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 (defun eval-interactive (expr)
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
432 "Evaluate EXPR; pass back multiple values, transform defvars to defconsts.
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
433
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
434 Always returns a list. The length of this list will be something other than
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
435 one if the form returned multiple values. It will be zero if the form
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
436 returned a single zero-length multiple value."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 (cond ((and (eq (car-safe expr) 'defvar)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 (> (length expr) 2))
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
439 (setq expr (multiple-value-list (eval (cons 'defconst (cdr expr)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 (when eval-interactive-verbose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 (message "defvar treated as defconst")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 (sit-for 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 (message ""))
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
444 expr)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 ((and (eq (car-safe expr) 'defcustom)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 (> (length expr) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 (default-boundp (nth 1 expr)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 ;; Force variable to be bound
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
449 (funcall
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
450 (or (plist-get expr :set) #'custom-set-default)
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
451 (nth 1 expr) (eval (nth 2 expr)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 ;; And evaluate the defcustom
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
453 (setq expr (multiple-value-list (eval expr)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 (when eval-interactive-verbose
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455 (message "defcustom evaluation forced")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 (sit-for 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 (message ""))
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
458 expr)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 (t
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
460 (multiple-value-list (eval expr)))))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
461
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
462 (defun prin1-list-as-multiple-values (multiple-value-list &optional stream)
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
463 "Call `prin1' on each element of MULTIPLE-VALUE-LIST, separated by \" ;\\n\"
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
464
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
465 If MULTIPLE-VALUE-LIST is zero-length, print the text
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
466 \"#<zero length multiple value> ;\\n\". Always returns nil."
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
467 (loop for value in multiple-value-list
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
468 with seen-first = nil
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
469 do
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
470 (if seen-first
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
471 (princ " ;\n" stream)
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
472 (setq seen-first t))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
473 (prin1 value stream)
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
474 finally (unless seen-first
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
475 (princ "#<zero length multiple value> ;" stream))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 ;; XEmacs change, based on Bob Weiner suggestion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 (defun eval-last-sexp (eval-last-sexp-arg-internal) ;dynamic scoping wonderment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 "Evaluate sexp before point; print value in minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 With argument, print output into current buffer."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 (let ((standard-output (if eval-last-sexp-arg-internal (current-buffer) t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 (opoint (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 ignore-quotes)
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
485 (prin1-list-as-multiple-values
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
486 (eval-interactive
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
487 (letf (((syntax-table) emacs-lisp-mode-syntax-table))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
488 (save-excursion
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
489 ;; If this sexp appears to be enclosed in `...' then
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
490 ;; ignore the surrounding quotes.
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
491 (setq ignore-quotes (or (eq (char-after) ?\')
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
492 (eq (char-before) ?\')))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
493 (forward-sexp -1)
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
494 ;; vladimir@cs.ualberta.ca 30-Jul-1997: skip ` in
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
495 ;; `variable' so that the value is returned, not the
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
496 ;; name.
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
497 (if (and ignore-quotes
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
498 (eq (char-after) ?\`))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
499 (forward-char))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
500 (save-restriction
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
501 (narrow-to-region (point-min) opoint)
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
502 (let ((expr (read (current-buffer))))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
503 (if (eq (car-safe expr) 'interactive)
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
504 ;; If it's an (interactive ...) form, it's
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
505 ;; more useful to show how an interactive call
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
506 ;; would use it.
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
507 `(call-interactively
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
508 (lambda (&rest args)
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
509 ,expr args))
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
510 expr)))))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 (defun eval-defun (eval-defun-arg-internal)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 "Evaluate defun that point is in or before.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 Print value in minibuffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 With argument, insert value in current buffer after the defun."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 (let ((standard-output (if eval-defun-arg-internal (current-buffer) t)))
4677
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
518 (prin1-list-as-multiple-values
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
519 (eval-interactive
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
520 (save-excursion
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
521 (end-of-defun)
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
522 (beginning-of-defun)
8f1ee2d15784 Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3261
diff changeset
523 (read (current-buffer)))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 (defun lisp-comment-indent ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 (if (looking-at "\\s<\\s<\\s<")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 (current-column)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 (if (looking-at "\\s<\\s<")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 ;; #### FSF has:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 ;; (let ((tem (or (calculate-lisp-indent) (current-column)))) ...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 (let ((tem (calculate-lisp-indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 (if (listp tem) (car tem) tem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 (skip-chars-backward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 (max (if (bolp) 0 (1+ (current-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 comment-column))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 (defun lisp-indent-for-comment ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 "Indent this line's comment appropriately, or insert an empty comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 If adding a new comment on a blank line, use `block-comment-start' instead
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 of `comment-start' to open the comment."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 ;; by Stig@hackvan.com
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 ;; #### - This functionality, the recognition of block-comment-{start,end},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 ;; will perhaps be standardized across modes and move to indent-for-comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 (if (and block-comment-start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 (save-excursion (beginning-of-line) (looking-at "^[ \t]*$")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 (insert block-comment-start))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 (indent-for-comment))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 (defvar lisp-indent-offset nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 (defvar lisp-indent-function 'lisp-indent-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 (defun lisp-indent-line (&optional whole-exp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 "Indent current line as Lisp code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 With argument, indent any additional lines of the same expression
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 rigidly along with this one."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 (let ((indent (calculate-lisp-indent)) shift-amt beg end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 (pos (- (point-max) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 (setq beg (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 (if (looking-at "\\s<\\s<\\s<")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 ;; Don't alter indentation of a ;;; comment line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 (goto-char (- (point-max) pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 (if (and (looking-at "\\s<") (not (looking-at "\\s<\\s<")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 ;; Single-semicolon comment lines should be indented
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 ;; as comment lines, not as code.
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 442
diff changeset
570 (progn (indent-for-comment) (backward-char 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 (if (listp indent) (setq indent (car indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 (setq shift-amt (- indent (current-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 (if (zerop shift-amt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 (delete-region beg (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 (indent-to indent)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 ;; If initial point was within line's indentation,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 ;; position after the indentation. Else stay at same point in text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 (if (> (- (point-max) pos) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 (goto-char (- (point-max) pos)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 ;; If desired, shift remaining lines of expression the same amount.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 (and whole-exp (not (zerop shift-amt))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 (goto-char beg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 (forward-sexp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 (setq end (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 (goto-char beg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 (setq beg (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 (> end beg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 (indent-code-rigidly beg end shift-amt)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 (defvar calculate-lisp-indent-last-sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 (defun calculate-lisp-indent (&optional parse-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 "Return appropriate indentation for current line as Lisp code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 In usual case returns an integer: the column to indent to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 Can instead return a list, whose car is the column to indent to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 This means that following lines at the same level of indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 should not necessarily be indented the same way.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 The second element of the list is the buffer position
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 of the start of the containing expression."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 (let ((indent-point (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 ;; XEmacs change (remove paren-depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 state ;;paren-depth
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 ;; setting this to a number inhibits calling hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 (desired-indent nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 (retry t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 calculate-lisp-indent-last-sexp containing-sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 (if parse-start
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 (goto-char parse-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 (beginning-of-defun))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 ;; Find outermost containing sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 (while (< (point) indent-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 (setq state (parse-partial-sexp (point) indent-point 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 ;; Find innermost containing sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 (while (and retry
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 state
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 ;; XEmacs change (remove paren-depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 (> ;;(setq paren-depth (elt state 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 (elt state 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 (setq retry nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 (setq calculate-lisp-indent-last-sexp (elt state 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 (setq containing-sexp (elt state 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 ;; Position following last unclosed open.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 (goto-char (1+ containing-sexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 ;; Is there a complete sexp since then?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 (if (and calculate-lisp-indent-last-sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 (> calculate-lisp-indent-last-sexp (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 ;; Yes, but is there a containing sexp after that?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 (let ((peek (parse-partial-sexp calculate-lisp-indent-last-sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 indent-point 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 (if (setq retry (car (cdr peek))) (setq state peek)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 (if retry
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 ;; Innermost containing sexp found
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 (goto-char (1+ containing-sexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 (if (not calculate-lisp-indent-last-sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 ;; indent-point immediately follows open paren.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 ;; Don't call hook.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 (setq desired-indent (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 ;; Find the start of first element of containing sexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 (cond ((looking-at "\\s(")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 ;; First element of containing sexp is a list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 ;; Indent under that list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 ((> (save-excursion (forward-line 1) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 calculate-lisp-indent-last-sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 ;; This is the first line to start within the containing sexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 ;; It's almost certainly a function call.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 (if (= (point) calculate-lisp-indent-last-sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 ;; Containing sexp has nothing before this line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 ;; except the first element. Indent under that element.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 ;; Skip the first element, find start of second (the first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 ;; argument of the function call) and indent under.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 (progn (forward-sexp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 (parse-partial-sexp (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 calculate-lisp-indent-last-sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 0 t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 (backward-prefix-chars))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 ;; Indent beneath first sexp on same line as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 ;; calculate-lisp-indent-last-sexp. Again, it's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 ;; almost certainly a function call.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 (goto-char calculate-lisp-indent-last-sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 0 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 (backward-prefix-chars)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 ;; Point is at the point to indent under unless we are inside a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 ;; Call indentation hook except when overridden by lisp-indent-offset
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 ;; or if the desired indentation has already been computed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 (let ((normal-indent (current-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 (cond ((elt state 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 ;; Inside a string, don't change indentation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 (goto-char indent-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 (desired-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 ((and (boundp 'lisp-indent-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 lisp-indent-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 (not retry))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 (or (funcall lisp-indent-function indent-point state)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 normal-indent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 ;; XEmacs change:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 ;; lisp-indent-offset shouldn't override lisp-indent-function !
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 ((and (integerp lisp-indent-offset) containing-sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 ;; Indent by constant offset
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 (goto-char containing-sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 (+ normal-indent lisp-indent-offset))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 normal-indent))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
699 (defvar lisp-function-and-type-regexp
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
700 (concat "def\\("
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
701 ;; def but not define-.
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
702 "\\(un\\|advice\\|alias\\|macro\\*?\\|setf\\|subst\\*?\\|"
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
703 "-edebug-spec\\|"
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
704 ;; CLOS
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
705 "method\\|generic\\|"
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
706 ;; define-*
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
707 "ine-\\(?:"
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
708 ;; basic Lisp stuff
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
709 "compiler-macro\\|function\\|function-when-void\\|modify-macro\\|"
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
710 "setf-method\\|"
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
711 ;; obsolete/compatible support, XEmacs-specific
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
712 "compatible-function-alias\\|obsolete-function-alias\\|"
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
713 ;; XEmacs-specific, supporting stuff inside of XEmacs
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
714 "ccl-program\\|device-method\\*?\\|prefix-command\\|skeleton"
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
715 "\\)\\)\\|"
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
716 ;; Structure declarations.
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
717 "\\(class\\|struct\\|type\\)\\)\\>")
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
718 "Regular expression to match the function and type keywords used in Lisp.
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
719 This matches, for example, the string \"defun\", as well as defsetf,
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
720 defsubst*, define-prefix-command, etc. Match string 1 matches everything
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
721 but the three-letter \"def\" string at the beginning. Match string 2
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
722 matches everything after that, when it's *NOT* a \"type\" declaration --
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
723 which includes defclass, defstruct, and deftype. Match string 3 is similar
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
724 to match string 2 in that it matches everything after the \"def\", when
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
725 \(and only when) the keyword matched *IS* a type declaration. You can use
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
726 match strings 2 and 3 to easily determine whether a function or type was
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
727 matched. The regex is terminated with a \\\> so that there must be a
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
728 word-end; i.e. defunbbb won't match.")
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
729
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
730 (defvar lisp-flet-regexp
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
731 "(\\(flet\\|macrolet\\|labels\\)\\(\\s-\\|\n\\)")
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
732
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 (defun lisp-indent-function (indent-point state)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 ;; free reference to `calculate-lisp-indent-last-sexp'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 ;; in #'calculate-lisp-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 (let ((normal-indent (current-column)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 (goto-char (1+ (elt state 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 (parse-partial-sexp (point) calculate-lisp-indent-last-sexp 0 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 (if (and (elt state 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 (not (looking-at "\\sw\\|\\s_")))
629
a6c89d799f00 [xemacs-hg @ 2001-07-15 08:18:59 by adrian]
adrian
parents: 613
diff changeset
741 ;; car of form doesn't seem to be a symbol
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 (if (not (> (save-excursion (forward-line 1) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 calculate-lisp-indent-last-sexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 (progn (goto-char calculate-lisp-indent-last-sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 (parse-partial-sexp (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 calculate-lisp-indent-last-sexp 0 t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 ;; Indent under the list or under the first sexp on the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 ;; line as calculate-lisp-indent-last-sexp. Note that first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 ;; thing on that line has to be complete sexp since we are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 ;; inside the innermost containing sexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 (backward-prefix-chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 (current-column))
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
755
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
756 ;; Now come a bunch of ad-hoc checks to see if we're in particular
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
757 ;; places (defining an flet function, in the argument list of a
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
758 ;; regular or flet function, in a quoted list, etc.) where the
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
759 ;; regular indenting doesn't work well.
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
760
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
761 ;; #### All this stuff here should be generalized so that
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
762 ;; you can specify, for various functions, how you want
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
763 ;; particular arguments handled -- in some way that works
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
764 ;; recursively, so it can handle flet and such.
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
765
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
766 (let* ((function (buffer-substring (point)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 (progn (forward-sexp 1) (point))))
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
768 (quote (condition-case nil
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
769 (save-excursion
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
770 (backward-up-list 1)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
771 (memq (char-before (point)) '(?' ?`)))))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
772 method)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
773 (cond
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
774 ;; if we're indenting a quoted list, and the first word is not
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
775 ;; lambda, line up second line below first with no indentation,
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
776 ;; so that property lists indent correctly.
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
777 ((and quote (not (equal function "lambda")))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
778 (setq method 'lisp-indent-quoteform))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
779 ;; do the same if we're indenting the arg list of a def* form.
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
780 ((let ((p (point)))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
781 (condition-case nil
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
782 (save-excursion
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
783 (backward-up-list 2)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
784 ;; make sure we're indeed the second argument of the
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
785 ;; def* form.
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
786 (and (eq (point) (save-excursion
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
787 (goto-char p)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
788 (backward-up-list 1)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
789 (backward-sexp 2)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
790 (1- (point))))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
791 ;; check to see that the function is a def* type
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
792 (eq (char-after) ?\()
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
793 (progn (forward-char 1) t)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
794 (looking-at lisp-function-and-type-regexp)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
795 ;; defstruct may have slot option specs, which
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
796 ;; should probably be reverse-indented like
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
797 ;; normal, because the slot name is the first
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
798 ;; in the list. #### Review this.
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
799 (not (equal (match-string 0) "defstruct"))))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
800 (error nil)))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
801 (setq method 'lisp-indent-quoteform))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
802
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
803 ;; handle functions in flet forms
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
804 ((let ((p (point)))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
805 (condition-case nil
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
806 (save-excursion
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
807 (backward-up-list 3)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
808 ;; make sure we're indeed a function, i.e. inside the
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
809 ;; first form after the flet.
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
810 (and (eq (point) (save-excursion
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
811 (goto-char p)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
812 (backward-up-list 2)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
813 (backward-sexp 1)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
814 (1- (point))))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
815 (looking-at lisp-flet-regexp)))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
816 (error nil)))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
817 (setq method 'defun))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
818
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
819 ;; handle the arg lists in functions in flet forms
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
820 ((let ((p (point)))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
821 (condition-case nil
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
822 (save-excursion
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
823 (backward-up-list 2)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
824 ;; make sure we're indeed the arg list -- i.e. the first
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
825 ;; element after the function name.
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
826 (and (eq (point) (save-excursion
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
827 (goto-char p)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
828 (backward-up-list 1)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
829 (backward-sexp 1)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
830 (1- (point))))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
831 (progn
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
832 (backward-up-list 2)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
833 (looking-at lisp-flet-regexp))))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
834 (error nil)))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
835 (setq method 'lisp-indent-quoteform))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
836 (t
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
837 (setq method
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
838 (or (get (intern-soft function) 'lisp-indent-function)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
839 (get (intern-soft function) 'lisp-indent-hook)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 (cond ((or (eq method 'defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 (and (null method)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 (> (length function) 3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 (string-match "\\`def" function)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 (lisp-indent-defform state indent-point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 ((integerp method)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 (lisp-indent-specform method state
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 indent-point normal-indent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 (method
4942
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
849 (funcall method state indent-point))
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
850 ((and (> (length function) 5)
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
851 (string-match "\\`with-" function))
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
852 (lisp-indent-specform 0 state indent-point normal-indent
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
853 t)))))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
855 (defun lisp-indent-quoteform (state indent-point)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
856 (goto-char (car (cdr state)))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
857 (forward-line 1)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
858 (if (> (point) (car (cdr (cdr state))))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
859 (progn
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
860 (goto-char (car (cdr state)))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
861 (+ 1 (current-column)))))
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
862
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 (defvar lisp-body-indent 2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 "Number of columns to indent the second line of a `(def...)' form.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865
4958
e4bbe5622a80 finish doc comment on `lisp-indent-specform'
Ben Wing <ben@xemacs.org>
parents: 4942
diff changeset
866 ;; Calculate the appropriate indentation for a special form (e.g. defun) or
e4bbe5622a80 finish doc comment on `lisp-indent-specform'
Ben Wing <ben@xemacs.org>
parents: 4942
diff changeset
867 ;; a macro that behaves like a special form (e.g. with-temp-buffer).
e4bbe5622a80 finish doc comment on `lisp-indent-specform'
Ben Wing <ben@xemacs.org>
parents: 4942
diff changeset
868 ;; Return value is as for `calculate-lisp-indent' (q.v.).
e4bbe5622a80 finish doc comment on `lisp-indent-specform'
Ben Wing <ben@xemacs.org>
parents: 4942
diff changeset
869 ;;
4942
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
870 ;; COUNT is the number of "distinguished" forms (e.g. arguments before the
4958
e4bbe5622a80 finish doc comment on `lisp-indent-specform'
Ben Wing <ben@xemacs.org>
parents: 4942
diff changeset
871 ;; "body", in a macro taking a body as its last argument).
e4bbe5622a80 finish doc comment on `lisp-indent-specform'
Ben Wing <ben@xemacs.org>
parents: 4942
diff changeset
872 ;;
e4bbe5622a80 finish doc comment on `lisp-indent-specform'
Ben Wing <ben@xemacs.org>
parents: 4942
diff changeset
873 ;; INDENT-POINT is usually the value of (point) at the beginning of the
e4bbe5622a80 finish doc comment on `lisp-indent-specform'
Ben Wing <ben@xemacs.org>
parents: 4942
diff changeset
874 ;; line containing the form to be indented.
e4bbe5622a80 finish doc comment on `lisp-indent-specform'
Ben Wing <ben@xemacs.org>
parents: 4942
diff changeset
875 ;;
e4bbe5622a80 finish doc comment on `lisp-indent-specform'
Ben Wing <ben@xemacs.org>
parents: 4942
diff changeset
876 ;; STATE is the result of calling (parse-partial-sexp (point) INDENT-POINT)
e4bbe5622a80 finish doc comment on `lisp-indent-specform'
Ben Wing <ben@xemacs.org>
parents: 4942
diff changeset
877 ;; when (point) is sitting on (i.e. just before) the outermost containing
e4bbe5622a80 finish doc comment on `lisp-indent-specform'
Ben Wing <ben@xemacs.org>
parents: 4942
diff changeset
878 ;; left paren for the form to be indented.
e4bbe5622a80 finish doc comment on `lisp-indent-specform'
Ben Wing <ben@xemacs.org>
parents: 4942
diff changeset
879 ;;
e4bbe5622a80 finish doc comment on `lisp-indent-specform'
Ben Wing <ben@xemacs.org>
parents: 4942
diff changeset
880 ;; NORMAL-INDENT is the amount of "full" indentation used for arguments
e4bbe5622a80 finish doc comment on `lisp-indent-specform'
Ben Wing <ben@xemacs.org>
parents: 4942
diff changeset
881 ;; that aren't given some special indentation (usually less), and normally
e4bbe5622a80 finish doc comment on `lisp-indent-specform'
Ben Wing <ben@xemacs.org>
parents: 4942
diff changeset
882 ;; it lines up with the first word after the function name. forms are
e4bbe5622a80 finish doc comment on `lisp-indent-specform'
Ben Wing <ben@xemacs.org>
parents: 4942
diff changeset
883 ;; indented as follows:
4942
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
884 ;;
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
885 ;; -- The first and second distinguished forms are given 2 times body indent
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
886 ;; (determined by `lisp-body-indent')
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
887 ;; -- Other distinguished forms are given normal indent
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
888 ;; -- The first nondistinguished form (the body, usually) is given body indent
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
889 ;; -- Normally, any further nondistinguished forms are given normal indent
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
890 ;; -- However, if INDENT-REMAINING-AS-BODY was specified, any further
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
891 ;; nondistinguished forms are given body indent. This is useful when the
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
892 ;; number of distinguished forms isn't known or may vary.
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
893
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
894 (defun lisp-indent-specform (count state indent-point normal-indent
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
895 &optional indent-remaining-as-body)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 (let ((containing-form-start (elt state 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 (i count)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 body-indent containing-form-column)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 ;; Move to the start of containing form, calculate indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 ;; to use for non-distinguished forms (> count), and move past the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 ;; function symbol. lisp-indent-function guarantees that there is at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 ;; least one word or symbol character following open paren of containing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 ;; form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 (goto-char containing-form-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 (setq containing-form-column (current-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 (setq body-indent (+ lisp-body-indent containing-form-column))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 (forward-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 (forward-sexp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 ;; Now find the start of the last form.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 (parse-partial-sexp (point) indent-point 1 t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 (while (and (< (point) indent-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 (condition-case ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 (setq count (1- count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 (forward-sexp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 (parse-partial-sexp (point) indent-point 1 t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 (error nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 ;; Point is sitting on first character of last (or count) sexp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 (if (> count 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 ;; A distinguished form. If it is the first or second form use double
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 ;; lisp-body-indent, else normal indent. With lisp-body-indent bound
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 ;; to 2 (the default), this just happens to work the same with if as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 ;; the older code, but it makes unwind-protect, condition-case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 ;; with-output-to-temp-buffer, et. al. much more tasteful. The older,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 ;; less hacked, behavior can be obtained by replacing below with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 ;; (list normal-indent containing-form-start).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 (if (<= (- i count) 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 (list (+ containing-form-column (* 2 lisp-body-indent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 containing-form-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 (list normal-indent containing-form-start))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 ;; A non-distinguished form. Use body-indent if there are no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 ;; distinguished forms and this is the first undistinguished form,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 ;; or if this is the first undistinguished form and the preceding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 ;; distinguished form has indentation at least as great as body-indent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 (if (or (and (= i 0) (= count 0))
4942
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
936 (and (or (= count 0) indent-remaining-as-body)
46f0df723e09 (for main branch) Indent all `with-*' expressions correctly
Ben Wing <ben@xemacs.org>
parents: 4677
diff changeset
937 (<= body-indent normal-indent)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 body-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 normal-indent))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 (defun lisp-indent-defform (state indent-point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 (goto-char (car (cdr state)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 (if (> (point) (car (cdr (cdr state))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946 (goto-char (car (cdr state)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 (+ lisp-body-indent (current-column)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 ;; (put 'progn 'lisp-indent-function 0), say, causes progn to be indented
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 ;; like defun if the first form is placed on the next line, otherwise
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 ;; it is indented like any other form (i.e. forms line up under first).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953
776
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
954 ;; NOTE: All def* functions are handled specially, no need to put them here.
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
955 ;; NOTE: All cl-* constructs are handled in cl.el.
79940b592197 [xemacs-hg @ 2002-03-15 07:43:14 by ben]
ben
parents: 771
diff changeset
956
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 (put 'lambda 'lisp-indent-function 'defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 (put 'autoload 'lisp-indent-function 'defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 (put 'progn 'lisp-indent-function 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 (put 'prog1 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 (put 'prog2 'lisp-indent-function 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962 (put 'save-excursion 'lisp-indent-function 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 (put 'save-window-excursion 'lisp-indent-function 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 (put 'save-selected-window 'lisp-indent-function 0)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
965 (put 'with-selected-window 'lisp-indent-function 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 (put 'save-selected-frame 'lisp-indent-function 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 (put 'with-selected-frame 'lisp-indent-function 1)
872
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
968 (put 'save-selected-device 'lisp-indent-function 0)
79c6ff3eef26 [xemacs-hg @ 2002-06-20 21:18:01 by ben]
ben
parents: 844
diff changeset
969 (put 'with-selected-device 'lisp-indent-function 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 (put 'save-restriction 'lisp-indent-function 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 (put 'save-match-data 'lisp-indent-function 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 (put 'let 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 (put 'let* 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 (put 'let-specifier 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 (put 'while 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 (put 'if 'lisp-indent-function 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 (put 'catch 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 (put 'condition-case 'lisp-indent-function 2)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
979 (put 'handler-case 'lisp-indent-function 1)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
980 (put 'handler-bind 'lisp-indent-function 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 (put 'call-with-condition-handler 'lisp-indent-function 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 (put 'unwind-protect 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 (put 'save-current-buffer 'lisp-indent-function 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 (put 'with-current-buffer 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 (put 'with-string-as-buffer-contents 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 (put 'with-temp-file 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 (put 'with-temp-buffer 'lisp-indent-function 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 (put 'with-output-to-string 'lisp-indent-function 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 (put 'with-output-to-temp-buffer 'lisp-indent-function 1)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
990 (put 'with-slots 'lisp-indent-function 2)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
991 (put 'with-open-file 'lisp-indent-function 1)
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
992 (put 'with-open-stream 'lisp-indent-function 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 (put 'eval-after-load 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 (put 'display-message 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 (put 'display-warning 'lisp-indent-function 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 (put 'lmessage 'lisp-indent-function 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
997 (put 'lwarn 'lisp-indent-function 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 (put 'global-set-key 'lisp-indent-function 1)
460
223736d75acb Import from CVS: tag r21-2-45
cvs
parents: 446
diff changeset
999 (put 'print-unreadable-object 'lisp-indent-function 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 (defun indent-sexp (&optional endpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 "Indent each line of the list starting just after point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 If optional arg ENDPOS is given, indent each line, stopping when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 ENDPOS is encountered."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 (let ((indent-stack (list nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 (next-depth 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 ;; If ENDPOS is non-nil, use nil as STARTING-POINT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 ;; so that calculate-lisp-indent will find the beginning of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 ;; the defun we are in.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 ;; If ENDPOS is nil, it is safe not to scan before point
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 ;; since every line we indent is more deeply nested than point is.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 (starting-point (if endpos nil (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 (last-point (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 last-depth bol outer-loop-done inner-loop-done state this-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 (or endpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 ;; Get error now if we don't have a complete sexp after point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 (save-excursion (forward-sexp 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 (setq outer-loop-done nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 (while (if endpos (< (point) endpos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 (not outer-loop-done))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 (setq last-depth next-depth
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 inner-loop-done nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 ;; Parse this line so we can learn the state
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 ;; to indent the next line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 ;; This inner loop goes through only once
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 ;; unless a line ends inside a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 (while (and (not inner-loop-done)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 (not (setq outer-loop-done (eobp))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 nil nil state))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 (setq next-depth (car state))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 ;; If the line contains a comment other than the sort
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 ;; that is indented like code,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 ;; indent it now with indent-for-comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 ;; Comments indented like code are right already.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 ;; In any case clear the in-comment flag in the state
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 ;; because parse-partial-sexp never sees the newlines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 (if (car (nthcdr 4 state))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 (progn (indent-for-comment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 (end-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 (setcar (nthcdr 4 state) nil)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 ;; If this line ends inside a string,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 ;; go straight to next line, remaining within the inner loop,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 ;; and turn off the \-flag.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 (if (car (nthcdr 3 state))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 (setcar (nthcdr 5 state) nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 (setq inner-loop-done t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 (and endpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 (<= next-depth 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 (setq indent-stack (append indent-stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 (make-list (- next-depth) nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057 last-depth (- last-depth next-depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 next-depth 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 (or outer-loop-done endpos
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 (setq outer-loop-done (<= next-depth 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 (if outer-loop-done
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1063 (while (> last-depth next-depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 (setq indent-stack (cdr indent-stack)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 last-depth (1- last-depth)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 (while (< last-depth next-depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 (setq indent-stack (cons nil indent-stack)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 last-depth (1+ last-depth)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 ;; Now go to the next line and indent it according
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 ;; to what we learned from parsing the previous one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 (setq bol (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 ;; But not if the line is blank, or just a comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 ;; (except for double-semi comments; indent them as usual).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076 (if (or (eobp) (looking-at "\\s<\\|\n"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 (if (and (car indent-stack)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 (>= (car indent-stack) 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 (setq this-indent (car indent-stack))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 (let ((val (calculate-lisp-indent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082 (if (car indent-stack) (- (car indent-stack))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 starting-point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 (if (integerp val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 (setcar indent-stack
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086 (setq this-indent val))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 (setcar indent-stack (- (car (cdr val))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 (setq this-indent (car val)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 (if (/= (current-column) this-indent)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 (progn (delete-region bol (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 (indent-to this-indent)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092 (or outer-loop-done
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 (setq outer-loop-done (= (point) last-point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 (setq last-point (point)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 ;; Indent every line whose first char is between START and END inclusive.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 (defun lisp-indent-region (start end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 (let ((endmark (copy-marker end)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 (goto-char start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 (and (bolp) (not (eolp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 (lisp-indent-line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 (indent-sexp endmark)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 (set-marker endmark nil))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 ;;;; Lisp paragraph filling commands.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 (defun lisp-fill-paragraph (&optional justify)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 "Like \\[fill-paragraph], but handle Emacs Lisp comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 If any of the current line is a comment, fill the comment or the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 paragraph of it that point is in, preserving the comment's indentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 and initial semicolons."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 (let (
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 ;; Non-nil if the current line contains a comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 has-comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 ;; Non-nil if the current line contains code and a comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 has-code-and-comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 ;; If has-comment, the appropriate fill-prefix for the comment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 comment-fill-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 ;; Figure out what kind of comment we are looking at.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 ;; A line with nothing but a comment on it?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 ((looking-at "[ \t]*;[; \t]*")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 (setq has-comment t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 comment-fill-prefix (buffer-substring (match-beginning 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 (match-end 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 ;; A line with some code, followed by a comment? Remember that the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 ;; semi which starts the comment shouldn't be part of a string or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 ;; character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 ;; XEmacs Try this the FSF and see if it works.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 ; ((progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 ; (while (not (looking-at ";\\|$"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 ; (skip-chars-forward "^;\n\"\\\\?")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 ; (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 ; ((eq (char-after (point)) ?\\) (forward-char 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 ; ((memq (char-after (point)) '(?\" ??)) (forward-sexp 1))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1146 ; (looking-at ";+[\t ]*"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 ; (setq has-comment t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1148 ((condition-case nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 (narrow-to-region (point-min)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 (save-excursion (end-of-line) (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 (while (not (looking-at ";\\|$"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 (skip-chars-forward "^;\n\"\\\\?")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 (cond
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 ((eq (char-after (point)) ?\\) (forward-char 2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 ((memq (char-after (point)) '(?\" ??)) (forward-sexp 1))))
844
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 800
diff changeset
1157 ;; don't do comment filling in a string, or we will mess up
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 800
diff changeset
1158 ;; doc strings and other places where semicolons are used.
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 800
diff changeset
1159 (and (not (eq 'string (buffer-syntactic-context)))
047d37eb70d7 [xemacs-hg @ 2002-05-16 13:30:23 by ben]
ben
parents: 800
diff changeset
1160 (looking-at ";+[\t ]*")))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 (error nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 (setq has-comment t has-code-and-comment t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 (setq comment-fill-prefix
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 (concat (make-string (/ (current-column) 8) ?\t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 (make-string (% (current-column) 8) ?\ )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 (buffer-substring (match-beginning 0) (match-end 0)))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168 (if (not has-comment)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 (fill-paragraph justify)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 ;; Narrow to include only the comment, and then fill the region.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 (save-restriction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 (beginning-of-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 (narrow-to-region
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 ;; Find the first line we should include in the region to fill.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 (while (and (zerop (forward-line -1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 (looking-at "^[ \t]*;")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 ;; We may have gone too far. Go forward again.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 (or (looking-at ".*;")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 (forward-line 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 ;; Find the beginning of the first line past the region to fill.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 (while (progn (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 (looking-at "^[ \t]*;")))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 ;; Lines with only semicolons on them can be paragraph boundaries.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 (let* ((paragraph-start (concat paragraph-start "\\|[ \t;]*$"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 (paragraph-separate (concat paragraph-start "\\|[ \t;]*$"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 (paragraph-ignore-fill-prefix nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 (fill-prefix comment-fill-prefix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 (after-line (if has-code-and-comment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197 (forward-line 1) (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 (end (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 (forward-paragraph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 (or (bolp) (newline 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 ;; If this comment starts on a line with code,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 ;; include that like in the filling.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 (beg (progn (backward-paragraph)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 (if (eq (point) after-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 (forward-line -1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 (fill-region-as-paragraph beg end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 justify nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 (goto-char beg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 (if (looking-at fill-prefix)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 (re-search-forward comment-start-skip)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 (point))))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 (defun indent-code-rigidly (start end arg &optional nochange-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219 "Indent all lines of code, starting in the region, sideways by ARG columns.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 Does not affect lines starting inside comments or strings, assuming that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 the start of the region is not inside them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 Called from a program, takes args START, END, COLUMNS and NOCHANGE-REGEXP.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 The last is a regexp which, if matched at the beginning of a line,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 means don't indent that line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226 (interactive "r\np")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 (let (state)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229 (goto-char end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 (setq end (point-marker))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 (goto-char start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 (or (bolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 (setq state (parse-partial-sexp (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235 (forward-line 1) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 nil nil state)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 (while (< (point) end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 (or (car (nthcdr 3 state))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 (and nochange-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240 (looking-at nochange-regexp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 ;; If line does not start in string, indent it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 (let ((indent (current-indentation)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 (delete-region (point) (progn (skip-chars-forward " \t") (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 (or (eolp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 (indent-to (max 0 (+ indent arg)) 0))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 (setq state (parse-partial-sexp (point)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 (forward-line 1) (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 nil nil state))))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 (provide 'lisp-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 ;;; lisp-mode.el ends here