diff options
| author | Mark Oteiza | 2016-11-09 12:54:36 -0500 |
|---|---|---|
| committer | Mark Oteiza | 2016-11-09 12:54:36 -0500 |
| commit | 86cbd942bc9c41d60aaefe15b6eab5b4dce390e9 (patch) | |
| tree | a787e6fefe36a7078e5bc0467995473b019c35ca | |
| parent | dba9bc9752f62c782853c7a652e84e33f0649c3b (diff) | |
| download | emacs-86cbd942bc9c41d60aaefe15b6eab5b4dce390e9.tar.gz emacs-86cbd942bc9c41d60aaefe15b6eab5b4dce390e9.zip | |
Update quickurl.el
* lisp/net/quickurl.el (quickurl-format-function):
(quickurl-sort-function): Use named function.
(quickurl-list-mode-map): Remove lines that are extraneous now that the
parent mode is special-mode.
(quickurl-format-url, quickurl-sort-urls): New functions.
(quickurl-read, quickurl): Use defun, as no cl-defun feature appears to
be used.
(quickurl-list-mode): Derive from special-mode. Nix setting
buffer-read-only: special-mode does that.
(quickurl-list-populate-buffer): Use dolist instead.
(quickurl-list-quit): Use quit-window. It looks like this was written
before the quit-window rewrite. quit-window is very useful now.
| -rw-r--r-- | lisp/net/quickurl.el | 52 |
1 files changed, 25 insertions, 27 deletions
diff --git a/lisp/net/quickurl.el b/lisp/net/quickurl.el index bb9ce31307b..773589af47e 100644 --- a/lisp/net/quickurl.el +++ b/lisp/net/quickurl.el | |||
| @@ -101,17 +101,12 @@ | |||
| 101 | :type 'file | 101 | :type 'file |
| 102 | :group 'quickurl) | 102 | :group 'quickurl) |
| 103 | 103 | ||
| 104 | (defcustom quickurl-format-function (lambda (url) (format "<URL:%s>" (quickurl-url-url url))) | 104 | (defcustom quickurl-format-function #'quickurl-format-url |
| 105 | "Function to format the URL before insertion into the current buffer." | 105 | "Function to format the URL before insertion into the current buffer." |
| 106 | :type 'function | 106 | :type 'function |
| 107 | :group 'quickurl) | 107 | :group 'quickurl) |
| 108 | 108 | ||
| 109 | (defcustom quickurl-sort-function (lambda (list) | 109 | (defcustom quickurl-sort-function #'quickurl-sort-urls |
| 110 | (sort list | ||
| 111 | (lambda (x y) | ||
| 112 | (string< | ||
| 113 | (downcase (quickurl-url-description x)) | ||
| 114 | (downcase (quickurl-url-description y)))))) | ||
| 115 | "Function to sort the URL list." | 110 | "Function to sort the URL list." |
| 116 | :type 'function | 111 | :type 'function |
| 117 | :group 'quickurl) | 112 | :group 'quickurl) |
| @@ -175,7 +170,6 @@ in your init file (after loading/requiring quickurl).") | |||
| 175 | 170 | ||
| 176 | (defvar quickurl-list-mode-map | 171 | (defvar quickurl-list-mode-map |
| 177 | (let ((map (make-sparse-keymap))) | 172 | (let ((map (make-sparse-keymap))) |
| 178 | (suppress-keymap map t) | ||
| 179 | (define-key map "a" #'quickurl-list-add-url) | 173 | (define-key map "a" #'quickurl-list-add-url) |
| 180 | (define-key map [(control m)] #'quickurl-list-insert-url) | 174 | (define-key map [(control m)] #'quickurl-list-insert-url) |
| 181 | (define-key map "u" #'quickurl-list-insert-naked-url) | 175 | (define-key map "u" #'quickurl-list-insert-naked-url) |
| @@ -185,7 +179,6 @@ in your init file (after loading/requiring quickurl).") | |||
| 185 | (define-key map [(control g)] #'quickurl-list-quit) | 179 | (define-key map [(control g)] #'quickurl-list-quit) |
| 186 | (define-key map "q" #'quickurl-list-quit) | 180 | (define-key map "q" #'quickurl-list-quit) |
| 187 | (define-key map [mouse-2] #'quickurl-list-mouse-select) | 181 | (define-key map [mouse-2] #'quickurl-list-mouse-select) |
| 188 | (define-key map "?" #'describe-mode) | ||
| 189 | map) | 182 | map) |
| 190 | "Local keymap for a `quickurl-list-mode' buffer.") | 183 | "Local keymap for a `quickurl-list-mode' buffer.") |
| 191 | 184 | ||
| @@ -253,7 +246,18 @@ returned." | |||
| 253 | 246 | ||
| 254 | ;; Main code: | 247 | ;; Main code: |
| 255 | 248 | ||
| 256 | (cl-defun quickurl-read (&optional buffer) | 249 | (defun quickurl-format-url (url) |
| 250 | (format "<URL:%s>" (quickurl-url-url url))) | ||
| 251 | |||
| 252 | (defun quickurl-sort-urls (list) | ||
| 253 | "Sort URLs in LIST according to their `quickurl-url-description'." | ||
| 254 | (sort list | ||
| 255 | (lambda (x y) | ||
| 256 | (string< | ||
| 257 | (downcase (quickurl-url-description x)) | ||
| 258 | (downcase (quickurl-url-description y)))))) | ||
| 259 | |||
| 260 | (defun quickurl-read (&optional buffer) | ||
| 257 | "`read' the URL list from BUFFER into `quickurl-urls'. | 261 | "`read' the URL list from BUFFER into `quickurl-urls'. |
| 258 | 262 | ||
| 259 | BUFFER, if nil, defaults to current buffer. | 263 | BUFFER, if nil, defaults to current buffer. |
| @@ -298,7 +302,7 @@ Also display a `message' saying what the URL was unless SILENT is non-nil." | |||
| 298 | (message "Found %s" (quickurl-url-url url)))) | 302 | (message "Found %s" (quickurl-url-url url)))) |
| 299 | 303 | ||
| 300 | ;;;###autoload | 304 | ;;;###autoload |
| 301 | (cl-defun quickurl (&optional lookup) | 305 | (defun quickurl (&optional lookup) |
| 302 | "Insert a URL based on LOOKUP. | 306 | "Insert a URL based on LOOKUP. |
| 303 | 307 | ||
| 304 | If not supplied LOOKUP is taken to be the word at point in the current | 308 | If not supplied LOOKUP is taken to be the word at point in the current |
| @@ -427,17 +431,14 @@ current buffer, this default action can be modified via | |||
| 427 | 431 | ||
| 428 | ;; quickurl-list mode. | 432 | ;; quickurl-list mode. |
| 429 | 433 | ||
| 430 | (put 'quickurl-list-mode 'mode-class 'special) | ||
| 431 | |||
| 432 | ;;;###autoload | 434 | ;;;###autoload |
| 433 | (define-derived-mode quickurl-list-mode fundamental-mode "quickurl list" | 435 | (define-derived-mode quickurl-list-mode special-mode "Quickurl" |
| 434 | "A mode for browsing the quickurl URL list. | 436 | "A mode for browsing the quickurl URL list. |
| 435 | 437 | ||
| 436 | The key bindings for `quickurl-list-mode' are: | 438 | The key bindings for `quickurl-list-mode' are: |
| 437 | 439 | ||
| 438 | \\{quickurl-list-mode-map}" | 440 | \\{quickurl-list-mode-map}" |
| 439 | (setq buffer-read-only t | 441 | (setq truncate-lines t)) |
| 440 | truncate-lines t)) | ||
| 441 | 442 | ||
| 442 | ;;;###autoload | 443 | ;;;###autoload |
| 443 | (defun quickurl-list () | 444 | (defun quickurl-list () |
| @@ -459,14 +460,13 @@ The key bindings for `quickurl-list-mode' are: | |||
| 459 | (fmt (format "%%-%ds %%s\n" (apply #'max sizes))) | 460 | (fmt (format "%%-%ds %%s\n" (apply #'max sizes))) |
| 460 | (inhibit-read-only t)) | 461 | (inhibit-read-only t)) |
| 461 | (erase-buffer) | 462 | (erase-buffer) |
| 462 | (cl-loop for url in quickurl-urls | 463 | (dolist (url quickurl-urls) |
| 463 | do (let ((start (point))) | 464 | (let ((start (point))) |
| 464 | (insert (format fmt (quickurl-url-description url) | 465 | (insert (format fmt (quickurl-url-description url) |
| 465 | (quickurl-url-url url))) | 466 | (quickurl-url-url url))) |
| 466 | (add-text-properties | 467 | (add-text-properties |
| 467 | start (1- (point)) | 468 | start (1- (point)) |
| 468 | '(mouse-face highlight | 469 | '(mouse-face highlight help-echo "mouse-2: insert this URL")))) |
| 469 | help-echo "mouse-2: insert this URL")))) | ||
| 470 | (goto-char (point-min))))) | 470 | (goto-char (point-min))))) |
| 471 | 471 | ||
| 472 | (defun quickurl-list-add-url (word url comment) | 472 | (defun quickurl-list-add-url (word url comment) |
| @@ -477,9 +477,7 @@ The key bindings for `quickurl-list-mode' are: | |||
| 477 | (defun quickurl-list-quit () | 477 | (defun quickurl-list-quit () |
| 478 | "Kill the buffer named `quickurl-list-buffer-name'." | 478 | "Kill the buffer named `quickurl-list-buffer-name'." |
| 479 | (interactive) | 479 | (interactive) |
| 480 | (kill-buffer quickurl-list-buffer-name) | 480 | (quit-window t)) |
| 481 | (switch-to-buffer quickurl-list-last-buffer) | ||
| 482 | (delete-other-windows)) | ||
| 483 | 481 | ||
| 484 | (defun quickurl-list-mouse-select (event) | 482 | (defun quickurl-list-mouse-select (event) |
| 485 | "Select the URL under the mouse click." | 483 | "Select the URL under the mouse click." |