diff options
| author | Stefan Kangas | 2019-07-01 01:21:47 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2019-07-03 14:49:38 +0300 |
| commit | 22760ab357dd8124c856b76a545e562917872d78 (patch) | |
| tree | 0cc0df574e004ed5a1bda791e2d5c460fe191558 /lisp | |
| parent | ecd7d40a3be0b3b51743fc2c2e98dd14c6faca84 (diff) | |
| download | emacs-22760ab357dd8124c856b76a545e562917872d78.tar.gz emacs-22760ab357dd8124c856b76a545e562917872d78.zip | |
Add tests for bookmark.el (Bug#36452)
* test/lisp/bookmark-resources/example.txt:
* test/lisp/bookmark-resources/test.bmk:
* test/lisp/bookmark-tests.el: New files.
* lisp/bookmark.el: Minor cleanups.
(bookmark-insert-annotation): Signal error on invalid bookmark.
(bookmark-write-file): Add newline at end of file.
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/bookmark.el | 48 |
1 files changed, 16 insertions, 32 deletions
diff --git a/lisp/bookmark.el b/lisp/bookmark.el index bbef0a927dc..92d0da35949 100644 --- a/lisp/bookmark.el +++ b/lisp/bookmark.el | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | ;; Author: Karl Fogel <kfogel@red-bean.com> | 5 | ;; Author: Karl Fogel <kfogel@red-bean.com> |
| 6 | ;; Created: July, 1993 | 6 | ;; Created: July, 1993 |
| 7 | ;; Keywords: bookmarks, placeholders, annotations | 7 | ;; Keywords: convenience |
| 8 | 8 | ||
| 9 | ;; This file is part of GNU Emacs. | 9 | ;; This file is part of GNU Emacs. |
| 10 | 10 | ||
| @@ -50,8 +50,7 @@ | |||
| 50 | 50 | ||
| 51 | (defcustom bookmark-use-annotations nil | 51 | (defcustom bookmark-use-annotations nil |
| 52 | "If non-nil, setting a bookmark queries for an annotation in a buffer." | 52 | "If non-nil, setting a bookmark queries for an annotation in a buffer." |
| 53 | :type 'boolean | 53 | :type 'boolean) |
| 54 | :group 'bookmark) | ||
| 55 | 54 | ||
| 56 | 55 | ||
| 57 | (defcustom bookmark-save-flag t | 56 | (defcustom bookmark-save-flag t |
| @@ -71,14 +70,11 @@ behavior.) | |||
| 71 | 70 | ||
| 72 | To specify the file in which to save them, modify the variable | 71 | To specify the file in which to save them, modify the variable |
| 73 | `bookmark-default-file'." | 72 | `bookmark-default-file'." |
| 74 | :type '(choice (const nil) integer (other t)) | 73 | :type '(choice (const nil) integer (other t))) |
| 75 | :group 'bookmark) | ||
| 76 | 74 | ||
| 77 | 75 | ||
| 78 | (define-obsolete-variable-alias 'bookmark-old-default-file | 76 | (define-obsolete-variable-alias 'bookmark-old-default-file |
| 79 | 'bookmark-default-file "27.1") | 77 | 'bookmark-default-file "27.1") |
| 80 | |||
| 81 | |||
| 82 | (define-obsolete-variable-alias 'bookmark-file 'bookmark-default-file "27.1") | 78 | (define-obsolete-variable-alias 'bookmark-file 'bookmark-default-file "27.1") |
| 83 | (defcustom bookmark-default-file | 79 | (defcustom bookmark-default-file |
| 84 | (locate-user-emacs-file "bookmarks" ".emacs.bmk") | 80 | (locate-user-emacs-file "bookmarks" ".emacs.bmk") |
| @@ -86,8 +82,7 @@ To specify the file in which to save them, modify the variable | |||
| 86 | ;; The current default file is defined via the internal variable | 82 | ;; The current default file is defined via the internal variable |
| 87 | ;; `bookmark-bookmarks-timestamp'. This does not affect the value | 83 | ;; `bookmark-bookmarks-timestamp'. This does not affect the value |
| 88 | ;; of `bookmark-default-file'. | 84 | ;; of `bookmark-default-file'. |
| 89 | :type 'file | 85 | :type 'file) |
| 90 | :group 'bookmark) | ||
| 91 | 86 | ||
| 92 | (defcustom bookmark-watch-bookmark-file t | 87 | (defcustom bookmark-watch-bookmark-file t |
| 93 | "If non-nil watch the default bookmark file. | 88 | "If non-nil watch the default bookmark file. |
| @@ -108,35 +103,30 @@ just use the value of `version-control'." | |||
| 108 | :type '(choice (const :tag "If existing" nil) | 103 | :type '(choice (const :tag "If existing" nil) |
| 109 | (const :tag "Never" never) | 104 | (const :tag "Never" never) |
| 110 | (const :tag "Use value of option `version-control'" nospecial) | 105 | (const :tag "Use value of option `version-control'" nospecial) |
| 111 | (other :tag "Always" t)) | 106 | (other :tag "Always" t))) |
| 112 | :group 'bookmark) | ||
| 113 | 107 | ||
| 114 | 108 | ||
| 115 | (defcustom bookmark-completion-ignore-case t | 109 | (defcustom bookmark-completion-ignore-case t |
| 116 | "Non-nil means bookmark functions ignore case in completion." | 110 | "Non-nil means bookmark functions ignore case in completion." |
| 117 | :type 'boolean | 111 | :type 'boolean) |
| 118 | :group 'bookmark) | ||
| 119 | 112 | ||
| 120 | 113 | ||
| 121 | (defcustom bookmark-sort-flag t | 114 | (defcustom bookmark-sort-flag t |
| 122 | "Non-nil means that bookmarks will be displayed sorted by bookmark name. | 115 | "Non-nil means that bookmarks will be displayed sorted by bookmark name. |
| 123 | Otherwise they will be displayed in LIFO order (that is, most | 116 | Otherwise they will be displayed in LIFO order (that is, most |
| 124 | recently set ones come first, oldest ones come last)." | 117 | recently set ones come first, oldest ones come last)." |
| 125 | :type 'boolean | 118 | :type 'boolean) |
| 126 | :group 'bookmark) | ||
| 127 | 119 | ||
| 128 | 120 | ||
| 129 | (defcustom bookmark-automatically-show-annotations t | 121 | (defcustom bookmark-automatically-show-annotations t |
| 130 | "Non-nil means show annotations when jumping to a bookmark." | 122 | "Non-nil means show annotations when jumping to a bookmark." |
| 131 | :type 'boolean | 123 | :type 'boolean) |
| 132 | :group 'bookmark) | ||
| 133 | 124 | ||
| 134 | (defcustom bookmark-bmenu-use-header-line t | 125 | (defcustom bookmark-bmenu-use-header-line t |
| 135 | "Non-nil means to use an immovable header line. | 126 | "Non-nil means to use an immovable header line. |
| 136 | This is as opposed to inline text at the top of the buffer." | 127 | This is as opposed to inline text at the top of the buffer." |
| 137 | :version "24.4" | 128 | :version "24.4" |
| 138 | :type 'boolean | 129 | :type 'boolean) |
| 139 | :group 'bookmark) | ||
| 140 | 130 | ||
| 141 | (defconst bookmark-bmenu-inline-header-height 2 | 131 | (defconst bookmark-bmenu-inline-header-height 2 |
| 142 | "Number of lines used for the *Bookmark List* header. | 132 | "Number of lines used for the *Bookmark List* header. |
| @@ -150,36 +140,30 @@ This includes the annotations column.") | |||
| 150 | (defcustom bookmark-bmenu-file-column 30 | 140 | (defcustom bookmark-bmenu-file-column 30 |
| 151 | "Column at which to display filenames in a buffer listing bookmarks. | 141 | "Column at which to display filenames in a buffer listing bookmarks. |
| 152 | You can toggle whether files are shown with \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-toggle-filenames]." | 142 | You can toggle whether files are shown with \\<bookmark-bmenu-mode-map>\\[bookmark-bmenu-toggle-filenames]." |
| 153 | :type 'integer | 143 | :type 'integer) |
| 154 | :group 'bookmark) | ||
| 155 | 144 | ||
| 156 | 145 | ||
| 157 | (defcustom bookmark-bmenu-toggle-filenames t | 146 | (defcustom bookmark-bmenu-toggle-filenames t |
| 158 | "Non-nil means show filenames when listing bookmarks. | 147 | "Non-nil means show filenames when listing bookmarks. |
| 159 | A non-nil value may result in truncated bookmark names." | 148 | A non-nil value may result in truncated bookmark names." |
| 160 | :type 'boolean | 149 | :type 'boolean) |
| 161 | :group 'bookmark) | ||
| 162 | 150 | ||
| 163 | (defface bookmark-menu-bookmark | 151 | (defface bookmark-menu-bookmark |
| 164 | '((t (:weight bold))) | 152 | '((t (:weight bold))) |
| 165 | "Face used to highlight bookmark names in bookmark menu buffers." | 153 | "Face used to highlight bookmark names in bookmark menu buffers.") |
| 166 | :group 'bookmark) | ||
| 167 | 154 | ||
| 168 | (defcustom bookmark-menu-length 70 | 155 | (defcustom bookmark-menu-length 70 |
| 169 | "Maximum length of a bookmark name displayed on a popup menu." | 156 | "Maximum length of a bookmark name displayed on a popup menu." |
| 170 | :type 'integer | 157 | :type 'integer) |
| 171 | :group 'bookmark) | ||
| 172 | 158 | ||
| 173 | ;; FIXME: Is it really worth a customization option? | 159 | ;; FIXME: Is it really worth a customization option? |
| 174 | (defcustom bookmark-search-delay 0.2 | 160 | (defcustom bookmark-search-delay 0.2 |
| 175 | "Time before `bookmark-bmenu-search' updates the display." | 161 | "Time before `bookmark-bmenu-search' updates the display." |
| 176 | :group 'bookmark | ||
| 177 | :type 'number) | 162 | :type 'number) |
| 178 | 163 | ||
| 179 | (defface bookmark-menu-heading | 164 | (defface bookmark-menu-heading |
| 180 | '((t (:inherit font-lock-type-face))) | 165 | '((t (:inherit font-lock-type-face))) |
| 181 | "Face used to highlight the heading in bookmark menu buffers." | 166 | "Face used to highlight the heading in bookmark menu buffers." |
| 182 | :group 'bookmark | ||
| 183 | :version "22.1") | 167 | :version "22.1") |
| 184 | 168 | ||
| 185 | 169 | ||
| @@ -279,8 +263,6 @@ defaults to `bookmark-default-file' and MODTIME is its modification time.") | |||
| 279 | (defvar bookmark-file-coding-system nil | 263 | (defvar bookmark-file-coding-system nil |
| 280 | "The coding-system of the last loaded or saved bookmark file.") | 264 | "The coding-system of the last loaded or saved bookmark file.") |
| 281 | 265 | ||
| 282 | ;; more stuff added by db. | ||
| 283 | |||
| 284 | (defvar bookmark-current-bookmark nil | 266 | (defvar bookmark-current-bookmark nil |
| 285 | "Name of bookmark most recently used in the current file. | 267 | "Name of bookmark most recently used in the current file. |
| 286 | It is buffer local, used to make moving a bookmark forward | 268 | It is buffer local, used to make moving a bookmark forward |
| @@ -937,6 +919,8 @@ It takes one argument, the name of the bookmark, as a string.") | |||
| 937 | 919 | ||
| 938 | (defun bookmark-insert-annotation (bookmark-name-or-record) | 920 | (defun bookmark-insert-annotation (bookmark-name-or-record) |
| 939 | "Insert annotation for BOOKMARK-NAME-OR-RECORD at point." | 921 | "Insert annotation for BOOKMARK-NAME-OR-RECORD at point." |
| 922 | (when (not (bookmark-get-bookmark bookmark-name-or-record t)) | ||
| 923 | (error "Invalid bookmark: %s" bookmark-name-or-record)) | ||
| 940 | (insert (funcall bookmark-edit-annotation-text-func bookmark-name-or-record)) | 924 | (insert (funcall bookmark-edit-annotation-text-func bookmark-name-or-record)) |
| 941 | (let ((annotation (bookmark-get-annotation bookmark-name-or-record))) | 925 | (let ((annotation (bookmark-get-annotation bookmark-name-or-record))) |
| 942 | (if (and annotation (not (string-equal annotation ""))) | 926 | (if (and annotation (not (string-equal annotation ""))) |
| @@ -1449,7 +1433,7 @@ for a file, defaulting to the file defined by variable | |||
| 1449 | ;; Apparently `pp' has a poor algorithmic complexity, so this | 1433 | ;; Apparently `pp' has a poor algorithmic complexity, so this |
| 1450 | ;; scales a lot better. bug#4485. | 1434 | ;; scales a lot better. bug#4485. |
| 1451 | (dolist (i bookmark-alist) (pp i (current-buffer))) | 1435 | (dolist (i bookmark-alist) (pp i (current-buffer))) |
| 1452 | (insert ")") | 1436 | (insert ")\n") |
| 1453 | ;; Make sure the specified encoding can safely encode the | 1437 | ;; Make sure the specified encoding can safely encode the |
| 1454 | ;; bookmarks. If it cannot, suggest utf-8-emacs as default. | 1438 | ;; bookmarks. If it cannot, suggest utf-8-emacs as default. |
| 1455 | (with-coding-priority '(utf-8-emacs) | 1439 | (with-coding-priority '(utf-8-emacs) |