;;; mode-abbrev-propose.el --- initial content for mode-abbrevs ;; for all Emacsen ;; Author: Andreas Roehler;; ;; Keywords: abbrev ;; This file 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 file 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 GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; A slightly modified `add-mode-abbrev' providing a ;; proposal for new abbrevs. Proposal is composed from ;; the initial character(s) of the expansion. ;;; Code: (defun add-abbrev-propose (table type arg &optional dont-ask) (save-excursion (let ((exp (and (>= arg 0) (buffer-substring-no-properties (point) (if (= arg 0) (mark) (save-excursion (forward-word (- arg)) (when (and (eq (char-before) 40) (eq major-mode 'emacs-lisp-mode)) (forward-char -1)) (point)))))) proposal name) (when (and (featurep 'xemacs)(eq major-mode 'emacs-lisp-mode)) ;; (when (eq major-mode 'emacs-lisp-mode) (setq exp (concat "(" exp))) (save-excursion (while (< 0 arg) (forward-word -1) (setq proposal (concat (downcase (buffer-substring-no-properties (point) (1+ (point)))) proposal)) (setq arg (1- arg)))) (setq name ;; ask only when interactive (if dont-ask proposal (read-string (format (if exp "%s abbrev for \"%s\": " "Undefine %s abbrev: ") type exp) proposal))) (set-text-properties 0 (length name) nil name) (when (or (null exp) (not (abbrev-expansion name table)) (y-or-n-p (format "%s expands to \"%s\"; redefine? " name (abbrev-expansion name table)))) (define-abbrev table (downcase name) exp ;; (replace-regexp-in-string "\n" " " exp) ))))) (defun add-mode-abbrev-propose (arg) "Define mode-specific abbrev for last word(s) before point. Argument is how many words before point form the expansion; or zero means the region is the expansion. A negative argument means to undefine the specified abbrev. Reads the abbreviation in the minibuffer. Don't use this function in a Lisp program; use `define-abbrev' instead." (interactive "p") (save-excursion (add-abbrev-propose (if only-global-abbrevs global-abbrev-table (or local-abbrev-table (error "No per-mode abbrev table"))) "Mode" arg))) (provide 'mode-abbrev-propose) ;;; mode-abbrev-propose.el ends here