annotate lisp/quickurl.el @ 25535:2fe0f62fa349

(mh-forward): Get new subject line from the original, not from the draft to forward.
author Richard M. Stallman <rms@gnu.org>
date Sat, 04 Sep 1999 00:08:17 +0000
parents de4c44c1c073
children 564aae4ff7f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25442
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; quickurl.el --- Insert an URL based on text at point in buffer.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1999 Free Software Foundation, Inc.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: Dave Pearson <davep@hagbard.demon.co.uk>
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Maintainer: Dave Pearson <davep@hagbard.demon.co.uk>
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Created: 1999-05-28
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; Keywords: hypermedia
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; This file is part of GNU emacs.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; any later version.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; GNU General Public License for more details.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;; Commentary:
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; This package provides a simple method of inserting an URL based on the
25497
de4c44c1c073 (quickurl): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 25442
diff changeset
30 ;; text at point in the current buffer. This is part of an on-going effort
de4c44c1c073 (quickurl): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 25442
diff changeset
31 ;; to increase the information I provide people while reducing the ammount
de4c44c1c073 (quickurl): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 25442
diff changeset
32 ;; of typing I need to do. No-doubt there are undiscovered Emacs packages
de4c44c1c073 (quickurl): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 25442
diff changeset
33 ;; out there that do all of this and do it better, feel free to point me to
de4c44c1c073 (quickurl): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 25442
diff changeset
34 ;; them, in the mean time I'm having fun playing with Emacs Lisp.
25442
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;;
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; The URLs are stored in an external file as a list of either cons cells,
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; or lists. A cons cell entry looks like this:
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;;
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; (<Lookup> . <URL>)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;;
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; where <Lookup> is a string that acts as the keyword lookup and <URL> is
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;; the URL associated with it. An example might be:
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;;
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; ("GNU" . "http://www.gnu.org/")
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;;
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; A list entry looks like:
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;;
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; (<Lookup> <URL> <Comment>)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;;
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; where <Lookup> and <URL> are the same as with the cons cell and <Comment>
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; is any text you like that describes the URL. This description will be
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;; used when presenting a list of URLS using `quickurl-list'. An example
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; might be:
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;;
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; ("FSF" "http://www.fsf.org/" "The Free Software Foundation")
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;;
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;; Given the above, your quickurl file might look like:
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;;
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;; (("GNU" . "http://www.gnu.org/")
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;; ("FSF" "http://www.fsf.org/" "The Free Software Foundation")
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;; ("emacs" . "http://www.emacs.org/")
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;; ("hagbard" "http://www.hagbard.demon.co.uk" "Hagbard's World"))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;;
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;; In case you're wondering about the mixture of cons cells and lists,
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;; quickurl started life using just the cons cells, there were no comments.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;; URL comments are a later addition and so there is a mixture to keep
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;; backward compatibility with existing URL lists.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;;
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;; The name and location of the file is up to you, the default name used by
25497
de4c44c1c073 (quickurl): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 25442
diff changeset
70 ;; `quickurl' is stored in `quickurl-url-file'.
25442
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;;
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;; quickurl is always available from:
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;;
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;; <URL:http://www.hagbard.demon.co.uk/archives/quickurl.el>
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;; <URL:http://www.acemake.com/hagbard/archives/quickurl.el>
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;;; TODO:
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;;
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;; o The quickurl-browse-url* functions pretty much duplicate their non
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;; browsing friends. It would feel better if a more generic solution could
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;; be found.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;;; Code:
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;; Things we need:
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 (eval-when-compile
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 (require 'cl))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 (require 'thingatpt)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 (require 'pp)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (require 'browse-url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 ;; Attempt to handle older/other emacs.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 (eval-and-compile
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;; If customize isn't available just use defvar instead.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (unless (fboundp 'defgroup)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (defmacro defgroup (&rest rest) nil)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (defmacro defcustom (symbol init docstring &rest rest)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 `(defvar ,symbol ,init ,docstring))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 ;; `caddr' is a function in cl and so might not always be available
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 ;; (remembering the general rule that says cl functions should not be used,
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 ;; only cl macros). So, to make use of `caddr' without forcing the load of
25497
de4c44c1c073 (quickurl): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 25442
diff changeset
104 ;; cl-seq we'll define our own.
25442
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 (eval-when (load eval)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 (unless (fboundp 'caddr)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (defun caddr (l)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 "Return the `car' of the `cddr' of L."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 (car (cddr l)))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 ;; Customize options.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (defgroup quickurl nil
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 "Insert an URL based on text at point in buffer."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 :group 'abbrev
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 :prefix "quickurl-")
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (defcustom quickurl-url-file "~/.quickurls"
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 "*File that contains the URL list."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 :type 'file
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 :group 'quickurl)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (defcustom quickurl-format-function (lambda (url) (format "<URL:%s>" url))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 "*Function to format the URL before insertion into the current buffer."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 :type 'function
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 :group 'quickurl)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (defcustom quickurl-sort-function (lambda (list)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 (sort list
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (lambda (x y)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (string<
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (downcase (quickurl-url-description x))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (downcase (quickurl-url-description y))))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 "*Function to sort the URL list."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 :type 'function
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 :group 'quickurl)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (defcustom quickurl-grab-lookup-function #'current-word
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 "*Function to grab the thing to lookup."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 :type 'function
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 :group 'quickurl)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (defcustom quickurl-assoc-function #'assoc-ignore-case
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 "*Function to use for alist lookup into `quickurl-urls'."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 :type 'function
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 :group 'quickurl)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (defcustom quickurl-prefix ";; -*- lisp -*-\n\n"
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 "*Text to write to `quickurl-url-file' before writing the URL list."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 :type 'string
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 :group 'quickurl)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (defcustom quickurl-postfix ""
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 "*Text to write to `quickurl-url-file' after writing the URL list.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 See the constant `quickurl-reread-hook-postfix' for some example text that
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 could be used here."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 :type 'string
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 :group 'quickurl)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (defcustom quickurl-list-mode-hook nil
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 "*Hooks for `quickurl-list-mode'."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 :type 'hook
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 :group 'quickurl)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 ;; Constants.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 ;;;###autoload
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (defconst quickurl-reread-hook-postfix
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 "
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 ;; Local Variables:
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 ;; eval: (progn (require 'quickurl) (add-hook 'local-write-file-hooks (lambda () (quickurl-read) nil)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 ;; End:
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 "
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 "Example `quickurl-postfix' text that adds a local variable to the
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 `quickurl-url-file' so that if you edit it by hand it will ensure that
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 `quickurl-urls' is updated with the new URL list.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 To make use of this do something like:
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (setq quickurl-postfix quickurl-reread-hook-postfix)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 in your ~/.emacs (after loading/requiring quickurl).")
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 ;; Non-customize variables.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (defvar quickurl-urls nil
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 "URL alist for use with `quickurl' and `quickurl-ask'.")
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (defvar quickurl-list-mode-map nil
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 "Local keymap for a `quickurl-list-mode' buffer.")
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (defvar quickurl-list-buffer-name "*quickurl-list*"
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 "Name for the URL listinig buffer.")
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (defvar quickurl-list-last-buffer nil
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 "`current-buffer' when `quickurl-list' was called.")
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 ;; Functions for working with an URL entry.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (defun quickurl-url-commented-p (url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 "Does the URL have a comment?"
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (listp (cdr url)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (defun quickurl-make-url (keyword url &optional comment)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 "Create an URL from KEYWORD, URL and (optionaly) COMMENT."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (if (and comment (not (zerop (length comment))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (list keyword url comment)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (cons keyword url)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (defun quickurl-url-keyword (url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 "Return the keyword for the URL.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 Note that this function is a setfable place."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (car url))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (defsetf quickurl-url-keyword (url) (store)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 `(setf (car ,url) ,store))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (defun quickurl-url-url (url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 "Return the actual URL of the URL.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 Note that this function is a setfable place."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (if (quickurl-url-commented-p url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (cadr url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (cdr url)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (defsetf quickurl-url-url (url) (store)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 `
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (if (quickurl-url-commented-p ,url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (setf (cadr ,url) ,store)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (setf (cdr ,url) ,store)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (defun quickurl-url-comment (url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 "Get the comment from an URL.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 If the URL has no comment an empty string is returned. Also note that this
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 function is a setfable place."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (if (quickurl-url-commented-p url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (caddr url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 ""))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (defsetf quickurl-url-comment (url) (store)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 `
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (if (quickurl-url-commented-p ,url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (if (zerop (length ,store))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (setf (cdr ,url) (cadr ,url))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (setf (caddr ,url) ,store))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (unless (zerop (length ,store))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (setf (cdr ,url) (list (cdr ,url) ,store)))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (defun quickurl-url-description (url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 "Return a description for the URL.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 If the URL has a comment then this is returned, otherwise the keyword is
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 returned."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (let ((desc (quickurl-url-comment url)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 (if (zerop (length desc))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (quickurl-url-keyword url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 desc)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 ;; Main code:
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (defun* quickurl-read (&optional (buffer (current-buffer)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 "`read' the URL list from BUFFER into `quickurl-urls'.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 Note that this function moves point to `point-min' before doing the `read'
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 It also restores point after the `read'."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (save-excursion
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (setf (point) (point-min))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (setq quickurl-urls (funcall quickurl-sort-function (read buffer)))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (defun quickurl-load-urls ()
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 "Load the contents of `quickurl-url-file' into `quickurl-urls'."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (when (file-exists-p quickurl-url-file)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (with-temp-buffer
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (insert-file-contents quickurl-url-file)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (quickurl-read))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (defun quickurl-save-urls ()
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 "Save the contents of `quickurl-urls' to `quickurl-url-file'."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (with-temp-buffer
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (let ((standard-output (current-buffer)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (princ quickurl-prefix)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (pp quickurl-urls)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (princ quickurl-postfix)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (write-region (point-min) (point-max) quickurl-url-file nil 0))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (defun quickurl-find-url (lookup)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 "Return URL associated with key LOOKUP.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 The lookup is done by looking in the alist `quickurl-urls' and the `cons'
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 for the URL is returned. The actual method used to look into the alist
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 depends on the setting of the variable `quickurl-assoc-function'."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (funcall quickurl-assoc-function lookup quickurl-urls))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 (defun quickurl-insert (url &optional silent)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 "Insert URL, formatted using `quickurl-format-function'.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 Also display a `message' saying what the URL was unless SILENT is non-nil."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (insert (funcall quickurl-format-function (quickurl-url-url url)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (unless silent
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (message "Found %s" (quickurl-url-url url))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 ;;;###autoload
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 (defun* quickurl (&optional (lookup (funcall quickurl-grab-lookup-function)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 "Insert an URL based on LOOKUP.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309
25497
de4c44c1c073 (quickurl): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 25442
diff changeset
310 If not supplied LOOKUP is taken to be the word at point in the current
de4c44c1c073 (quickurl): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 25442
diff changeset
311 buffer, this default action can be modifed via
25442
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 `quickurl-grab-lookup-function'."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 (interactive)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 (when lookup
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (quickurl-load-urls)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (let ((url (quickurl-find-url lookup)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 (if (null url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 (error "No URL associated with \"%s\"" lookup)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (when (looking-at "\\w")
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (skip-syntax-forward "\\w"))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 (insert " ")
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (quickurl-insert url)))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 ;;;###autoload
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (defun quickurl-ask (lookup)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 "Insert an URL, with `completing-read' prompt, based on LOOKUP."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (interactive
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 (list
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (progn
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 (quickurl-load-urls)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (completing-read "Lookup: " quickurl-urls nil t))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (let ((url (quickurl-find-url lookup)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (when url
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (quickurl-insert url))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (defun quickurl-grab-url ()
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 "Attempt to grab a word/url pair from point in the current buffer.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 Point should be somewhere on the URL and the word is taken to be the thing
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 that is returned from calling `quickurl-grab-lookup-function' once a
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 `backward-word' has been issued at the start of the URL.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 It is assumed that the URL is either \"unguarded\" or is wrapped inside an
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 <URL:...> wrapper."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (let ((url (thing-at-point 'url)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (when url
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (save-excursion
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (beginning-of-thing 'url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 ;; `beginning-of-thing' doesn't take you to the start of a marked-up
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 ;; URL, only to the start of the URL within the "markup". So, we
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 ;; need to do a little more work to get to where we want to be.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 (when (thing-at-point-looking-at thing-at-point-markedup-url-regexp)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (search-backward "<URL:"))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (backward-word 1)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (let ((word (funcall quickurl-grab-lookup-function)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 (when word
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 (quickurl-make-url
25497
de4c44c1c073 (quickurl): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents: 25442
diff changeset
358 ;; The grab function may return the word with properties. I don't
25442
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 ;; want the properties. I couldn't find a method of stripping
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 ;; them from a "string" so this will have to do. If you know of
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 ;; a better method of doing this I'd love to know.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 (with-temp-buffer
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 (insert word)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (buffer-substring-no-properties (point-min) (point-max)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 url)))))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 ;;;###autoload
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 (defun quickurl-add-url (word url comment)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 "Allow the user to interactively add a new URL associated with WORD.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 See `quickurl-grab-url' for details on how the default word/url combination
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 is decided."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (interactive (let ((word-url (quickurl-grab-url)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (list (read-string "Word: " (quickurl-url-keyword word-url))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (read-string "URL: " (quickurl-url-url word-url))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (read-string "Comment: " (quickurl-url-comment word-url)))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 (if (zerop (length word))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 (error "You must specify a WORD for lookup")
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 (quickurl-load-urls)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 (let* ((current-url (quickurl-find-url word))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (add-it (if current-url
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (if (interactive-p)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 (y-or-n-p (format "\"%s\" exists, replace URL? " word))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 t)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 t)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 (when add-it
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 (if current-url
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 (progn
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 (setf (quickurl-url-url current-url) url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 (setf (quickurl-url-comment current-url) comment))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 (push (quickurl-make-url word url comment) quickurl-urls))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (setq quickurl-urls (funcall quickurl-sort-function quickurl-urls))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 (quickurl-save-urls)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 (when (get-buffer quickurl-list-buffer-name)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 (quickurl-list-populate-buffer))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 (when (interactive-p)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 (message "Added %s" url))))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 ;;;###autoload
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 (defun* quickurl-browse-url (&optional (lookup (funcall quickurl-grab-lookup-function)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 "Browse the URL associated with LOOKUP.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 If not supplied LOOKUP is taken to be the word at point in the
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 current buffer, this default action can be modifed via
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 `quickurl-grab-lookup-function'."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 (interactive)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 (when lookup
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (quickurl-load-urls)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (let ((url (quickurl-find-url lookup)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 (if url
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 (browse-url (quickurl-url-url url))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 (error "No URL associated with \"%s\"" lookup)))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 ;;;###autoload
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (defun quickurl-browse-url-ask (lookup)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 "Browse the URL, with `completing-read' prompt, associated with LOOKUP."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (interactive (list
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 (progn
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 (quickurl-load-urls)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 (completing-read "Browse: " quickurl-urls nil t))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 (let ((url (quickurl-find-url lookup)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (when url
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (browse-url (quickurl-url-url url)))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 ;;;###autoload
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 (defun quickurl-edit-urls ()
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 "Pull `quickurl-url-file' into a buffer for hand editing."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 (interactive)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 (find-file quickurl-url-file))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 ;; quickurl-list mode.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 (unless quickurl-list-mode-map
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 (let ((map (make-sparse-keymap)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 (suppress-keymap map t)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 (define-key map "a" #'quickurl-list-add-url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 (define-key map [(control m)] #'quickurl-list-insert-url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 (define-key map "u" #'quickurl-list-insert-naked-url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 (define-key map " " #'quickurl-list-insert-with-lookup)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 (define-key map "l" #'quickurl-list-insert-lookup)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 (define-key map "d" #'quickurl-list-insert-with-desc)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 (define-key map [(control g)] #'quickurl-list-quit)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (define-key map "q" #'quickurl-list-quit)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (define-key map [mouse-2] #'quickurl-list-mouse-select)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (define-key map "?" #'describe-mode)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 (setq quickurl-list-mode-map map)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 (put 'quickurl-list-mode 'mode-class 'special)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 ;;;###autoload
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 (defun quickurl-list-mode ()
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 "A mode for browsing the quickurl URL list.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 The key bindings for `quickurl-list-mode' are:
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 \\{quickurl-list-mode-map}"
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 (interactive)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 (kill-all-local-variables)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 (use-local-map quickurl-list-mode-map)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 (setq major-mode 'quickurl-list-mode
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 mode-name "quickurl list")
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 (run-hooks 'quickurl-list-mode-hook)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 (setq buffer-read-only t
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 truncate-lines t))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 ;;;###autoload
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 (defun quickurl-list ()
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 "Display `quickurl-list' as a formatted list using `quickurl-list-mode'."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 (interactive)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 (quickurl-load-urls)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 (unless (string= (buffer-name) quickurl-list-buffer-name)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 (setq quickurl-list-last-buffer (current-buffer)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 (pop-to-buffer quickurl-list-buffer-name)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 (quickurl-list-populate-buffer)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 (quickurl-list-mode))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 (defun quickurl-list-populate-buffer ()
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 "Populate the `quickurl-list' buffer."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 (with-current-buffer (get-buffer quickurl-list-buffer-name)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 (let ((buffer-read-only nil)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 (fmt (format "%%-%ds %%s\n"
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 (apply #'max (or (loop for url in quickurl-urls
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 collect (length (quickurl-url-description url)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 (list 20))))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 (setf (buffer-string) "")
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 (loop for url in quickurl-urls
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 do (let ((start (point)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 (insert (format fmt (quickurl-url-description url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 (quickurl-url-url url)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 (put-text-property start (1- (point))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 'mouse-face 'highlight)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 (setf (point) (point-min)))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 (defun quickurl-list-add-url (word url comment)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 "Wrapper for `quickurl-add-url' that doesn't guess the parameters."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 (interactive "sWord: \nsURL: \nsComment: ")
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 (quickurl-add-url word url comment))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 (defun quickurl-list-quit ()
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 "Kill the buffer named `quickurl-list-buffer-name'."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 (interactive)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 (kill-buffer quickurl-list-buffer-name)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 (switch-to-buffer quickurl-list-last-buffer)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 (delete-other-windows))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 (defun quickurl-list-mouse-select (event)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 "Select the URL under the mouse click."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 (interactive "e")
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 (setf (point) (posn-point (event-end event)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 (quickurl-list-insert-url))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 (defun quickurl-list-focused-line ()
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 "Work out the line containing point."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 (save-excursion
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 (beginning-of-line)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 (let ((point (point)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 (setf (point) (point-min))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 (loop while (< (point) point) sum 1 do (next-line 1)))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 (defun quickurl-list-insert (type)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 "Insert the URL under cursor into `quickurl-list-last-buffer'.
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 TYPE dictates what will be inserted, options are:
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 `url' - Insert the URL as <URL:url>
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 `naked-url' - Insert the URL with no formatting
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 `with-lookup' - Insert \"lookup <URL:url>\"
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 `with-desc' - Insert \"description <URL:url>\"
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 `lookup' - Insert the lookup for that URL"
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 (let ((url (nth (quickurl-list-focused-line) quickurl-urls)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 (if url
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 (with-current-buffer quickurl-list-last-buffer
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 (insert
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 (case type
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 ('url (format "<URL:%s>" (quickurl-url-url url)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 ('naked-url (quickurl-url-url url))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 ('with-lookup (format "%s <URL:%s>"
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 (quickurl-url-keyword url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 (quickurl-url-url url)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 ('with-desc (format "%S <URL:%s>"
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 (quickurl-url-description url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 (quickurl-url-url url)))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 ('lookup (quickurl-url-keyword url)))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 (error "No URL details on that line"))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 url))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 (defmacro quickurl-list-make-inserter (type)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 "Macro to make a key-response function for use in `quickurl-list-mode-map'."
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 `(defun ,(intern (format "quickurl-list-insert-%S" type)) ()
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 ,(format "Insert the result of calling `quickurl-list-insert' with `%s'." type)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 (interactive)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 (when (quickurl-list-insert ',type)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 (quickurl-list-quit))))
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 (quickurl-list-make-inserter url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 (quickurl-list-make-inserter naked-url)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 (quickurl-list-make-inserter with-lookup)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 (quickurl-list-make-inserter with-desc)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 (quickurl-list-make-inserter lookup)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 (provide 'quickurl)
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560
b12e672a1edd Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 ;;; quickurl.el ends here