Fix declarations.
[bpt/emacs.git] / lisp / org / org-protocol.el
1 ;;; org-protocol.el --- Intercept calls from emacsclient to trigger custom actions.
2 ;;
3 ;; Copyright (C) 2008, 2009
4 ;; Free Software Foundation, Inc.
5 ;;
6 ;; Author: Bastien Guerry <bzg AT altern DOT org>
7 ;; Author: Daniel M German <dmg AT uvic DOT org>
8 ;; Author: Sebastian Rose <sebastian_rose AT gmx DOT de>
9 ;; Author: Ross Patterson <me AT rpatterson DOT net>
10 ;; Maintainer: Sebastian Rose <sebastian_rose AT gmx DOT de>
11 ;; Keywords: org, emacsclient, wp
12 ;; Version: 6.30c
13
14 ;; This file is part of GNU Emacs.
15 ;;
16 ;; GNU Emacs is free software: you can redistribute it and/or modify
17 ;; it under the terms of the GNU General Public License as published by
18 ;; the Free Software Foundation, either version 3 of the License, or
19 ;; (at your option) any later version.
20
21 ;; GNU Emacs is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
25
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28
29 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 ;;; Commentary:
31 ;;
32 ;; Intercept calls from emacsclient to trigger custom actions.
33 ;;
34 ;; This is done by advising `server-visit-files' to scann the list of filenames
35 ;; for `org-protocol-the-protocol' and sub-procols defined in
36 ;; `org-protocol-protocol-alist' and `org-protocol-protocol-alist-default'.
37 ;;
38 ;; Any application that supports calling external programs with an URL
39 ;; as argument may be used with this functionality.
40 ;;
41 ;;
42 ;; Usage:
43 ;; ------
44 ;;
45 ;; 1.) Add this to your init file (.emacs probably):
46 ;;
47 ;; (add-to-list 'load-path "/path/to/org-protocol/")
48 ;; (require 'org-protocol)
49 ;;
50 ;; 3.) Ensure emacs-server is up and running.
51 ;; 4.) Try this from the command line (adjust the URL as needed):
52 ;;
53 ;; $ emacsclient \
54 ;; org-protocol://store-link://http:%2F%2Flocalhost%2Findex.html/The%20title
55 ;;
56 ;; 5.) Optionally add custom sub-protocols and handlers:
57 ;;
58 ;; (setq org-protocol-protocol-alist
59 ;; '(("my-protocol"
60 ;; :protocol "my-protocol"
61 ;; :function my-protocol-handler-fuction)))
62 ;;
63 ;; A "sub-protocol" will be found in URLs like this:
64 ;;
65 ;; org-protocol://sub-protocol://data
66 ;;
67 ;; If it works, you can now setup other applications for using this feature.
68 ;;
69 ;;
70 ;; As of March 2009 Firefox users follow the steps documented on
71 ;; http://kb.mozillazine.org/Register_protocol, Opera setup is described here:
72 ;; http://www.opera.com/support/kb/view/535/
73 ;;
74 ;;
75 ;; Documentation
76 ;; -------------
77 ;;
78 ;; org-protocol.el comes with and installs handlers to open sources of published
79 ;; online content, store and insert the browser's URLs and cite online content
80 ;; by clicking on a bookmark in Firefox, Opera and probably other browsers and
81 ;; applications:
82 ;;
83 ;; * `org-protocol-open-source' uses the sub-protocol \"open-source\" and maps
84 ;; URLs to local filenames defined in `org-protocol-project-alist'.
85 ;;
86 ;; * `org-protocol-store-link' stores an Org-link (if Org-mode is present) and
87 ;; pushes the browsers URL to the `kill-ring' for yanking. This handler is
88 ;; triggered through the sub-protocol \"store-link\".
89 ;;
90 ;; * Call `org-protocol-remember' by using the sub-protocol \"remember\". If
91 ;; Org-mode is loaded, emacs will popup a remember buffer and fill the
92 ;; template with the data provided. I.e. the browser's URL is inserted as an
93 ;; Org-link of which the page title will be the description part. If text
94 ;; was select in the browser, that text will be the body of the entry.
95 ;;
96 ;; You may use the same bookmark URL for all those standard handlers and just
97 ;; adjust the sub-protocol used:
98 ;;
99 ;; location.href='org-protocol://sub-protocol://'+
100 ;; encodeURIComponent(location.href)+'/'+
101 ;; encodeURIComponent(document.title)+'/'+
102 ;; encodeURIComponent(window.getSelection())
103 ;;
104 ;; The handler for the sub-protocol \"remember\" detects an optional template
105 ;; char that, if present, triggers the use of a special template.
106 ;; Example:
107 ;;
108 ;; location.href='org-protocol://sub-protocol://x/'+ ...
109 ;;
110 ;; use template ?x.
111 ;;
112 ;; Note, that using double shlashes is optional from org-protocol.el's point of
113 ;; view because emacsclient sqashes the slashes to one.
114 ;;
115 ;;
116 ;; provides: 'org-protocol
117 ;;
118 ;;; Code:
119
120 (require 'org)
121 (eval-when-compile
122 (require 'cl))
123
124 (declare-function org-publish-initialize-files-alist "org-publish"
125 (&optional refresh))
126 (declare-function org-publish-get-project-from-filename "org-publish"
127 (filename &optional up))
128 (declare-function server-edit "server" (&optional arg))
129
130
131 (defgroup org-protocol nil
132 "Intercept calls from emacsclient to trigger custom actions.
133
134 This is done by advising `server-visit-files' to scann the list of filenames
135 for `org-protocol-the-protocol' and sub-procols defined in
136 `org-protocol-protocol-alist' and `org-protocol-protocol-alist-default'."
137 :version "22.1"
138 :group 'convenience
139 :group 'org)
140
141
142 ;;; Variables:
143
144 (defconst org-protocol-protocol-alist-default
145 '(("org-remember" :protocol "remember" :function org-protocol-remember :kill-client t)
146 ("org-store-link" :protocol "store-link" :function org-protocol-store-link)
147 ("org-open-source" :protocol "open-source" :function org-protocol-open-source))
148 "Default protocols to use.
149 See `org-protocol-protocol-alist' for a description of this variable.")
150
151
152 (defconst org-protocol-the-protocol "org-protocol"
153 "This is the protocol to detect if org-protocol.el is loaded.
154 `org-protocol-protocol-alist-default' and `org-protocol-protocol-alist' hold the
155 sub-protocols that trigger the required action. You will have to define just one
156 protocol handler OS-wide (MS-Windows) or per application (Linux). That protocol
157 handler should call emacsclient.")
158
159
160 ;;; User variables:
161
162 (defcustom org-protocol-reverse-list-of-files t
163 "* The filenames passed on the commandline are passed to the emacs-server in
164 reversed order. Set to `t' (default) to re-reverse the list, i.e. use the
165 sequence on the command line. If nil, the sequence of the filenames is
166 unchanged."
167 :group 'org-protocol
168 :type 'boolean)
169
170
171 (defcustom org-protocol-project-alist nil
172 "* Map URLs to local filenames for `org-protocol-open-source' (open-source).
173
174 Each element of this list must be of the form:
175
176 (module-name :property value property: value ...)
177
178 where module-name is an arbitrary name. All the values are strings.
179
180 Possible properties are:
181
182 :online-suffix - the suffix to strip from the published URLs
183 :working-suffix - the replacement for online-suffix
184 :base-url - the base URL, e.g. http://www.example.com/project/
185 Last slash required.
186 :working-directory - the local working directory. This is, what base-url will
187 be replaced with.
188
189 Example:
190
191 (setq org-protocol-project-alist
192 '((\"http://orgmode.org/worg/\"
193 :online-suffix \".php\"
194 :working-suffix \".org\"
195 :base-url \"http://orgmode.org/worg/\"
196 :working-directory \"/home/user/org/Worg/\")
197 (\"http://localhost/org-notes/\"
198 :online-suffix \".html\"
199 :working-suffix \".org\"
200 :base-url \"http://localhost/org/\"
201 :working-directory \"/home/user/org/\")))
202
203 Consider using the interactive functions `org-protocol-create' and
204 `org-protocol-create-for-org' to help you filling this variable with valid contents."
205 :group 'org-protocol
206 :type 'alist)
207
208
209 (defcustom org-protocol-protocol-alist nil
210 "* Register custom handlers for org-protocol.
211
212 Each element of this list must be of the form:
213
214 (module-name :protocol protocol :function func :kill-client nil)
215
216 protocol - protocol to detect in a filename without trailing colon and slashes.
217 See rfc1738 section 2.1 for more on this.
218 If you define a protocol \"my-protocol\", `org-protocol-check-filename-for-protocol'
219 will search filenames for \"org-protocol:/my-protocol:/\"
220 and trigger your action for every match. `org-protocol' is defined in
221 `org-protocol-the-protocol'. Double and tripple slashes are compressed
222 to one by emacsclient.
223
224 function - function that handles requests with protocol and takes exactly one
225 argument: the filename with all protocols stripped. If the function
226 returns nil, emacsclient and -server do nothing. Any non-nil return
227 value is considered a valid filename and thus passed to the server.
228
229 `org-protocol.el provides some support for handling those filenames,
230 if you stay with the conventions used for the standard handlers in
231 `org-protocol-protocol-alist-default'. See `org-protocol-split-data'.
232
233 kill-client - If t, kill the client immediately, once the sub-protocol is
234 detected. This is neccessary for actions that can be interupted by
235 `C-g' to avoid dangeling emacsclients. Note, that all other command
236 line arguments but the this one will be discarded, greedy handlers
237 still receive the whole list of arguments though.
238
239 Here is an example:
240
241 (setq org-protocol-protocol-alist
242 '((\"my-protocol\"
243 :protocol \"my-protocol\"
244 :function my-protocol-handler-fuction)
245 (\"your-protocol\"
246 :protocol \"your-protocol\"
247 :function your-protocol-handler-fuction)))"
248 :group 'org-protocol
249 :type '(alist))
250
251 (defcustom org-protocol-default-template-key "w"
252 "The default org-remember-templates key to use."
253 :group 'org-protocol
254 :type 'string)
255
256
257 ;;; Helper functions:
258
259 (defun org-protocol-sanitize-uri (uri)
260 "emacsclient compresses double and tripple slashes.
261 Slashes are sanitized to double slashes here."
262 (when (string-match "^\\([a-z]+\\):/" uri)
263 (let* ((splitparts (split-string uri "/+")))
264 (setq uri (concat (car splitparts) "//" (mapconcat 'identity (cdr splitparts) "/")))))
265 uri)
266
267
268 (defun org-protocol-split-data(data &optional unhexify separator)
269 "Split, what a org-protocol handler function gets as only argument.
270 data is that one argument. Data is splitted at each occurrence of separator
271 (regexp). If no separator is specified or separator is nil, assume \"/+\".
272 The results of that splitting are return as a list. If unhexify is non-nil,
273 hex-decode each split part. If unhexify is a function, use that function to
274 decode each split part."
275 (let* ((sep (or separator "/+"))
276 (split-parts (split-string data sep)))
277 (if unhexify
278 (if (fboundp unhexify)
279 (mapcar unhexify split-parts)
280 (mapcar 'org-protocol-unhex-string split-parts))
281 split-parts)))
282
283 (defun org-protocol-unhex-string(str)
284 "Unhex hexified unicode strings as returned from the JavaScript function
285 encodeURIComponent. E.g. `%C3%B6' is the german Umlaut `ü'."
286 (setq str (or str ""))
287 (let ((tmp "")
288 (case-fold-search t))
289 (while (string-match "\\(%[0-9a-f][0-9a-f]\\)+" str)
290 (let* ((start (match-beginning 0))
291 (end (match-end 0))
292 (hex (match-string 0 str))
293 (replacement (org-protocol-unhex-compound hex)))
294 (setq tmp (concat tmp (substring str 0 start) replacement))
295 (setq str (substring str end))))
296 (setq tmp (concat tmp str))
297 tmp))
298
299
300 (defun org-protocol-unhex-compound (hex)
301 "Unhexify unicode hex-chars. E.g. `%C3%B6' is the german Umlaut `ü'."
302 (let* ((bytes (remove "" (split-string hex "%")))
303 (ret "")
304 (eat 0)
305 (sum 0))
306 (while bytes
307 (let* ((b (pop bytes))
308 (a (elt b 0))
309 (b (elt b 1))
310 (c1 (if (> a ?9) (+ 10 (- a ?A)) (- a ?0)))
311 (c2 (if (> b ?9) (+ 10 (- b ?A)) (- b ?0)))
312 (val (+ (lsh c1 4) c2))
313 (shift
314 (if (= 0 eat) ;; new byte
315 (if (>= val 252) 6
316 (if (>= val 248) 5
317 (if (>= val 240) 4
318 (if (>= val 224) 3
319 (if (>= val 192) 2 0)))))
320 6))
321 (xor
322 (if (= 0 eat) ;; new byte
323 (if (>= val 252) 252
324 (if (>= val 248) 248
325 (if (>= val 240) 240
326 (if (>= val 224) 224
327 (if (>= val 192) 192 0)))))
328 128)))
329 (if (>= val 192) (setq eat shift))
330 (setq val (logxor val xor))
331 (setq sum (+ (lsh sum shift) val))
332 (if (> eat 0) (setq eat (- eat 1)))
333 (when (= 0 eat)
334 (setq ret (concat ret (char-to-string sum)))
335 (setq sum 0))
336 )) ;; end (while bytes
337 ret ))
338
339 (defun org-protocol-flatten-greedy (param-list &optional strip-path replacement)
340 "Greedy handlers might recieve a list like this from emacsclient:
341 '( (\"/dir/org-protocol:/greedy:/~/path1\" (23 . 12)) (\"/dir/param\")
342 where \"/dir/\" is the absolute path to emacsclients working directory. This
343 function transforms it into a flat list utilizing `org-protocol-flatten' and
344 transforms the elements of that list as follows:
345
346 If strip-path is non-nil, remove the \"/dir/\" prefix from all members of
347 param-list.
348
349 If replacement is string, replace the \"/dir/\" prefix with it.
350
351 The first parameter, the one that contains the protocols, is always changed.
352 Everything up to the end of the protocols is stripped.
353
354 Note, that this function will always behave as if
355 `org-protocol-reverse-list-of-files' was set to t and the returned list will
356 reflect that. I.e. emacsclients first parameter will be the first one in the
357 returned list."
358 (let* ((l (org-protocol-flatten (if org-protocol-reverse-list-of-files
359 param-list
360 (reverse param-list))))
361 (trigger (car l))
362 (len 0)
363 dir
364 ret)
365 (when (string-match "^\\(.*\\)\\(org-protocol:/+[a-zA-z0-9][-_a-zA-z0-9]*:/+\\)\\(.*\\)" trigger)
366 (setq dir (match-string 1 trigger))
367 (setq len (length dir))
368 (setcar l (concat dir (match-string 3 trigger))))
369 (if strip-path
370 (progn
371 (dolist (e l ret)
372 (setq ret
373 (append ret
374 (list
375 (if (stringp e)
376 (if (stringp replacement)
377 (setq e (concat replacement (substring e len)))
378 (setq e (substring e len)))
379 e)))))
380 ret)
381 l)))
382
383
384 (defun org-protocol-flatten (l)
385 "Greedy handlers might recieve a list like this from emacsclient:
386 '( (\"/dir/org-protocol:/greedy:/~/path1\" (23 . 12)) (\"/dir/param\")
387 where \"/dir/\" is the absolute path to emacsclients working directory. This
388 function transforms it into a flat list."
389 (if (null l) ()
390 (if (listp l)
391 (append (org-protocol-flatten (car l)) (org-protocol-flatten (cdr l)))
392 (list l))))
393
394 ;;; Standard protocol handlers:
395
396 (defun org-protocol-store-link (fname)
397 "Process an org-protocol://store-link:// style url
398 and store a browser URL as an org link. Also pushes the links URL to the
399 `kill-ring'.
400
401 The location for a browser's bookmark has to look like this:
402
403 javascript:location.href='org-protocol://store-link://'+ \\
404 encodeURIComponent(location.href)
405 encodeURIComponent(document.title)+'/'+ \\
406
407 Don't use `escape()'! Use `encodeURIComponent()' instead. The title of the page
408 could contain slashes and the location definitely will.
409
410 The sub-protocol used to reach this function is set in
411 `org-protocol-protocol-alist'."
412 (let* ((splitparts (org-protocol-split-data fname t))
413 (uri (org-protocol-sanitize-uri (car splitparts)))
414 (title (cadr splitparts))
415 orglink)
416 (if (boundp 'org-stored-links)
417 (setq org-stored-links (cons (list uri title) org-stored-links)))
418 (kill-new uri)
419 (message "`%s' to insert new org-link, `%s' to insert `%s'"
420 (substitute-command-keys"\\[org-insert-link]")
421 (substitute-command-keys"\\[yank]")
422 uri))
423 nil)
424
425 (defun org-protocol-remember (info)
426 "Process an org-protocol://remember:// style url.
427
428 The sub-protocol used to reach this function is set in
429 `org-protocol-protocol-alist'.
430
431 This function detects an URL, title and optinal text, separated by '/'
432 The location for a browser's bookmark has to look like this:
433
434 javascript:location.href='org-protocol://remember://'+ \\
435 encodeURIComponent(location.href)+'/' \\
436 encodeURIComponent(document.title)+'/'+ \\
437 encodeURIComponent(window.getSelection())
438
439 By default, it uses the character `org-protocol-default-template-key',
440 which should be associated with a template in `org-remember-templates'.
441 But you may prepend the encoded URL with a character and a slash like so:
442
443 javascript:location.href='org-protocol://org-store-link://b/'+ ...
444
445 Now template ?b will be used."
446
447 (if (and (boundp 'org-stored-links)
448 (fboundp 'org-remember))
449 (let* ((parts (org-protocol-split-data info t))
450 (template (or (and (= 1 (length (car parts))) (pop parts))
451 org-protocol-default-template-key))
452 (url (org-protocol-sanitize-uri (car parts)))
453 (type (if (string-match "^\\([a-z]+\\):" url)
454 (match-string 1 url)))
455 (title (cadr parts))
456 (region (caddr parts))
457 (orglink (org-make-link-string url title))
458 remember-annotation-functions)
459 (setq org-stored-links
460 (cons (list url title) org-stored-links))
461 (kill-new orglink)
462 (org-store-link-props :type type
463 :link url
464 :description title
465 :initial region)
466 (raise-frame)
467 (org-remember nil (string-to-char template)))
468
469 (message "Org-mode not loaded."))
470 nil)
471
472 (defun org-protocol-open-source (fname)
473 "Process an org-protocol://open-source:// style url.
474
475 Change a filename by mapping URLs to local filenames as set
476 in `org-protocol-project-alist'.
477
478 The location for a browser's bookmark should look like this:
479
480 javascript:location.href='org-protocol://open-source://'+ \\
481 encodeURIComponent(location.href)"
482
483 ;; As we enter this function for a match on our protocol, the return value
484 ;; defaults to nil.
485 (let ((result nil)
486 (f (org-protocol-unhex-string fname)))
487 (catch 'result
488 (dolist (prolist org-protocol-project-alist)
489 (let* ((base-url (plist-get (cdr prolist) :base-url))
490 (wsearch (regexp-quote base-url)))
491
492 (when (string-match wsearch f)
493 (let* ((wdir (plist-get (cdr prolist) :working-directory))
494 (strip-suffix (plist-get (cdr prolist) :online-suffix))
495 (add-suffix (plist-get (cdr prolist) :working-suffix))
496 (start-pos (+ (string-match wsearch f) (length base-url)))
497 (end-pos (string-match
498 (concat (regexp-quote strip-suffix) "\\([?#].*\\)?$") f))
499 (the-file (concat wdir (substring f start-pos end-pos) add-suffix)))
500 (if (file-readable-p the-file)
501 (throw 'result the-file))
502 (if (file-exists-p the-file)
503 (message "%s: permission denied!" the-file)
504 (message "%s: no such file or directory." the-file))))))
505 result)))
506
507
508 ;;; Core functions:
509
510 (defun org-protocol-check-filename-for-protocol (fname restoffiles client)
511 "Detect if `org-protocol-the-protocol' and a known sub-protocol is used in fname.
512 Sub-protocols are registered in `org-protocol-protocol-alist' and
513 `org-protocol-protocol-alist-default'.
514 This is, how the matching is done:
515
516 (string-match \"protocol:/+sub-protocol:/+\" ...)
517
518 protocol and sub-protocol are regexp-quoted.
519
520 If a matching protcol is found, the protcol is stripped from fname and the
521 result is passed to the protocols function as the only parameter. If the
522 function returns nil, the filename is removed from the list of filenames
523 passed from emacsclient to the server.
524 If the function returns a non nil value, that value is passed to the server
525 as filename."
526 (let ((sub-protocols (append org-protocol-protocol-alist org-protocol-protocol-alist-default)))
527 (catch 'fname
528 (let ((the-protocol (concat (regexp-quote org-protocol-the-protocol) ":/+")))
529 (when (string-match the-protocol fname)
530 (dolist (prolist sub-protocols)
531 (let ((proto (concat the-protocol (regexp-quote (plist-get (cdr prolist) :protocol)) ":/+")))
532 (when (string-match proto fname)
533 (let* ((func (plist-get (cdr prolist) :function))
534 (greedy (plist-get (cdr prolist) :greedy))
535 (splitted (split-string fname proto))
536 (result (if greedy restoffiles (cadr splitted))))
537 (when (plist-get (cdr prolist) :kill-client)
538 (message "Greedy org-protocol handler. Killing client.")
539 (server-edit))
540 (when (fboundp func)
541 (unless greedy
542 (throw 'fname (funcall func result)))
543 (funcall func result)
544 (throw 'fname t))))))))
545 ;; (message "fname: %s" fname)
546 fname)))
547
548
549 (defadvice server-visit-files (before org-protocol-detect-protocol-server activate)
550 "Advice server-visit-flist to call `org-protocol-modify-filename-for-protocol'."
551 (let ((flist (if org-protocol-reverse-list-of-files
552 (reverse (ad-get-arg 0))
553 (ad-get-arg 0)))
554 (client (ad-get-arg 1)))
555 (catch 'greedy
556 (dolist (var flist)
557 (let ((fname (expand-file-name (car var)))) ;; `\' to `/' on windows. FIXME: could this be done any better?
558 (setq fname (org-protocol-check-filename-for-protocol fname (member var flist) client))
559 (if (eq fname t) ;; greedy? We need the `t' return value.
560 (progn
561 (ad-set-arg 0 nil)
562 (throw 'greedy t))
563 (if (stringp fname) ;; probably filename
564 (setcar var fname)
565 (ad-set-arg 0 (delq var (ad-get-arg 0))))))
566 ))))
567
568 ;;; Org specific functions:
569
570 (defun org-protocol-create-for-org ()
571 "Create a org-protocol project for the current file's Org-mode project.
572 This works, if the file visited is part of a publishing project in
573 `org-publish-project-alist'. This functions calls `org-protocol-create' to do
574 most of the work."
575 (interactive)
576 (require 'org-publish)
577 (org-publish-initialize-files-alist)
578 (let ((all (or (org-publish-get-project-from-filename buffer-file-name))))
579 (if all (org-protocol-create (cdr all))
580 (message "Not in an org-project. Did mean %s?"
581 (substitute-command-keys"\\[org-protocol-create]")))))
582
583
584 (defun org-protocol-create(&optional project-plist)
585 "Create a new org-protocol project interactively.
586 An org-protocol project is an entry in `org-protocol-project-alist'
587 which is used by `org-protocol-open-source'.
588 Optionally use project-plist to initialize the defaults for this worglet. If
589 project-plist is the CDR of an element in `org-publish-project-alist', reuse
590 :base-directory, :html-extension and :base-extension."
591 (interactive)
592 (let ((working-dir (expand-file-name(or (plist-get project-plist :base-directory) default-directory)))
593 (base-url "http://orgmode.org/worg/")
594 (strip-suffix (or (plist-get project-plist :html-extension) ".html"))
595 (working-suffix (if (plist-get project-plist :base-extension)
596 (concat "." (plist-get project-plist :base-extension))
597 ".org"))
598
599 (worglet-buffer nil)
600
601 (insert-default-directory t)
602 (minibuffer-allow-text-properties nil))
603
604 (setq base-url (read-string "Base URL of published content: " base-url nil base-url t))
605 (if (not (string-match "\\/$" base-url))
606 (setq base-url (concat base-url "/")))
607
608 (setq working-dir
609 (expand-file-name
610 (read-directory-name "Local working directory: " working-dir working-dir t)))
611 (if (not (string-match "\\/$" working-dir))
612 (setq working-dir (concat working-dir "/")))
613
614 (setq strip-suffix
615 (read-string
616 (concat "Extension to strip from published URLs ("strip-suffix"): ")
617 strip-suffix nil strip-suffix t))
618
619 (setq working-suffix
620 (read-string
621 (concat "Extension of editable files ("working-suffix"): ")
622 working-suffix nil working-suffix t))
623
624 (when (yes-or-no-p "Save the new worglet to your init file? ")
625 (setq org-protocol-project-alist
626 (cons `(,base-url . (:base-url ,base-url
627 :working-directory ,working-dir
628 :online-suffix ,strip-suffix
629 :working-suffix ,working-suffix))
630 org-protocol-project-alist))
631 (customize-save-variable 'org-protocol-project-alist org-protocol-project-alist))))
632
633 (provide 'org-protocol)
634
635 ;; arch-tag: b5c5c2ac-77cf-4a94-a649-2163dff95846
636 ;;; org-protocol.el ends here