comparison lisp/abbrev.el @ 446:1ccc32a20af4 r21-2-38

Import from CVS: tag r21-2-38
author cvs
date Mon, 13 Aug 2007 11:37:21 +0200
parents 576fb035e263
children a634e3b7acc8
comparison
equal deleted inserted replaced
445:34f3776fcf0e 446:1ccc32a20af4
86 86
87 (defun define-abbrev (table name &optional expansion hook count) 87 (defun define-abbrev (table name &optional expansion hook count)
88 "Define an abbrev in TABLE named NAME, to expand to EXPANSION or call HOOK. 88 "Define an abbrev in TABLE named NAME, to expand to EXPANSION or call HOOK.
89 NAME and EXPANSION are strings. Hook is a function or `nil'. 89 NAME and EXPANSION are strings. Hook is a function or `nil'.
90 To undefine an abbrev, define it with an expansion of `nil'." 90 To undefine an abbrev, define it with an expansion of `nil'."
91 (unless (or (null expansion) (stringp expansion)) 91 (check-type expansion (or null string))
92 (setq expansion (wrong-type-argument 'stringp expansion))) 92 (check-type count (or null integer))
93 93 (check-type table vector)
94 (unless (or (null count) (integerp count))
95 (setq count (wrong-type-argument 'fixnump count)))
96
97 (unless (vectorp table)
98 (setq table (wrong-type-argument 'vectorp table)))
99
100 (let* ((sym (intern name table)) 94 (let* ((sym (intern name table))
101 (oexp (and (boundp sym) (symbol-value sym))) 95 (oexp (and (boundp sym) (symbol-value sym)))
102 (ohook (and (fboundp sym) (symbol-function sym)))) 96 (ohook (and (fboundp sym) (symbol-function sym))))
103 (unless (and (equal ohook hook) 97 (unless (and (equal ohook hook)
104 (stringp oexp) 98 (stringp oexp)
424 (setq arg (prefix-numeric-value arg))) 418 (setq arg (prefix-numeric-value arg)))
425 (and (>= arg 0) 419 (and (>= arg 0)
426 (buffer-substring 420 (buffer-substring
427 (point) 421 (point)
428 (if (= arg 0) (mark) 422 (if (= arg 0) (mark)
429 (save-excursion (forward-word (- arg)) (point)))))) 423 (save-excursion (backward-word arg) (point))))))
430 424
431 (defun add-mode-abbrev (arg) 425 (defun add-mode-abbrev (arg)
432 "Define mode-specific abbrev for last word(s) before point. 426 "Define mode-specific abbrev for last word(s) before point.
433 Argument is how many words before point form the expansion; 427 Argument is how many words before point form the expansion;
434 or zero means the region is the expansion. 428 or zero means the region is the expansion.
482 (defun inverse-abbrev-string-to-be-defined (arg) 476 (defun inverse-abbrev-string-to-be-defined (arg)
483 "Return the string for which an inverse abbrev will be defined. 477 "Return the string for which an inverse abbrev will be defined.
484 ARG is the argument to `inverse-add-global-abbrev' or 478 ARG is the argument to `inverse-add-global-abbrev' or
485 `inverse-add-mode-abbrev'." 479 `inverse-add-mode-abbrev'."
486 (save-excursion 480 (save-excursion
487 (forward-word (- arg)) 481 (backward-word arg)
488 (buffer-substring (point) (progn (forward-word 1) (point))))) 482 (buffer-substring (point) (progn (forward-word 1) (point)))))
489 483
490 (defun inverse-add-mode-abbrev (arg) 484 (defun inverse-add-mode-abbrev (arg)
491 "Define last word before point as a mode-specific abbrev. 485 "Define last word before point as a mode-specific abbrev.
492 With prefix argument N, defines the Nth word before point. 486 With prefix argument N, defines the Nth word before point.
509 (inverse-add-abbrev global-abbrev-table "Global" arg)) 503 (inverse-add-abbrev global-abbrev-table "Global" arg))
510 504
511 (defun inverse-add-abbrev (table type arg) 505 (defun inverse-add-abbrev (table type arg)
512 (let (name nameloc exp) 506 (let (name nameloc exp)
513 (save-excursion 507 (save-excursion
514 (forward-word (- arg)) 508 (backward-word arg)
515 (setq name (buffer-substring (point) (progn (forward-word 1) 509 (setq name (buffer-substring (point) (progn (forward-word 1)
516 (setq nameloc (point)))))) 510 (setq nameloc (point))))))
517 (set-text-properties 0 (length name) nil name) 511 (set-text-properties 0 (length name) nil name)
518 (setq exp (read-string (format "%s expansion for \"%s\": " 512 (setq exp (read-string (format "%s expansion for \"%s\": "
519 type name))) 513 type name)))
552 (progn (forward-word 1) 546 (progn (forward-word 1)
553 (<= (setq pnt (point)) (- (point-max) lim)))) 547 (<= (setq pnt (point)) (- (point-max) lim))))
554 (if (abbrev-expansion 548 (if (abbrev-expansion
555 (setq string 549 (setq string
556 (buffer-substring 550 (buffer-substring
557 (save-excursion (forward-word -1) (point)) 551 (save-excursion (backward-word) (point))
558 pnt))) 552 pnt)))
559 (if (or noquery (y-or-n-p (format "Expand `%s'? " string))) 553 (if (or noquery (y-or-n-p (format "Expand `%s'? " string)))
560 (expand-abbrev))))))) 554 (expand-abbrev)))))))
561 555
562 ;;; abbrev.el ends here 556 ;;; abbrev.el ends here