annotate lisp/lisp.el @ 665:fdefd0186b75

[xemacs-hg @ 2001-09-20 06:28:42 by ben] The great integral types renaming. The purpose of this is to rationalize the names used for various integral types, so that they match their intended uses and follow consist conventions, and eliminate types that were not semantically different from each other. The conventions are: -- All integral types that measure quantities of anything are signed. Some people disagree vociferously with this, but their arguments are mostly theoretical, and are vastly outweighed by the practical headaches of mixing signed and unsigned values, and more importantly by the far increased likelihood of inadvertent bugs: Because of the broken "viral" nature of unsigned quantities in C (operations involving mixed signed/unsigned are done unsigned, when exactly the opposite is nearly always wanted), even a single error in declaring a quantity unsigned that should be signed, or even the even more subtle error of comparing signed and unsigned values and forgetting the necessary cast, can be catastrophic, as comparisons will yield wrong results. -Wsign-compare is turned on specifically to catch this, but this tends to result in a great number of warnings when mixing signed and unsigned, and the casts are annoying. More has been written on this elsewhere. -- All such quantity types just mentioned boil down to EMACS_INT, which is 32 bits on 32-bit machines and 64 bits on 64-bit machines. This is guaranteed to be the same size as Lisp objects of type `int', and (as far as I can tell) of size_t (unsigned!) and ssize_t. The only type below that is not an EMACS_INT is Hashcode, which is an unsigned value of the same size as EMACS_INT. -- Type names should be relatively short (no more than 10 characters or so), with the first letter capitalized and no underscores if they can at all be avoided. -- "count" == a zero-based measurement of some quantity. Includes sizes, offsets, and indexes. -- "bpos" == a one-based measurement of a position in a buffer. "Charbpos" and "Bytebpos" count text in the buffer, rather than bytes in memory; thus Bytebpos does not directly correspond to the memory representation. Use "Membpos" for this. -- "Char" refers to internal-format characters, not to the C type "char", which is really a byte. -- For the actual name changes, see the script below. I ran the following script to do the conversion. (NOTE: This script is idempotent. You can safely run it multiple times and it will not screw up previous results -- in fact, it will do nothing if nothing has changed. Thus, it can be run repeatedly as necessary to handle patches coming in from old workspaces, or old branches.) There are two tags, just before and just after the change: `pre-integral-type-rename' and `post-integral-type-rename'. When merging code from the main trunk into a branch, the best thing to do is first merge up to `pre-integral-type-rename', then apply the script and associated changes, then merge from `post-integral-type-change' to the present. (Alternatively, just do the merging in one operation; but you may then have a lot of conflicts needing to be resolved by hand.) Script `fixtypes.sh' follows: ----------------------------------- cut ------------------------------------ files="*.[ch] s/*.h m/*.h config.h.in ../configure.in Makefile.in.in ../lib-src/*.[ch] ../lwlib/*.[ch]" gr Memory_Count Bytecount $files gr Lstream_Data_Count Bytecount $files gr Element_Count Elemcount $files gr Hash_Code Hashcode $files gr extcount bytecount $files gr bufpos charbpos $files gr bytind bytebpos $files gr memind membpos $files gr bufbyte intbyte $files gr Extcount Bytecount $files gr Bufpos Charbpos $files gr Bytind Bytebpos $files gr Memind Membpos $files gr Bufbyte Intbyte $files gr EXTCOUNT BYTECOUNT $files gr BUFPOS CHARBPOS $files gr BYTIND BYTEBPOS $files gr MEMIND MEMBPOS $files gr BUFBYTE INTBYTE $files gr MEMORY_COUNT BYTECOUNT $files gr LSTREAM_DATA_COUNT BYTECOUNT $files gr ELEMENT_COUNT ELEMCOUNT $files gr HASH_CODE HASHCODE $files ----------------------------------- cut ------------------------------------ `fixtypes.sh' is a Bourne-shell script; it uses 'gr': ----------------------------------- cut ------------------------------------ #!/bin/sh # Usage is like this: # gr FROM TO FILES ... # globally replace FROM with TO in FILES. FROM and TO are regular expressions. # backup files are stored in the `backup' directory. from="$1" to="$2" shift 2 echo ${1+"$@"} | xargs global-replace "s/$from/$to/g" ----------------------------------- cut ------------------------------------ `gr' in turn uses a Perl script to do its real work, `global-replace', which follows: ----------------------------------- cut ------------------------------------ : #-*- Perl -*- ### global-modify --- modify the contents of a file by a Perl expression ## Copyright (C) 1999 Martin Buchholz. ## Copyright (C) 2001 Ben Wing. ## Authors: Martin Buchholz <martin@xemacs.org>, Ben Wing <ben@xemacs.org> ## Maintainer: Ben Wing <ben@xemacs.org> ## Current Version: 1.0, May 5, 2001 # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with XEmacs; see the file COPYING. If not, write to the Free # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. eval 'exec perl -w -S $0 ${1+"$@"}' if 0; use strict; use FileHandle; use Carp; use Getopt::Long; use File::Basename; (my $myName = $0) =~ s@.*/@@; my $usage=" Usage: $myName [--help] [--backup-dir=DIR] [--line-mode] [--hunk-mode] PERLEXPR FILE ... Globally modify a file, either line by line or in one big hunk. Typical usage is like this: [with GNU print, GNU xargs: guaranteed to handle spaces, quotes, etc. in file names] find . -name '*.[ch]' -print0 | xargs -0 $0 's/\bCONST\b/const/g'\n [with non-GNU print, xargs] find . -name '*.[ch]' -print | xargs $0 's/\bCONST\b/const/g'\n The file is read in, either line by line (with --line-mode specified) or in one big hunk (with --hunk-mode specified; it's the default), and the Perl expression is then evalled with \$_ set to the line or hunk of text, including the terminating newline if there is one. It should destructively modify the value there, storing the changed result in \$_. Files in which any modifications are made are backed up to the directory specified using --backup-dir, or to `backup' by default. To disable this, use --backup-dir= with no argument. Hunk mode is the default because it is MUCH MUCH faster than line-by-line. Use line-by-line only when it matters, e.g. you want to do a replacement only once per line (the default without the `g' argument). Conversely, when using hunk mode, *ALWAYS* use `g'; otherwise, you will only make one replacement in the entire file! "; my %options = (); $Getopt::Long::ignorecase = 0; &GetOptions ( \%options, 'help', 'backup-dir=s', 'line-mode', 'hunk-mode', ); die $usage if $options{"help"} or @ARGV <= 1; my $code = shift; die $usage if grep (-d || ! -w, @ARGV); sub SafeOpen { open ((my $fh = new FileHandle), $_[0]); confess "Can't open $_[0]: $!" if ! defined $fh; return $fh; } sub SafeClose { close $_[0] or confess "Can't close $_[0]: $!"; } sub FileContents { my $fh = SafeOpen ("< $_[0]"); my $olddollarslash = $/; local $/ = undef; my $contents = <$fh>; $/ = $olddollarslash; return $contents; } sub WriteStringToFile { my $fh = SafeOpen ("> $_[0]"); binmode $fh; print $fh $_[1] or confess "$_[0]: $!\n"; SafeClose $fh; } foreach my $file (@ARGV) { my $changed_p = 0; my $new_contents = ""; if ($options{"line-mode"}) { my $fh = SafeOpen $file; while (<$fh>) { my $save_line = $_; eval $code; $changed_p = 1 if $save_line ne $_; $new_contents .= $_; } } else { my $orig_contents = $_ = FileContents $file; eval $code; if ($_ ne $orig_contents) { $changed_p = 1; $new_contents = $_; } } if ($changed_p) { my $backdir = $options{"backup-dir"}; $backdir = "backup" if !defined ($backdir); if ($backdir) { my ($name, $path, $suffix) = fileparse ($file, ""); my $backfulldir = $path . $backdir; my $backfile = "$backfulldir/$name"; mkdir $backfulldir, 0755 unless -d $backfulldir; print "modifying $file (original saved in $backfile)\n"; rename $file, $backfile; } WriteStringToFile ($file, $new_contents); } } ----------------------------------- cut ------------------------------------ In addition to those programs, I needed to fix up a few other things, particularly relating to the duplicate definitions of types, now that some types merged with others. Specifically: 1. in lisp.h, removed duplicate declarations of Bytecount. The changed code should now look like this: (In each code snippet below, the first and last lines are the same as the original, as are all lines outside of those lines. That allows you to locate the section to be replaced, and replace the stuff in that section, verifying that there isn't anything new added that would need to be kept.) --------------------------------- snip ------------------------------------- /* Counts of bytes or chars */ typedef EMACS_INT Bytecount; typedef EMACS_INT Charcount; /* Counts of elements */ typedef EMACS_INT Elemcount; /* Hash codes */ typedef unsigned long Hashcode; /* ------------------------ dynamic arrays ------------------- */ --------------------------------- snip ------------------------------------- 2. in lstream.h, removed duplicate declaration of Bytecount. Rewrote the comment about this type. The changed code should now look like this: --------------------------------- snip ------------------------------------- #endif /* The have been some arguments over the what the type should be that specifies a count of bytes in a data block to be written out or read in, using Lstream_read(), Lstream_write(), and related functions. Originally it was long, which worked fine; Martin "corrected" these to size_t and ssize_t on the grounds that this is theoretically cleaner and is in keeping with the C standards. Unfortunately, this practice is horribly error-prone due to design flaws in the way that mixed signed/unsigned arithmetic happens. In fact, by doing this change, Martin introduced a subtle but fatal error that caused the operation of sending large mail messages to the SMTP server under Windows to fail. By putting all values back to be signed, avoiding any signed/unsigned mixing, the bug immediately went away. The type then in use was Lstream_Data_Count, so that it be reverted cleanly if a vote came to that. Now it is Bytecount. Some earlier comments about why the type must be signed: This MUST BE SIGNED, since it also is used in functions that return the number of bytes actually read to or written from in an operation, and these functions can return -1 to signal error. Note that the standard Unix read() and write() functions define the count going in as a size_t, which is UNSIGNED, and the count going out as an ssize_t, which is SIGNED. This is a horrible design flaw. Not only is it highly likely to lead to logic errors when a -1 gets interpreted as a large positive number, but operations are bound to fail in all sorts of horrible ways when a number in the upper-half of the size_t range is passed in -- this number is unrepresentable as an ssize_t, so code that checks to see how many bytes are actually written (which is mandatory if you are dealing with certain types of devices) will get completely screwed up. --ben */ typedef enum lstream_buffering --------------------------------- snip ------------------------------------- 3. in dumper.c, there are four places, all inside of switch() statements, where XD_BYTECOUNT appears twice as a case tag. In each case, the two case blocks contain identical code, and you should *REMOVE THE SECOND* and leave the first.
author ben
date Thu, 20 Sep 2001 06:31:11 +0000
parents 1ccc32a20af4
children c136144fe765
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.el --- Lisp editing commands for XEmacs
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, 1986, 1994, 1997 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 ;; Maintainer: FSF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 ;; Keywords: lisp, languages, dumped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
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 ;; XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ;; any later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 ;; General Public License for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 ;; 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
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 ;; 02111-1307, USA.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 ;;; Synched up with: Emacs/Mule zeta.
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 ;;; Commentary:
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 ;; This file is dumped with XEmacs.
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 ;; Lisp editing commands to go with Lisp major mode.
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 ;; 06/11/1997 - Use char-(after|before) instead of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 ;; (following|preceding)-char. -slb
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 ;; Note that this variable is used by non-lisp modes too.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 (defcustom defun-prompt-regexp nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 "*Non-nil => regexp to ignore, before the character that starts a defun.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 This is only necessary if the opening paren or brace is not in column 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 See `beginning-of-defun'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 :type '(choice (const :tag "none" nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 :group 'lisp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 (make-variable-buffer-local 'defun-prompt-regexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 (defcustom parens-require-spaces t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 "Non-nil => `insert-parentheses' should insert whitespace as needed."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 :type 'boolean
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 :group 'editing-basics
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 :group 'lisp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 (defun forward-sexp (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 "Move forward across one balanced expression (sexp).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 With argument, do it that many times. Negative arg -N means
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 move backward across N balanced expressions."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 ;; XEmacs change (for zmacs regions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 (interactive "_p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 (or arg (setq arg 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 ;; XEmacs: evil hack! The other half of the evil hack below.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 (if (and (> arg 0) (looking-at "#s("))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 (goto-char (+ (point) 2)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 (goto-char (or (scan-sexps (point) arg) (buffer-end arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 (if (< arg 0) (backward-prefix-chars))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 ;; XEmacs: evil hack! Skip back over #s so that structures are read
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 ;; properly. the current cheesified syntax tables just aren't up to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 ;; this.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 (if (and (< arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 (eq (char-after (point)) ?\()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 (>= (- (point) (point-min)) 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 (eq (char-after (- (point) 1)) ?s)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 (eq (char-after (- (point) 2)) ?#))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 (goto-char (- (point) 2))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 (defun backward-sexp (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 "Move backward across one balanced expression (sexp).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 With argument, do it that many times. Negative arg -N means
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 move forward across N balanced expressions."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 ;; XEmacs change (for zmacs regions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 (interactive "_p")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
83 (forward-sexp (- (or arg 1))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
85 (defun mark-sexp (&optional arg)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 "Set mark ARG sexps from point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 The place mark goes is the same place \\[forward-sexp] would
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 move to with the same argument.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 Repeat this command to mark more sexps in the same direction."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 (interactive "p")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
91 (mark-something 'mark-sexp 'forward-sexp (or arg 1)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 (defun forward-list (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 "Move forward across one balanced group of parentheses.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 With argument, do it that many times.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 Negative arg -N means move backward across N groups of parentheses."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 (interactive "_p")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
99 (goto-char (or (scan-lists (point) (or arg 1) 0) (buffer-end (or arg 1)))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 (defun backward-list (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 "Move backward across one balanced group of parentheses.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 With argument, do it that many times.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 Negative arg -N means move forward across N groups of parentheses."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 ;; XEmacs change (for zmacs regions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 (interactive "_p")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
107 (forward-list (- (or arg 1))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
109 (defun down-list (&optional arg)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 "Move forward down one level of parentheses.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 With argument, do this that many times.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
112 A negative argument means move backward but still go down a level."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 ;; XEmacs change (for zmacs regions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 (interactive "_p")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
115 (or arg (setq arg 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 (let ((inc (if (> arg 0) 1 -1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 (while (/= arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 (goto-char (or (scan-lists (point) inc -1) (buffer-end arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 (setq arg (- arg inc)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
121 (defun backward-up-list (&optional arg)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 "Move backward out of one level of parentheses.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 With argument, do this that many times.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
124 A negative argument means move forward but still to a less deep spot."
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 (interactive "_p")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
126 (up-list (- (or arg 1))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
128 (defun up-list (&optional arg)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 "Move forward out of one level of parentheses.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 With argument, do this that many times.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 A negative argument means move backward but still to a less deep spot.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 In Lisp programs, an argument is required."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 ;; XEmacs change (for zmacs regions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 (interactive "_p")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
135 (or arg (setq arg 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 (let ((inc (if (> arg 0) 1 -1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 (while (/= arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 (goto-char (or (scan-lists (point) inc 1) (buffer-end arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 (setq arg (- arg inc)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
141 (defun kill-sexp (&optional arg)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 "Kill the sexp (balanced expression) following the cursor.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 With argument, kill that many sexps after the cursor.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 Negative arg -N means kill N sexps before the cursor."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 (let ((opoint (point)))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
147 (forward-sexp (or arg 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 (kill-region opoint (point))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
150 (defun backward-kill-sexp (&optional arg)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 "Kill the sexp (balanced expression) preceding the cursor.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 With argument, kill that many sexps before the cursor.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 Negative arg -N means kill N sexps after the cursor."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 (interactive "p")
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
155 (kill-sexp (- (or arg 1))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 (defun beginning-of-defun (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 "Move backward to the beginning of a defun.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 With argument, do it that many times. Negative arg -N
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 means move forward to Nth following beginning of defun.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 Returns t unless search stops due to beginning or end of buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 Normally a defun starts when there is an char with open-parenthesis
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 syntax at the beginning of a line. If `defun-prompt-regexp' is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 non-nil, then a string which matches that regexp may precede the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 open-parenthesis, and point ends up at the beginning of the line."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 ;; XEmacs change (for zmacs regions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 (interactive "_p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 (and (beginning-of-defun-raw arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 (progn (beginning-of-line) t)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 (defun beginning-of-defun-raw (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 "Move point to the character that starts a defun.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 This is identical to beginning-of-defun, except that point does not move
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 to the beginning of the line when `defun-prompt-regexp' is non-nil."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 (interactive "p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 (and arg (< arg 0) (not (eobp)) (forward-char 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 (and (re-search-backward (if defun-prompt-regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 (concat "^\\s(\\|"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 "\\(" defun-prompt-regexp "\\)\\s(")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 "^\\s(")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 nil 'move (or arg 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 (progn (goto-char (1- (match-end 0)))) t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 ;; XEmacs change (optional buffer parameter)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 (defun buffer-end (arg &optional buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 "Return `point-max' of BUFFER if ARG is > 0; return `point-min' otherwise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 BUFFER defaults to the current buffer if omitted."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 (if (> arg 0) (point-max buffer) (point-min buffer)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 (defun end-of-defun (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 "Move forward to next end of defun. With argument, do it that many times.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 Negative argument -N means move back to Nth preceding end of defun.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 An end of a defun occurs right after the close-parenthesis that matches
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 the open-parenthesis that starts a defun; see `beginning-of-defun'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 ;; XEmacs change (for zmacs regions)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 (interactive "_p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 (if (or (null arg) (= arg 0)) (setq arg 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 (let ((first t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 (while (and (> arg 0) (< (point) (point-max)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 (let ((pos (point))) ; XEmacs -- remove unused npos.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 (while (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 (if (and first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 (end-of-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 (beginning-of-defun-raw 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 nil
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
209 (or (bobp) (backward-char 1))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 (beginning-of-defun-raw -1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 (setq first nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 (forward-list 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 (if (looking-at "\\s<\\|\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 (forward-line 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 (<= (point) pos))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 (setq arg (1- arg)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 (while (< arg 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 (let ((pos (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 (beginning-of-defun-raw 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 (forward-sexp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 (forward-line 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 (if (>= (point) pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 (if (beginning-of-defun-raw 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 (progn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 (forward-list 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 (skip-chars-forward " \t")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 (if (looking-at "\\s<\\|\n")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 (forward-line 1)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 (goto-char (point-min)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 (setq arg (1+ arg)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 (defun mark-defun ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 "Put mark at end of this defun, point at beginning.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 The defun marked is the one that contains point or follows point."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 (push-mark (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 (end-of-defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 (push-mark (point) nil t)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (beginning-of-defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 (re-search-backward "^\n" (- (point) 1) t))
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 (defun narrow-to-defun (&optional arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 "Make text outside current defun invisible.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 The defun visible is the one that contains point or follows point."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 (widen)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 (end-of-defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 (let ((end (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 (beginning-of-defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 (narrow-to-region (point) end))))
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 (defun insert-parentheses (arg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 "Enclose following ARG sexps in parentheses. Leave point after open-paren.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 A negative ARG encloses the preceding ARG sexps instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 No argument is equivalent to zero: just insert `()' and leave point between.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 If `parens-require-spaces' is non-nil, this command also inserts a space
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 before and after, depending on the surrounding characters."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 (interactive "P")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 (if arg (setq arg (prefix-numeric-value arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 (setq arg 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 (cond ((> arg 0) (skip-chars-forward " \t"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 ((< arg 0) (forward-sexp arg) (setq arg (- arg))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 (and parens-require-spaces
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 (not (bobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 (memq (char-syntax (char-before (point))) '(?w ?_ ?\) ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 (insert " "))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 (insert ?\()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 (or (eq arg 0) (forward-sexp arg))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 (insert ?\))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 (and parens-require-spaces
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 (not (eobp))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 (memq (char-syntax (char-after (point))) '(?w ?_ ?\( ))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 (insert " "))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 (defun move-past-close-and-reindent ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 "Move past next `)', delete indentation before it, then indent after it."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 (up-list 1)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
282 (backward-char 1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 (while (save-excursion ; this is my contribution
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 (let ((before-paren (point)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 (back-to-indentation)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 (= (point) before-paren)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 (delete-indentation))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 (forward-char 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 (newline-and-indent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 (defun lisp-complete-symbol ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 "Perform completion on Lisp symbol preceding point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 Compare that symbol against the known Lisp symbols.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 The context determines which symbols are considered.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 If the symbol starts just after an open-parenthesis, only symbols
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 with function definitions are considered. Otherwise, all symbols with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 function definitions, values or properties are considered."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 (let* ((end (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 (buffer-syntax (syntax-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 (beg (unwind-protect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 (if emacs-lisp-mode-syntax-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 (set-syntax-table emacs-lisp-mode-syntax-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 (backward-sexp 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 (while (eq (char-syntax (char-after (point))) ?\')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 (forward-char 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 (point))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 (set-syntax-table buffer-syntax)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 (pattern (buffer-substring beg end))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 (predicate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 (if (eq (char-after (1- beg)) ?\()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 'fboundp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 ;; XEmacs change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 #'(lambda (sym)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 (or (boundp sym) (fboundp sym)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 (symbol-plist sym)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 (completion (try-completion pattern obarray predicate)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 (cond ((eq completion t))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 ((null completion)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 (message "Can't find completion for \"%s\"" pattern)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 (ding))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 ((not (string= pattern completion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 (delete-region beg end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 (insert completion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 (t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 (message "Making completion list...")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 (let ((list (all-completions pattern obarray predicate))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 ;FSFmacs crock unnecessary in XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 ;see minibuf.el
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 ;(completion-fixup-function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 ; (function (lambda () (if (save-excursion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 ; (goto-char (max (point-min)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 ; (- (point) 4)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 ; (looking-at " <f>"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 ; (forward-char -4))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 (or (eq predicate 'fboundp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 (let (new)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 (while list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 (setq new (cons (if (fboundp (intern (car list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 (list (car list) " <f>")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 (car list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 new))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 (setq list (cdr list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 (setq list (nreverse new))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 (with-output-to-temp-buffer "*Completions*"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 (display-completion-list list)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 (message "Making completion list...%s" "done")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 ;;; lisp.el ends here