comparison lisp/abbrev.el @ 442:abe6d1db359e r21-2-36

Import from CVS: tag r21-2-36
author cvs
date Mon, 13 Aug 2007 11:35:02 +0200
parents 3ecd8885ac67
children 576fb035e263
comparison
equal deleted inserted replaced
441:72a7cfa4a488 442:abe6d1db359e
417 (insert-abbrev-table-description (car tables) nil) 417 (insert-abbrev-table-description (car tables) nil)
418 (setq tables (cdr tables)))) 418 (setq tables (cdr tables))))
419 (write-region 1 (point-max) file) 419 (write-region 1 (point-max) file)
420 (erase-buffer))) 420 (erase-buffer)))
421 421
422 (defun abbrev-string-to-be-defined (arg)
423 "Return the string for which an abbrev will be defined.
424 ARG is the argument to `add-global-abbrev' or `add-mode-abbrev'."
425 (if (and (not arg) (region-active-p)) (setq arg 0)
426 (setq arg (prefix-numeric-value arg)))
427 (and (>= arg 0)
428 (buffer-substring
429 (point)
430 (if (= arg 0) (mark)
431 (save-excursion (forward-word (- arg)) (point))))))
432
422 (defun add-mode-abbrev (arg) 433 (defun add-mode-abbrev (arg)
423 "Define mode-specific abbrev for last word(s) before point. 434 "Define mode-specific abbrev for last word(s) before point.
424 Argument is how many words before point form the expansion; 435 Argument is how many words before point form the expansion;
425 or zero means the region is the expansion. 436 or zero means the region is the expansion.
426 A negative argument means to undefine the specified abbrev. 437 A negative argument means to undefine the specified abbrev.
448 (interactive "P") 459 (interactive "P")
449 (add-abbrev global-abbrev-table "Global" arg)) 460 (add-abbrev global-abbrev-table "Global" arg))
450 461
451 (defun add-abbrev (table type arg) 462 (defun add-abbrev (table type arg)
452 ;; XEmacs change: 463 ;; XEmacs change:
453 (if (and (not arg) (region-active-p)) (setq arg 0) 464 (let ((exp (abbrev-string-to-be-defined arg))
454 (setq arg (prefix-numeric-value arg)))
455 (let ((exp (and (>= arg 0)
456 (buffer-substring
457 (point)
458 (if (= arg 0) (mark)
459 (save-excursion (forward-word (- arg)) (point))))))
460 name) 465 name)
461 (setq name 466 (setq name
462 (read-string (format (if exp "%s abbrev for \"%s\": " 467 (read-string (format (if exp "%s abbrev for \"%s\": "
463 "Undefine %s abbrev: ") 468 "Undefine %s abbrev: ")
464 type exp))) 469 type exp)))
466 (if (or (null exp) 471 (if (or (null exp)
467 (not (abbrev-expansion name table)) 472 (not (abbrev-expansion name table))
468 (y-or-n-p (format "%s expands to \"%s\"; redefine? " 473 (y-or-n-p (format "%s expands to \"%s\"; redefine? "
469 name (abbrev-expansion name table)))) 474 name (abbrev-expansion name table))))
470 (define-abbrev table (downcase name) exp)))) 475 (define-abbrev table (downcase name) exp))))
476
477 (defun inverse-abbrev-string-to-be-defined (arg)
478 "Return the string for which an inverse abbrev will be defined.
479 ARG is the argument to `inverse-add-global-abbrev' or
480 `inverse-add-mode-abbrev'."
481 (save-excursion
482 (forward-word (- arg))
483 (buffer-substring (point) (progn (forward-word 1) (point)))))
471 484
472 (defun inverse-add-mode-abbrev (arg) 485 (defun inverse-add-mode-abbrev (arg)
473 "Define last word before point as a mode-specific abbrev. 486 "Define last word before point as a mode-specific abbrev.
474 With prefix argument N, defines the Nth word before point. 487 With prefix argument N, defines the Nth word before point.
475 This command uses the minibuffer to read the expansion. 488 This command uses the minibuffer to read the expansion.