annotate lisp/net/quickurl.el @ 82426:a86fcb95bff2

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