Changeset 4228

Show
Ignore:
Timestamp:
04/06/08 15:46:06 (8 months ago)
Author:
miyoshi
Message:

--

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/4.00-dev/info

    • Property svn:ignore changed from
      ada-mode
      autotype
      calc
      calc-1
      calc-2
      calc-3
      calc-4
      calc-5
      calc-6
      ccmode
      cl
      dired-x
      ebrowse
      ediff
      efaq
      eintr
      eintr-1
      eintr-2
      eintr-3
      elisp
      elisp-1
      elisp-10
      elisp-11
      elisp-2
      elisp-3
      elisp-4
      elisp-5
      elisp-6
      elisp-7
      elisp-8
      elisp-9
      emacs
      emacs-1
      emacs-2
      emacs-3
      emacs-4
      emacs-5
      emacs-6
      emacs-7
      emacs-8
      emacs-mime
      emacs-xtra
      eshell
      eudc
      flymake
      forms
      gnus
      gnus-1
      gnus-2
      gnus-3
      gnus-4
      gnus-5
      idlwave
      info
      message
      mh-e
      org
      pcl-cvs
      pgg
      rcirc
      reftex
      sc
      ses
      sieve
      smtpmail
      speedbar
      tramp
      url
      vip
      viper
      widget
      woman
      newsticker
      erc
      mh-e-2
      mh-e-1
      org-1
      ccmode-1
      org-2
      to
      ada-mode
      autotype
      calc
      calc-1
      calc-2
      calc-3
      calc-4
      calc-5
      calc-6
      ccmode
      cl
      dired-x
      ebrowse
      ediff
      efaq
      eintr
      eintr-1
      eintr-2
      eintr-3
      elisp
      elisp-1
      elisp-10
      elisp-11
      elisp-2
      elisp-3
      elisp-4
      elisp-5
      elisp-6
      elisp-7
      elisp-8
      elisp-9
      emacs
      emacs-1
      emacs-2
      emacs-3
      emacs-4
      emacs-5
      emacs-6
      emacs-7
      emacs-8
      emacs-mime
      emacs-xtra
      eshell
      eudc
      flymake
      forms
      gnus
      gnus-1
      gnus-2
      gnus-3
      gnus-4
      gnus-5
      idlwave
      info
      message
      mh-e
      org
      pcl-cvs
      pgg
      rcirc
      reftex
      sc
      ses
      sieve
      smtpmail
      speedbar
      tramp
      url
      vip
      viper
      widget
      woman
      newsticker
      erc
      mh-e-2
      mh-e-1
      org-1
      ccmode-1
      org-2
      ccmode-2
      dbus
      epa
      nxml-mode
      remember
  • branches/4.00-dev/lisp/ChangeLog.Meadow

    r4220 r4228  
     12008-04-06  MIYOSHI Masanori  <miyoshi@meadowy.org> 
     2 
     3        * abbrev.el: Sync up with Emacs CVS HEAD. 
     4 
     5        * emacs-lisp/lisp-mode.el:  
     6 
     7        * loadup.el: Ditto. 
     8 
    192008-04-04  MIYOSHI Masanori  <miyoshi@meadowy.org> 
    210 
  • branches/4.00-dev/lisp/abbrev.el

    r4220 r4228  
    2828;; This facility is documented in the Emacs Manual. 
    2929 
     30;; Todo: 
     31 
     32;; - Make abbrev-file-name obey user-emacs-directory. 
     33;; - Cleanup name space. 
     34 
    3035;;; Code: 
     36 
     37(eval-when-compile (require 'cl)) 
     38 
     39(defgroup abbrev-mode nil 
     40  "Word abbreviations mode." 
     41  :link '(custom-manual "(emacs)Abbrevs") 
     42  :group 'abbrev) 
    3143 
    3244(defcustom only-global-abbrevs nil 
     
    3850  :group 'convenience) 
    3951 
    40 (defun abbrev-mode (&optional arg) 
     52(define-minor-mode abbrev-mode 
    4153  "Toggle Abbrev mode in the current buffer. 
    4254With optional argument ARG, turn abbrev mode on if ARG is 
    4355positive, otherwise turn it off.  In Abbrev mode, inserting an 
    44 abbreviation causes it to expand and be replaced by its expansion." 
    45   (interactive "P") 
    46   (setq abbrev-mode 
    47         (if (null arg) (not abbrev-mode) 
    48           (> (prefix-numeric-value arg) 0))) 
    49   (force-mode-line-update)) 
     56abbreviation causes it to expand and be replaced by its expansion.") 
    5057 
    5158(defcustom abbrev-mode nil 
     
    5966  :type 'boolean 
    6067  :group 'abbrev-mode) 
    61 ;;;###autoload(put 'abbrev-mode 'safe-local-variable 'booleanp) 
     68(put 'abbrev-mode 'safe-local-variable 'booleanp) 
    6269 
    6370  
     
    7279  "Undefine all defined abbrevs." 
    7380  (interactive) 
    74   (let ((tables abbrev-table-name-list)) 
    75     (while tables 
    76       (clear-abbrev-table (symbol-value (car tables))) 
    77       (setq tables (cdr tables))))) 
     81  (dolist (tablesym abbrev-table-name-list) 
     82    (clear-abbrev-table (symbol-value tablesym)))) 
    7883 
    7984(defun copy-abbrev-table (table) 
     
    95100  (push-mark 
    96101   (save-excursion 
    97      (let ((tables abbrev-table-name-list)) 
    98        (while tables 
    99          (insert-abbrev-table-description (car tables) t) 
    100          (setq tables (cdr tables)))) 
     102     (dolist (tablesym abbrev-table-name-list) 
     103       (insert-abbrev-table-description tablesym t)) 
    101104     (point)))) 
    102105 
     
    120123 
    121124(defun prepare-abbrev-list-buffer (&optional local) 
    122   (save-excursion 
    123     (let ((table local-abbrev-table)) 
    124       (set-buffer (get-buffer-create "*Abbrevs*")) 
    125       (erase-buffer) 
    126       (if local 
    127           (insert-abbrev-table-description (abbrev-table-name table) t) 
    128         (dolist (table abbrev-table-name-list) 
    129           (insert-abbrev-table-description table t))) 
    130       (goto-char (point-min)) 
    131       (set-buffer-modified-p nil) 
    132       (edit-abbrevs-mode) 
    133       (current-buffer)))) 
     125  (with-current-buffer (get-buffer-create "*Abbrevs*") 
     126    (erase-buffer) 
     127    (if local 
     128        (insert-abbrev-table-description 
     129         (abbrev-table-name local-abbrev-table) t) 
     130      (dolist (table abbrev-table-name-list) 
     131        (insert-abbrev-table-description table t))) 
     132    (goto-char (point-min)) 
     133    (set-buffer-modified-p nil) 
     134    (edit-abbrevs-mode) 
     135    (current-buffer))) 
    134136 
    135137(defun edit-abbrevs-mode () 
     
    364366                (expand-abbrev))))))) 
    365367 
     368;;; Abbrev properties. 
     369 
     370(defun abbrev-table-get (table prop) 
     371  "Get the PROP property of abbrev table TABLE." 
     372  (let ((sym (intern-soft "" table))) 
     373    (if sym (get sym prop)))) 
     374 
     375(defun abbrev-table-put (table prop val) 
     376  "Set the PROP property of abbrev table TABLE to VAL." 
     377  (let ((sym (intern "" table))) 
     378    (set sym nil)            ; Make sure it won't be confused for an abbrev. 
     379    (put sym prop val))) 
     380 
     381(defalias 'abbrev-get 'get 
     382  "Get the property PROP of abbrev ABBREV 
     383 
     384\(fn ABBREV PROP)") 
     385 
     386(defalias 'abbrev-put 'put 
     387  "Set the property PROP of abbrev ABREV to value VAL. 
     388See `define-abbrev' for the effect of some special properties. 
     389 
     390\(fn ABBREV PROP VAL)") 
     391 
     392(defmacro abbrev-with-wrapper-hook (var &rest body) 
     393  "Run BODY wrapped with the VAR hook. 
     394VAR is a special hook: its functions are called with one argument which 
     395is the \"original\" code (the BODY), so the hook function can wrap the 
     396original function, can call it several times, or even not call it at all. 
     397VAR is normally a symbol (a variable) in which case it is treated like a hook, 
     398with a buffer-local and a global part.  But it can also be an arbitrary expression. 
     399This is similar to an `around' advice." 
     400  (declare (indent 1) (debug t)) 
     401  ;; We need those two gensyms because CL's lexical scoping is not available 
     402  ;; for function arguments :-( 
     403  (let ((funs (make-symbol "funs")) 
     404        (global (make-symbol "global"))) 
     405    ;; Since the hook is a wrapper, the loop has to be done via 
     406    ;; recursion: a given hook function will call its parameter in order to 
     407    ;; continue looping. 
     408    `(labels ((runrestofhook (,funs ,global) 
     409                 ;; `funs' holds the functions left on the hook and `global' 
     410                 ;; holds the functions left on the global part of the hook 
     411                 ;; (in case the hook is local). 
     412                 (lexical-let ((funs ,funs) 
     413                               (global ,global)) 
     414                   (if (consp funs) 
     415                       (if (eq t (car funs)) 
     416                           (runrestofhook (append global (cdr funs)) nil) 
     417                         (funcall (car funs) 
     418                                  (lambda () (runrestofhook (cdr funs) global)))) 
     419                     ;; Once there are no more functions on the hook, run 
     420                     ;; the original body. 
     421                     ,@body)))) 
     422       (runrestofhook ,var 
     423                      ;; The global part of the hook, if any. 
     424                      ,(if (symbolp var) 
     425                           `(if (local-variable-p ',var) 
     426                                (default-value ',var))))))) 
     427 
     428 
     429;;; Code that used to be implemented in src/abbrev.c 
     430 
     431(defvar abbrev-table-name-list '(fundamental-mode-abbrev-table 
     432                                 global-abbrev-table) 
     433  "List of symbols whose values are abbrev tables.") 
     434 
     435(defun make-abbrev-table (&optional props) 
     436  "Create a new, empty abbrev table object. 
     437PROPS is a " 
     438  ;; The value 59 is an arbitrary prime number. 
     439  (let ((table (make-vector 59 0))) 
     440    ;; Each abbrev-table has a `modiff' counter which can be used to detect 
     441    ;; when an abbreviation was added.  An example of use would be to 
     442    ;; construct :regexp dynamically as the union of all abbrev names, so 
     443    ;; `modiff' can let us detect that an abbrev was added and hence :regexp 
     444    ;; needs to be refreshed. 
     445    ;; The presence of `modiff' entry is also used as a tag indicating this 
     446    ;; vector is really an abbrev-table. 
     447    (abbrev-table-put table :abbrev-table-modiff 0) 
     448    (while (consp props) 
     449      (abbrev-table-put table (pop props) (pop props))) 
     450    table)) 
     451 
     452(defun abbrev-table-p (object) 
     453  (and (vectorp object) 
     454       (numberp (abbrev-table-get object :abbrev-table-modiff)))) 
     455 
     456(defvar global-abbrev-table (make-abbrev-table) 
     457  "The abbrev table whose abbrevs affect all buffers. 
     458Each buffer may also have a local abbrev table. 
     459If it does, the local table overrides the global one 
     460for any particular abbrev defined in both.") 
     461 
     462(defvar abbrev-minor-mode-table-alist nil 
     463  "Alist of abbrev tables to use for minor modes. 
     464Each element looks like (VARIABLE . ABBREV-TABLE); 
     465ABBREV-TABLE is active whenever VARIABLE's value is non-nil.") 
     466 
     467(defvar fundamental-mode-abbrev-table 
     468  (let ((table (make-abbrev-table))) 
     469    ;; Set local-abbrev-table's default to be fundamental-mode-abbrev-table. 
     470    (setq-default local-abbrev-table table) 
     471    table) 
     472  "The abbrev table of mode-specific abbrevs for Fundamental Mode.") 
     473 
     474(defvar abbrevs-changed nil 
     475  "Set non-nil by defining or altering any word abbrevs. 
     476This causes `save-some-buffers' to offer to save the abbrevs.") 
     477 
     478(defcustom abbrev-all-caps nil 
     479  "Non-nil means expand multi-word abbrevs all caps if abbrev was so." 
     480  :type 'boolean 
     481  :group 'abbrev-mode) 
     482 
     483(defvar abbrev-start-location nil 
     484  "Buffer position for `expand-abbrev' to use as the start of the abbrev. 
     485When nil, use the word before point as the abbrev. 
     486Calling `expand-abbrev' sets this to nil.") 
     487 
     488(defvar abbrev-start-location-buffer nil 
     489  "Buffer that `abbrev-start-location' has been set for. 
     490Trying to expand an abbrev in any other buffer clears `abbrev-start-location'.") 
     491 
     492(defvar last-abbrev nil 
     493  "The abbrev-symbol of the last abbrev expanded.  See `abbrev-symbol'.") 
     494 
     495(defvar last-abbrev-text nil 
     496  "The exact text of the last abbrev expanded. 
     497nil if the abbrev has already been unexpanded.") 
     498 
     499(defvar last-abbrev-location 0 
     500  "The location of the start of the last abbrev expanded.") 
     501 
     502;; (defvar local-abbrev-table fundamental-mode-abbrev-table 
     503;;   "Local (mode-specific) abbrev table of current buffer.") 
     504;; (make-variable-buffer-local 'local-abbrev-table) 
     505 
     506(defcustom pre-abbrev-expand-hook nil 
     507  "Function or functions to be called before abbrev expansion is done. 
     508This is the first thing that `expand-abbrev' does, and so this may change 
     509the current abbrev table before abbrev lookup happens." 
     510  :type 'hook 
     511  :group 'abbrev-mode) 
     512(make-obsolete-variable 'pre-abbrev-expand-hook 'abbrev-expand-functions "23.1") 
     513 
     514(defun clear-abbrev-table (table) 
     515  "Undefine all abbrevs in abbrev table TABLE, leaving it empty." 
     516  (setq abbrevs-changed t) 
     517  (let* ((sym (intern-soft "" table))) 
     518    (dotimes (i (length table)) 
     519      (aset table i 0)) 
     520    ;; Preserve the table's properties. 
     521    (assert sym) 
     522    (let ((newsym (intern "" table))) 
     523      (set newsym nil)       ; Make sure it won't be confused for an abbrev. 
     524      (setplist newsym (symbol-plist sym))) 
     525    (abbrev-table-put table :abbrev-table-modiff 
     526                      (1+ (abbrev-table-get table :abbrev-table-modiff))))) 
     527 
     528(defun define-abbrev (table name expansion &optional hook &rest props) 
     529  "Define an abbrev in TABLE named NAME, to expand to EXPANSION and call HOOK. 
     530NAME must be a string, and should be lower-case. 
     531EXPANSION should usually be a string. 
     532To undefine an abbrev, define it with EXPANSION = nil. 
     533If HOOK is non-nil, it should be a function of no arguments; 
     534it is called after EXPANSION is inserted. 
     535If EXPANSION is not a string, the abbrev is a special one, 
     536 which does not expand in the usual way but only runs HOOK. 
     537 
     538PROPS is a property list.  The following properties are special: 
     539- `:count': the value for the abbrev's usage-count, which is incremented each time 
     540  the abbrev is used (the default is zero). 
     541- `:system': if non-nil, says that this is a \"system\" abbreviation 
     542  which should not be saved in the user's abbreviation file. 
     543  Unless `:system' is `force', a system abbreviation will not 
     544  overwrite a non-system abbreviation of the same name. 
     545- `:case-fixed': non-nil means that abbreviations are looked up without 
     546  case-folding, and the expansion is not capitalized/upcased. 
     547- `:enable-function': a function of no argument which returns non-nil iff the 
     548  abbrev should be used for a particular call of `expand-abbrev'. 
     549 
     550An obsolete but still supported calling form is: 
     551 
     552\(define-abbrev TABLE NAME EXPANSION &optional HOOK COUNT SYSTEM)." 
     553  (when (and (consp props) (or (null (car props)) (numberp (car props)))) 
     554    ;; Old-style calling convention. 
     555    (setq props (list* :count (car props) 
     556                       (if (cadr props) (list :system (cadr props)))))) 
     557  (unless (plist-get props :count) 
     558    (setq props (plist-put props :count 0))) 
     559  (let ((system-flag (plist-get props :system)) 
     560        (sym (intern name table))) 
     561    ;; Don't override a prior user-defined abbrev with a system abbrev, 
     562    ;; unless system-flag is `force'. 
     563    (unless (and (not (memq system-flag '(nil force))) 
     564                 (boundp sym) (symbol-value sym) 
     565                 (not (abbrev-get sym :system))) 
     566      (unless (or system-flag 
     567                  (and (boundp sym) (fboundp sym) 
     568                       ;; load-file-name 
     569                       (equal (symbol-value sym) expansion) 
     570                       (equal (symbol-function sym) hook))) 
     571        (setq abbrevs-changed t)) 
     572      (set sym expansion) 
     573      (fset sym hook) 
     574      (setplist sym 
     575                ;; Don't store the `force' value of `system-flag' into 
     576                ;; the :system property. 
     577                (if (eq 'force system-flag) (plist-put props :system t) props)) 
     578      (abbrev-table-put table :abbrev-table-modiff 
     579                        (1+ (abbrev-table-get table :abbrev-table-modiff)))) 
     580    name)) 
     581 
     582(defun abbrev--check-chars (abbrev global) 
     583  "Check if the characters in ABBREV have word syntax in either the 
     584current (if global is nil) or standard syntax table." 
     585  (with-syntax-table 
     586      (cond ((null global) (standard-syntax-table)) 
     587            ;; ((syntax-table-p global) global) 
     588            (t (syntax-table))) 
     589    (when (string-match "\\W" abbrev) 
     590      (let ((badchars ()) 
     591            (pos 0)) 
     592        (while (string-match "\\W" abbrev pos) 
     593          (pushnew (aref abbrev (match-beginning 0)) badchars) 
     594          (setq pos (1+ pos))) 
     595        (error "Some abbrev characters (%s) are not word constituents %s" 
     596               (apply 'string (nreverse badchars)) 
     597               (if global "in the standard syntax" "in this mode")))))) 
     598 
     599(defun define-global-abbrev (abbrev expansion) 
     600  "Define ABBREV as a global abbreviation for EXPANSION. 
     601The characters in ABBREV must all be word constituents in the standard 
     602syntax table." 
     603  (interactive "sDefine global abbrev: \nsExpansion for %s: ") 
     604  (abbrev--check-chars abbrev 'global) 
     605  (define-abbrev global-abbrev-table (downcase abbrev) expansion)) 
     606 
     607(defun define-mode-abbrev (abbrev expansion) 
     608  "Define ABBREV as a mode-specific abbreviation for EXPANSION. 
     609The characters in ABBREV must all be word-constituents in the current mode." 
     610  (interactive "sDefine mode abbrev: \nsExpansion for %s: ") 
     611  (unless local-abbrev-table 
     612    (error "Major mode has no abbrev table")) 
     613  (abbrev--check-chars abbrev nil) 
     614  (define-abbrev local-abbrev-table (downcase abbrev) expansion)) 
     615 
     616(defun abbrev--active-tables (&optional tables) 
     617  "Return the list of abbrev tables currently active. 
     618TABLES if non-nil overrides the usual rules.  It can hold 
     619either a single abbrev table or a list of abbrev tables." 
     620  ;; We could just remove the `tables' arg and let callers use 
     621  ;; (or table (abbrev--active-tables)) but then they'd have to be careful 
     622  ;; to treat the distinction between a single table and a list of tables. 
     623  (cond 
     624   ((consp tables) tables) 
     625   ((vectorp tables) (list tables)) 
     626   (t 
     627    (let ((tables (if (listp local-abbrev-table) 
     628                      (append local-abbrev-table 
     629                              (list global-abbrev-table)) 
     630                    (list local-abbrev-table global-abbrev-table)))) 
     631      ;; Add the minor-mode abbrev tables. 
     632      (dolist (x abbrev-minor-mode-table-alist) 
     633        (when (and (symbolp (car x)) (boundp (car x)) (symbol-value (car x))) 
     634          (setq tables 
     635                (if (listp (cdr x)) 
     636                    (append (cdr x) tables) (cons (cdr x) tables))))) 
     637      tables)))) 
     638 
     639 
     640(defun abbrev-symbol (abbrev &optional table) 
     641  "Return the symbol representing abbrev named ABBREV. 
     642This symbol's name is ABBREV, but it is not the canonical symbol of that name; 
     643it is interned in an abbrev-table rather than the normal obarray. 
     644The value is nil if that abbrev is not defined. 
     645Optional second arg TABLE is abbrev table to look it up in. 
     646The default is to try buffer's mode-specific abbrev table, then global table." 
     647  (let ((tables (abbrev--active-tables table)) 
     648        sym) 
     649    (while (and tables (not (symbol-value sym))) 
     650      (let* ((table (pop tables)) 
     651             (case-fold (not (abbrev-table-get table :case-fixed)))) 
     652        (setq tables (append (abbrev-table-get table :parents) tables)) 
     653        ;; In case the table doesn't set :case-fixed but some of the 
     654        ;; abbrevs do, we have to be careful. 
     655        (setq sym 
     656              ;; First try without case-folding. 
     657              (or (intern-soft abbrev table) 
     658                  (when case-fold 
     659                    ;; We didn't find any abbrev, try case-folding. 
     660                    (let ((sym (intern-soft (downcase abbrev) table))) 
     661                      ;; Only use it if it doesn't require :case-fixed. 
     662                      (and sym (not (abbrev-get sym :case-fixed)) 
     663                           sym))))))) 
     664    (if (symbol-value sym) 
     665        sym))) 
     666 
     667 
     668(defun abbrev-expansion (abbrev &optional table) 
     669  "Return the string that ABBREV expands into in the current buffer. 
     670Optionally specify an abbrev table as second arg; 
     671then ABBREV is looked up in that table only." 
     672  (symbol-value (abbrev-symbol abbrev table))) 
     673 
     674 
     675(defun abbrev--before-point () 
     676  "Try and find an abbrev before point.  Return it if found, nil otherwise." 
     677  (unless (eq abbrev-start-location-buffer (current-buffer)) 
     678    (setq abbrev-start-location nil)) 
     679 
     680  (let ((tables (abbrev--active-tables)) 
     681        (pos (point)) 
     682        start end name res) 
     683 
     684    (if abbrev-start-location 
     685        (progn 
     686          (setq start abbrev-start-location) 
     687          (setq abbrev-start-location nil) 
     688          ;; Remove the hyphen inserted by `abbrev-prefix-mark'. 
     689          (if (and (< start (point-max)) 
     690                   (eq (char-after start) ?-)) 
     691              (delete-region start (1+ start))) 
     692          (skip-syntax-backward " ") 
     693          (setq end (point)) 
     694          (when (> end start) 
     695            (setq name (buffer-substring start end)) 
     696            (goto-char pos)               ; Restore point. 
     697            (list (abbrev-symbol name tables) name start end))) 
     698 
     699      (while (and tables (not (car res))) 
     700        (let* ((table (pop tables)) 
     701               (enable-fun (abbrev-table-get table :enable-function))) 
     702          (setq tables (append (abbrev-table-get table :parents) tables)) 
     703          (setq res 
     704                (and (or (not enable-fun) (funcall enable-fun)) 
     705                     (looking-back (or (abbrev-table-get table :regexp) 
     706                                       "\\<\\(\\w+\\)\\W*") 
     707                                   (line-beginning-position)) 
     708                     (setq start (match-beginning 1)) 
     709                     (setq end   (match-end 1)) 
     710                     (setq name  (buffer-substring start end)) 
     711                     (let ((abbrev (abbrev-symbol name table))) 
     712                       (when abbrev 
     713                         (setq enable-fun (abbrev-get abbrev :enable-function)) 
     714                         (and (or (not enable-fun) (funcall enable-fun)) 
     715                              ;; This will also look it up in parent tables. 
     716                              ;; This is not on purpose, but it seems harmless. 
     717                              (list abbrev name start end)))))) 
     718          ;; Restore point. 
     719          (goto-char pos))) 
     720      res))) 
     721 
     722(defvar abbrev-expand-functions nil 
     723  "Wrapper hook around `expand-abbrev'. 
     724The functions on this special hook are called with one argument: 
     725a function that performs the abbrev expansion.  It should return 
     726the abbrev symbol if expansion took place.") 
     727 
     728(defun expand-abbrev () 
     729  "Expand the abbrev before point, if there is an abbrev there. 
     730Effective when explicitly called even when `abbrev-mode' is nil. 
     731Returns the abbrev symbol, if expansion took place." 
     732  (interactive) 
     733  (run-hooks 'pre-abbrev-expand-hook) 
     734  (abbrev-with-wrapper-hook abbrev-expand-functions 
     735    (destructuring-bind (&optional sym name wordstart wordend) 
     736        (abbrev--before-point) 
     737      (when sym 
     738        (let ((value sym)) 
     739          (unless (or ;; executing-kbd-macro 
     740                   noninteractive 
     741                   (window-minibuffer-p (selected-window))) 
     742            ;; Add an undo boundary, in case we are doing this for 
     743            ;; a self-inserting command which has avoided making one so far. 
     744            (undo-boundary)) 
     745          ;; Now sym is the abbrev symbol. 
     746          (setq last-abbrev-text name) 
     747          (setq last-abbrev sym) 
     748          (setq last-abbrev-location wordstart) 
     749          ;; Increment use count. 
     750          (abbrev-put sym :count (1+ (abbrev-get sym :count))) 
     751          ;; If this abbrev has an expansion, delete the abbrev 
     752          ;; and insert the expansion. 
     753          (when (stringp (symbol-value sym)) 
     754            (goto-char wordstart) 
     755            ;; Insert at beginning so that markers at the end (e.g. point) 
     756            ;; are preserved. 
     757            (insert (symbol-value sym)) 
     758            (delete-char (- wordend wordstart)) 
     759            (let ((case-fold-search nil)) 
     760              ;; If the abbrev's name is different from the buffer text (the 
     761              ;; only difference should be capitalization), then we may want 
     762              ;; to adjust the capitalization of the expansion. 
     763              (when (and (not (equal name (symbol-name sym))) 
     764                         (string-match "[[:upper:]]" name)) 
     765                (if (not (string-match "[[:lower:]]" name)) 
     766                    ;; Abbrev was all caps.  If expansion is multiple words, 
     767                    ;; normally capitalize each word. 
     768                    (if (and (not abbrev-all-caps) 
     769                             (save-excursion 
     770                               (> (progn (backward-word 1) (point)) 
     771                                  (progn (goto-char wordstart) 
     772                                         (forward-word 1) (point))))) 
     773                        (upcase-initials-region wordstart (point)) 
     774                      (upcase-region wordstart (point))) 
     775                  ;; Abbrev included some caps.  Cap first initial of expansion. 
     776                  (let ((end (point))) 
     777                    ;; Find the initial. 
     778                    (goto-char wordstart) 
     779                    (skip-syntax-forward "^w" (1- end)) 
     780                    ;; Change just that. 
     781                    (upcase-initials-region (point) (1+ (point))) 
     782                    (goto-char end)))))) 
     783          ;; Now point is at the end of the expansion and the beginning is 
     784          ;; in last-abbrev-location. 
     785          (when (symbol-function sym) 
     786            (let* ((hook (symbol-function sym)) 
     787                   (expanded 
     788                    ;; If the abbrev has a hook function, run it. 
     789                    (funcall hook))) 
     790              ;; In addition, if the hook function is a symbol with 
     791              ;; a non-nil `no-self-insert' property, let the value it 
     792              ;; returned specify whether we consider that an expansion took 
     793              ;; place.  If it returns nil, no expansion has been done. 
     794              (if (and (symbolp hook) 
     795                       (null expanded) 
     796                       (get hook 'no-self-insert)) 
     797                  (setq value nil)))) 
     798          value))))) 
     799 
     800(defun unexpand-abbrev () 
     801  "Undo the expansion of the last abbrev that expanded. 
     802This differs from ordinary undo in that other editing done since then 
     803is not undone." 
     804  (interactive) 
     805  (save-excursion 
     806    (unless (or (< last-abbrev-location (point-min)) 
     807                (> last-abbrev-location (point-max))) 
     808      (goto-char last-abbrev-location) 
     809      (when (stringp last-abbrev-text) 
     810        ;; This isn't correct if last-abbrev's hook was used 
     811        ;; to do the expansion. 
     812        (let ((val (symbol-value last-abbrev))) 
     813          (unless (stringp val) 
     814            (error "value of abbrev-symbol must be a string")) 
     815          (delete-region (point) (+ (point) (length val))) 
     816          ;; Don't inherit properties here; just copy from old contents. 
     817          (insert last-abbrev-text) 
     818          (setq last-abbrev-text nil)))))) 
     819 
     820(defun abbrev--write (sym) 
     821  "Write the abbrev in a `read'able form. 
     822Only writes the non-system abbrevs. 
     823Presumes that `standard-output' points to `current-buffer'." 
     824  (unless (or (null (symbol-value sym)) (abbrev-get sym :system)) 
     825    (insert "    (") 
     826    (prin1 (symbol-name sym)) 
     827    (insert " ") 
     828    (prin1 (symbol-value sym)) 
     829    (insert " ") 
     830    (prin1 (symbol-function sym)) 
     831    (insert " ") 
     832    (prin1 (abbrev-get sym :count)) 
     833    (insert ")\n"))) 
     834 
     835(defun abbrev--describe (sym) 
     836  (when (symbol-value sym) 
     837    (prin1 (symbol-name sym)) 
     838    (if (null (abbrev-get sym :system)) 
     839        (indent-to 15 1) 
     840      (insert " (sys)") 
     841      (indent-to 20 1)) 
     842    (prin1 (abbrev-get sym :count)) 
     843    (indent-to 20 1) 
     844    (prin1 (symbol-value sym)) 
     845    (when (symbol-function sym) 
     846      (indent-to 45 1) 
     847      (prin1 (symbol-function sym))) 
     848    (terpri))) 
     849 
     850(defun insert-abbrev-table-description (name &optional readable) 
     851  "Insert before point a full description of abbrev table named NAME. 
     852NAME is a symbol whose value is an abbrev table. 
     853If optional 2nd arg READABLE is non-nil, a human-readable description 
     854is inserted.  Otherwise the description is an expression, 
     855a call to `define-abbrev-table', which would 
     856define the abbrev table NAME exactly as it is currently defined. 
     857 
     858Abbrevs marked as \"system abbrevs\" are omitted." 
     859  (let ((table (symbol-value name)) 
     860        (symbols ())) 
     861    (mapatoms (lambda (sym) (if (symbol-value sym) (push sym symbols))) table) 
     862    (setq symbols (sort symbols 'string-lessp)) 
     863    (let ((standard-output (current-buffer))) 
     864      (if readable 
     865          (progn 
     866            (insert "(") 
     867            (prin1 name) 
     868            (insert ")\n\n") 
     869            (mapc 'abbrev--describe symbols) 
     870            (insert "\n\n")) 
     871        (insert "(define-abbrev-table '") 
     872        (prin1 name) 
     873        (insert " '(") 
     874        (mapc 'abbrev--write symbols) 
     875        (insert "    ))\n\n")) 
     876      nil))) 
     877 
     878(defun define-abbrev-table (tablename definitions 
     879                                      &optional docstring &rest props) 
     880  "Define TABLENAME (a symbol) as an abbrev table name. 
     881Define abbrevs in it according to DEFINITIONS, which is a list of elements 
     882of the form (ABBREVNAME EXPANSION HOOK USECOUNT SYSTEMFLAG). 
     883\(If the list is shorter than that, omitted elements default to nil). 
     884PROPS is a property list to apply to the table. 
     885Properties with special meaning: 
     886- `:parents' contains a list of abbrev tables from which this table inherits 
     887  abbreviations. 
     888- `:case-fixed' non-nil means that abbreviations are looked up without 
     889  case-folding, and the expansion is not capitalized/upcased. 
     890- `:regexp' describes the form of abbrevs.  It defaults to \\=\\<\\(\\w+\\)\\W* which 
     891  means that an abbrev can only be a single word.  The submatch 1 is treated 
     892  as the potential name of an abbrev. 
     893- `:enable-function' can be set to a function of no argument which returns 
     894  non-nil iff the abbrevs in this table should be used for this instance 
     895  of `expand-abbrev'." 
     896  ;; We used to manually add the docstring, but we also want to record this 
     897  ;; location as the definition of the variable (in load-history), so we may 
     898  ;; as well just use `defvar'. 
     899  (eval `(defvar ,tablename nil ,@(if (stringp docstring) (list docstring)))) 
     900  (let ((table (if (boundp tablename) (symbol-value tablename)))) 
     901    (unless table 
     902      (setq table (make-abbrev-table props)) 
     903      (set tablename table) 
     904      (push tablename abbrev-table-name-list)) 
     905    (dolist (elt definitions) 
     906      (apply 'define-abbrev table elt)))) 
     907 
    366908(provide 'abbrev) 
    367909 
  • branches/4.00-dev/lisp/emacs-lisp/lisp-mode.el

    r4220 r4228  
    3737 
    3838(defvar lisp-mode-abbrev-table nil) 
     39 
     40(define-abbrev-table 'lisp-mode-abbrev-table ()) 
    3941 
    4042(defvar emacs-lisp-mode-syntax-table 
     
    5759        (setq i (1+ i))) 
    5860      (modify-syntax-entry ?\s "    " table) 
     61      ;; Non-break space acts as whitespace. 
     62      (modify-syntax-entry ?\x8a0 "    " table) 
    5963      (modify-syntax-entry ?\t "    " table) 
    6064      (modify-syntax-entry ?\f "    " table) 
     
    8690    (modify-syntax-entry ?| "\" 23bn" table) 
    8791    table)) 
    88  
    89 (define-abbrev-table 'lisp-mode-abbrev-table ()) 
    9092 
    9193(defvar lisp-imenu-generic-expression 
     
    260262(defvar lisp-mode-shared-map 
    261263  (let ((map (make-sparse-keymap))) 
    262     (define-key map "\t" 'lisp-indent-line) 
    263264    (define-key map "\e\C-q" 'indent-sexp) 
    264265    (define-key map "\177" 'backward-delete-char-untabify) 
     
    270271  "Keymap for commands shared by all sorts of Lisp modes.") 
    271272 
    272 (defvar emacs-lisp-mode-map () 
     273(defvar emacs-lisp-mode-map  
     274  (let ((map (make-sparse-keymap "Emacs-Lisp")) 
     275        (menu-map (make-sparse-keymap "Emacs-Lisp")) 
     276        (prof-map (make-sparse-keymap)) 
     277        (tracing-map (make-sparse-keymap))) 
     278    (set-keymap-parent map lisp-mode-shared-map) 
     279    (define-key map "\e\t" 'lisp-complete-symbol) 
     280    (define-key map "\e\C-x" 'eval-defun) 
     281    (define-key map "\e\C-q" 'indent-pp-sexp) 
     282    (define-key map [menu-bar emacs-lisp] (cons "Emacs-Lisp" menu-map)) 
     283    (define-key menu-map [eldoc] 
     284      '(menu-item "Auto-Display Documentation Strings" eldoc-mode 
     285                  :button (:toggle . (bound-and-true-p eldoc-mode)) 
     286                  :help "Display the documentation string for the item under cursor")) 
     287    (define-key menu-map [checkdoc] 
     288      '(menu-item "Check Documentation Strings" checkdoc 
     289                  :help "Check documentation strings for style requirements")) 
     290    (define-key menu-map [re-builder] 
     291      '(menu-item "Construct Regexp" re-builder 
     292                  :help "Construct a regexp interactively")) 
     293    (define-key menu-map [tracing] (cons "Tracing" tracing-map)) 
     294    (define-key tracing-map [tr-a] 
     295      '(menu-item "Untrace all" untrace-all 
     296                  :help "Untraces all currently traced functions")) 
     297    (define-key tracing-map [tr-uf] 
     298      '(menu-item "Untrace function..." untrace-function 
     299                  :help "Untraces FUNCTION and possibly activates all remaining advice")) 
     300    (define-key tracing-map [tr-sep] '("--")) 
     301    (define-key tracing-map [tr-q] 
     302      '(menu-item "Trace function quietly..." trace-function 
     303                  :help "Trace the function with trace output going quietly to a buffer")) 
     304    (define-key tracing-map [tr-f] 
     305      '(menu-item "Trace function..." trace-function 
     306                  :help "Trace the function given as a argument")) 
     307    (define-key menu-map [profiling] (cons "Profiling" prof-map)) 
     308    (define-key prof-map [prof-restall] 
     309      '(menu-item "Remove Instrumentation for All Functions" elp-restore-all 
     310                  :help "Restore the original definitions of all functions being profiled")) 
     311    (define-key prof-map [prof-restfunc] 
     312      '(menu-item "Remove Instrumentation for Function..." elp-restore-function 
     313                  :help "Restore an instrumented function to its original definition")) 
     314 
     315    (define-key prof-map [sep-rem] '("--")) 
     316    (define-key prof-map [prof-resall] 
     317      '(menu-item "Reset Counters for All Functions" elp-reset-all 
     318                  :help "Reset the profiling information for all functions being profiled")) 
     319    (define-key prof-map [prof-resfunc] 
     320      '(menu-item "Reset Counters for Function..." elp-reset-function 
     321                  :help "Reset the profiling information for a function")) 
     322    (define-key prof-map [prof-res] 
     323      '(menu-item "Show Profiling Results" elp-results 
     324                  :help "Display current profiling results")) 
     325    (define-key prof-map [prof-pack] 
     326      '(menu-item "Instrument Package..." elp-instrument-package 
     327                  :help "Instrument for profiling all function that start with a prefix")) 
     328    (define-key prof-map [prof-func] 
     329      '(menu-item "Instrument Function..." elp-instrument-function 
     330                  :help "Instrument a function for profiling")) 
     331    (define-key menu-map [edebug-defun] 
     332      '(menu-item "Instrument Function for Debugging" edebug-defun 
     333                  :help "Evaluate the top level form point is in, stepping through with Edebug" 
     334                  :keys "C-u C-M-x")) 
     335    (define-key menu-map [separator-byte] '("--")) 
     336    (define-key menu-map [disas] 
     337      '(menu-item "Disassemble byte compiled object..." disassemble 
     338                  :help "Print disassembled code for OBJECT in a buffer")) 
     339    (define-key menu-map [byte-recompile] 
     340      '(menu-item "Byte-recompile Directory..." byte-recompile-directory 
     341                  :help "Recompile every `.el' file in DIRECTORY that needs recompilation")) 
     342    (define-key menu-map [emacs-byte-compile-and-load] 
     343      '(menu-item "Byte-compile And Load" emacs-lisp-byte-compile-and-load 
     344                  :help "Byte-compile the current file (if it has changed), then load compiled code")) 
     345    (define-key menu-map [byte-compile] 
     346      '(menu-item "Byte-compile This File" emacs-lisp-byte-compile 
     347                  :help "Byte compile the file containing the current buffer")) 
     348    (define-key menu-map [separator-eval] '("--")) 
     349    (define-key menu-map [ielm] 
     350      '(menu-item "Interactive Expression Evaluation" ielm 
     351                  :help "Interactively evaluate Emacs Lisp expressions")) 
     352    (define-key menu-map [eval-buffer] 
     353      '(menu-item "Evaluate Buffer" eval-buffer 
     354                  :help "Execute the current buffer as Lisp code")) 
     355    (define-key menu-map [eval-region] 
     356      '(menu-item "Evaluate Region" eval-region 
     357                  :help "Execute the region as Lisp code" 
     358                  :enable mark-active)) 
     359    (define-key menu-map [eval-sexp]  
     360      '(menu-item "Evaluate Last S-expression" eval-last-sexp 
     361                  :help "Evaluate sexp before point; print value in minibuffer")) 
     362    (define-key menu-map [separator-format] '("--")) 
     363    (define-key menu-map [comment-region] 
     364      '(menu-item "Comment Out Region" comment-region 
     365                  :help "Comment or uncomment each line in the region" 
     366                  :enable mark-active)) 
     367    (define-key menu-map [indent-region] 
     368      '(menu-item "Indent Region" indent-region 
     369                  :help "Indent each nonblank line in the region" 
     370                  :enable mark-active)) 
     371    (define-key menu-map [indent-line] '("Indent Line" . lisp-indent-line)) 
     372    map) 
    273373  "Keymap for Emacs Lisp mode. 
    274374All commands in `lisp-mode-shared-map' are inherited by this map.") 
    275  
    276 (if emacs-lisp-mode-map 
    277     () 
    278   (let ((map (make-sparse-keymap "Emacs-Lisp"))) 
    279     (setq emacs-lisp-mode-map (make-sparse-keymap)) 
    280     (set-keymap-parent emacs-lisp-mode-map lisp-mode-shared-map) 
    281     (define-key emacs-lisp-mode-map "\e\t" 'lisp-complete-symbol) 
    282     (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun) 
    283     (define-key emacs-lisp-mode-map "\e\C-q" 'indent-pp-sexp) 
    284     (define-key emacs-lisp-mode-map [menu-bar] (make-sparse-keymap)) 
    285     (define-key emacs-lisp-mode-map [menu-bar emacs-lisp] 
    286       (cons "Emacs-Lisp" map)) 
    287     (define-key map [edebug-defun] 
    288       '("Instrument Function for Debugging" . edebug-defun)) 
    289     (define-key map [byte-recompile] 
    290       '("Byte-recompile Directory..." . byte-recompile-directory)) 
    291     (define-key map [emacs-byte-compile-and-load] 
    292       '("Byte-compile And Load" . emacs-lisp-byte-compile-and-load)) 
    293     (define-key map [byte-compile] 
    294       '("Byte-compile This File" . emacs-lisp-byte-compile)) 
    295     (define-key map [separator-eval] '("--")) 
    296     (define-key map [eval-buffer] '("Evaluate Buffer" . eval-buffer)) 
    297     (define-key map [eval-region] '("Evaluate Region" . eval-region)) 
    298     (define-key map [eval-sexp] '("Evaluate Last S-expression" . eval-last-sexp)) 
    299     (define-key map [separator-format] '("--")) 
    300     (define-key map [comment-region] '("Comment Out Region" . comment-region)) 
    301     (define-key map [indent-region] '("Indent Region" . indent-region)) 
    302     (define-key map [indent-line] '("Indent Line" . lisp-indent-line)) 
    303     (put 'eval-region 'menu-enable 'mark-active) 
    304     (put 'comment-region 'menu-enable 'mark-active) 
    305     (put 'indent-region 'menu-enable 'mark-active))) 
    306375 
    307376(defun emacs-lisp-byte-compile () 
     
    417486 
    418487(defvar lisp-interaction-mode-map 
    419   (let ((map (make-sparse-keymap))) 
     488  (let ((map (make-sparse-keymap)) 
     489        (menu-map (make-sparse-keymap "Lisp-Interaction"))) 
    420490    (set-keymap-parent map lisp-mode-shared-map) 
    421491    (define-key map "\e\C-x" 'eval-defun) 
     
    423493    (define-key map "\e\t" 'lisp-complete-symbol) 
    424494    (define-key map "\n" 'eval-print-last-sexp) 
     495    (define-key map [menu-bar lisp-interaction] (cons "Lisp-Interaction" menu-map)) 
     496    (define-key menu-map [eval-defun]  
     497      '(menu-item "Evaluate Defun" eval-defun 
     498                  :help "Evaluate the top-level form containing point, or after point")) 
     499    (define-key menu-map [eval-print-last-sexp] 
     500      '(menu-item "Evaluate and print" eval-print-last-sexp 
     501                  :help "Evaluate sexp before point; print value into current buffer")) 
     502    (define-key menu-map [edebug-defun-lisp-interaction] 
     503      '(menu-item "Instrument Function for Debugging" edebug-defun 
     504                  :help "Evaluate the top level form point is in, stepping through with Edebug" 
     505                  :keys "C-u C-M-x")) 
     506    (define-key menu-map [indent-pp-sexp] 
     507      '(menu-item "Indent or Pretty-Print" indent-pp-sexp 
     508                  :help "Indent each line of the list starting just after point, or prettyprint it")) 
     509    (define-key menu-map [lisp-complete-symbol] 
     510      '(menu-item "Complete Lisp Symbol" lisp-complete-symbol 
     511                  :help "Perform completion on Lisp symbol preceding point")) 
    425512    map) 
    426513  "Keymap for Lisp Interaction mode.