diff options
| author | Federico Tedin | 2019-05-14 09:16:00 -0300 |
|---|---|---|
| committer | Basil L. Contovounesios | 2019-05-21 15:23:23 +0100 |
| commit | eb2e9a2ca29f7d5e3b97709e9eca14fa5556ac63 (patch) | |
| tree | 1cf8ff22d7dae507eb4ea9bb8fcb2165e2375791 /lisp | |
| parent | 5856512911488e40609be5685e64f9fb8cd395ad (diff) | |
| download | emacs-eb2e9a2ca29f7d5e3b97709e9eca14fa5556ac63.tar.gz emacs-eb2e9a2ca29f7d5e3b97709e9eca14fa5556ac63.zip | |
Use lexical-binding in tempo.el and add tests
For discussion, see the following thread:
https://lists.gnu.org/archive/html/emacs-devel/2019-05/msg00395.html
* lisp/tempo.el: Use lexical-binding.
(tempo-define-template): Expand documentation to mention
`tempo-user-elements'.
(tempo-local-tags, tempo-collection, tempo-dirty-collection)
(tempo-marks, tempo-match-finder): Define with defvar-local.
(tempo-named-insertions, tempo-region-start, tempo-region-stop): Make
them automatically buffer-local.
* test/lisp/tempo-tests.el: Add tests for tempo.el.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/tempo.el | 41 |
1 files changed, 18 insertions, 23 deletions
diff --git a/lisp/tempo.el b/lisp/tempo.el index 28afbec0f49..e3b9c76a5b8 100644 --- a/lisp/tempo.el +++ b/lisp/tempo.el | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | ;;; tempo.el --- Flexible template insertion | 1 | ;;; tempo.el --- Flexible template insertion -*- lexical-binding: t; -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1994-1995, 2001-2019 Free Software Foundation, Inc. | 3 | ;; Copyright (C) 1994-1995, 2001-2019 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | ;; Author: David Kågedal <davidk@lysator.liu.se> | 5 | ;; Author: David Kågedal <davidk@lysator.liu.se> |
| 6 | ;; Created: 16 Feb 1994 | 6 | ;; Created: 16 Feb 1994 |
| 7 | ;; Kågedal's last version number: 1.2.4 | 7 | ;; Kågedal's last version number: 1.2.4 |
| 8 | ;; Keywords: extensions, languages, tools | 8 | ;; Keywords: abbrev, extensions, languages, tools |
| 9 | 9 | ||
| 10 | ;; This file is part of GNU Emacs. | 10 | ;; This file is part of GNU Emacs. |
| 11 | 11 | ||
| @@ -152,7 +152,7 @@ setting it to (upcase), for example.") | |||
| 152 | (defvar tempo-tags nil | 152 | (defvar tempo-tags nil |
| 153 | "An association list with tags and corresponding templates.") | 153 | "An association list with tags and corresponding templates.") |
| 154 | 154 | ||
| 155 | (defvar tempo-local-tags '((tempo-tags . nil)) | 155 | (defvar-local tempo-local-tags '((tempo-tags . nil)) |
| 156 | "A list of locally installed tag completion lists. | 156 | "A list of locally installed tag completion lists. |
| 157 | It is an association list where the car of every element is a symbol | 157 | It is an association list where the car of every element is a symbol |
| 158 | whose variable value is a template list. The cdr part, if non-nil, | 158 | whose variable value is a template list. The cdr part, if non-nil, |
| @@ -161,16 +161,16 @@ documentation for the function `tempo-complete-tag' for more info. | |||
| 161 | 161 | ||
| 162 | `tempo-tags' is always in the last position in this list.") | 162 | `tempo-tags' is always in the last position in this list.") |
| 163 | 163 | ||
| 164 | (defvar tempo-collection nil | 164 | (defvar-local tempo-collection nil |
| 165 | "A collection of all the tags defined for the current buffer.") | 165 | "A collection of all the tags defined for the current buffer.") |
| 166 | 166 | ||
| 167 | (defvar tempo-dirty-collection t | 167 | (defvar-local tempo-dirty-collection t |
| 168 | "Indicates if the tag collection needs to be rebuilt.") | 168 | "Indicates if the tag collection needs to be rebuilt.") |
| 169 | 169 | ||
| 170 | (defvar tempo-marks nil | 170 | (defvar-local tempo-marks nil |
| 171 | "A list of marks to jump to with `\\[tempo-forward-mark]' and `\\[tempo-backward-mark]'.") | 171 | "A list of marks to jump to with `\\[tempo-forward-mark]' and `\\[tempo-backward-mark]'.") |
| 172 | 172 | ||
| 173 | (defvar tempo-match-finder "\\b\\([[:word:]]+\\)\\=" | 173 | (defvar-local tempo-match-finder "\\b\\([[:word:]]+\\)\\=" |
| 174 | "The regexp or function used to find the string to match against tags. | 174 | "The regexp or function used to find the string to match against tags. |
| 175 | 175 | ||
| 176 | If `tempo-match-finder' is a string, it should contain a regular | 176 | If `tempo-match-finder' is a string, it should contain a regular |
| @@ -195,23 +195,15 @@ A list of symbols which are bound to functions that take one argument. | |||
| 195 | This function should return something to be sent to `tempo-insert' if | 195 | This function should return something to be sent to `tempo-insert' if |
| 196 | it recognizes the argument, and nil otherwise.") | 196 | it recognizes the argument, and nil otherwise.") |
| 197 | 197 | ||
| 198 | (defvar tempo-named-insertions nil | 198 | (defvar-local tempo-named-insertions nil |
| 199 | "Temporary storage for named insertions.") | 199 | "Temporary storage for named insertions.") |
| 200 | 200 | ||
| 201 | (defvar tempo-region-start (make-marker) | 201 | (defvar-local tempo-region-start (make-marker) |
| 202 | "Region start when inserting around the region.") | 202 | "Region start when inserting around the region.") |
| 203 | 203 | ||
| 204 | (defvar tempo-region-stop (make-marker) | 204 | (defvar-local tempo-region-stop (make-marker) |
| 205 | "Region stop when inserting around the region.") | 205 | "Region stop when inserting around the region.") |
| 206 | 206 | ||
| 207 | ;; Make some variables local to every buffer | ||
| 208 | |||
| 209 | (make-variable-buffer-local 'tempo-marks) | ||
| 210 | (make-variable-buffer-local 'tempo-local-tags) | ||
| 211 | (make-variable-buffer-local 'tempo-match-finder) | ||
| 212 | (make-variable-buffer-local 'tempo-collection) | ||
| 213 | (make-variable-buffer-local 'tempo-dirty-collection) | ||
| 214 | |||
| 215 | ;;; Functions | 207 | ;;; Functions |
| 216 | 208 | ||
| 217 | ;; | 209 | ;; |
| @@ -268,11 +260,14 @@ The elements in ELEMENTS can be of several types: | |||
| 268 | - `n>': Inserts a newline and indents line. | 260 | - `n>': Inserts a newline and indents line. |
| 269 | - `o': Like `%' but leaves the point before the newline. | 261 | - `o': Like `%' but leaves the point before the newline. |
| 270 | - nil: It is ignored. | 262 | - nil: It is ignored. |
| 271 | - Anything else: It is evaluated and the result is treated as an | 263 | - Anything else: Each function in `tempo-user-elements' is called |
| 272 | element to be inserted. One additional tag is useful for these | 264 | with it as argument until one of them returns non-nil, and the |
| 273 | cases. If an expression returns a list (l foo bar), the elements | 265 | result is inserted. If all of them return nil, it is evaluated and |
| 274 | after `l' will be inserted according to the usual rules. This makes | 266 | the result is treated as an element to be inserted. One additional |
| 275 | it possible to return several elements from one expression." | 267 | tag is useful for these cases. If an expression returns a list (l |
| 268 | foo bar), the elements after `l' will be inserted according to the | ||
| 269 | usual rules. This makes it possible to return several elements | ||
| 270 | from one expression." | ||
| 276 | (let* ((template-name (intern (concat "tempo-template-" | 271 | (let* ((template-name (intern (concat "tempo-template-" |
| 277 | name))) | 272 | name))) |
| 278 | (command-name template-name)) | 273 | (command-name template-name)) |