-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathar-abbrev-propose.el
95 lines (80 loc) · 3.64 KB
/
ar-abbrev-propose.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
;;; ar-abbrev-propose.el --- initial content for mode-abbrevs
;; Copyright (C) 2015-2016 Andreas Röhler
;; Author: Andreas Röhler <[email protected]>
;; 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 3, 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 ar-edit-abbrevs ()
"Jumps to `ar-mode-abbrev-table' in a buffer containing lists of abbrev definitions.
You can edit them and type \\<edit-abbrevs-map>\\[edit-abbrevs-redefine] to redefine abbrevs
according to your editing.
Buffer contains a header line for each abbrev table,
which is the abbrev table name in parentheses.
This is followed by one line per abbrev in that table:
NAME USECOUNT EXPANSION HOOK
where NAME and EXPANSION are strings with quotes,
USECOUNT is an integer, and HOOK is any valid function
or may be omitted (it is usually omitted). "
(interactive)
(save-excursion
(let ((mat (abbrev-table-name local-abbrev-table)))
(prepare-abbrev-list-buffer)
(set-buffer "*Abbrevs*")
(switch-to-buffer (current-buffer))
(goto-char (point-min))
(search-forward (concat "(" (format "%s" mat))))))
(defun ar--add-abbrev-propose (table type arg &optional dont-ask)
(save-excursion
(let ((orig (point))
proposal exp name)
(while (< 0 arg)
(ar-beginning-of-partial-expression)
(when (looking-at "[[:alpha:]]")
(setq proposal (concat (downcase (match-string-no-properties 0)) proposal)))
(setq arg (1- arg)))
(setq exp (buffer-substring-no-properties (point) orig))
(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)))))
(defun ar-add-abbrev (arg)
"Defines ar-mode specific abbrev for last expressions before point.
Argument is how many `ar-partial-expression's form the expansion; or zero means the region is the expansion.
Reads the abbreviation in the minibuffer; with numeric arg it displays a proposal for an abbrev.
Proposal is composed from the initial character(s) of the
expansion.
Don't use this function in a Lisp program; use `define-abbrev' instead."
(interactive "p")
(save-excursion
(ar--add-abbrev-propose
(if only-global-abbrevs
global-abbrev-table
(or local-abbrev-table
(error "No per-mode abbrev table")))
"Mode" arg)))
(provide 'ar-abbrev-propose)
;;; mode-abbrev-propose.el ends here