2016-06-21 17:23:18 -04:00
|
|
|
;;; org-protocol.el --- Intercept Calls from Emacsclient to Trigger Custom Actions -*- lexical-binding: t; -*-
|
2009-03-30 09:47:34 -04:00
|
|
|
;;
|
2023-01-01 05:31:12 -05:00
|
|
|
;; Copyright (C) 2008-2023 Free Software Foundation, Inc.
|
2009-03-30 09:47:34 -04:00
|
|
|
;;
|
2013-10-08 02:07:21 -04:00
|
|
|
;; Authors: Bastien Guerry <bzg@gnu.org>
|
2012-04-01 18:53:28 -04:00
|
|
|
;; Daniel M German <dmg AT uvic DOT org>
|
|
|
|
;; Sebastian Rose <sebastian_rose AT gmx DOT de>
|
|
|
|
;; Ross Patterson <me AT rpatterson DOT net>
|
2009-03-30 09:47:34 -04:00
|
|
|
;; Maintainer: Sebastian Rose <sebastian_rose AT gmx DOT de>
|
|
|
|
;; Keywords: org, emacsclient, wp
|
|
|
|
|
2009-08-04 18:59:09 -04:00
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
2009-03-30 09:47:34 -04:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
|
2009-08-04 18:59:09 -04:00
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
2009-03-30 09:47:34 -04:00
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
2009-08-04 18:59:09 -04:00
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 18:52:52 -04:00
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
2009-03-30 09:47:34 -04:00
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;; Commentary:
|
|
|
|
;;
|
|
|
|
;; Intercept calls from emacsclient to trigger custom actions.
|
|
|
|
;;
|
2010-07-16 17:23:01 -04:00
|
|
|
;; This is done by advising `server-visit-files' to scan the list of filenames
|
|
|
|
;; for `org-protocol-the-protocol' and sub-protocols defined in
|
2009-03-30 09:47:34 -04:00
|
|
|
;; `org-protocol-protocol-alist' and `org-protocol-protocol-alist-default'.
|
|
|
|
;;
|
|
|
|
;; Any application that supports calling external programs with an URL
|
|
|
|
;; as argument may be used with this functionality.
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
;; Usage:
|
|
|
|
;; ------
|
|
|
|
;;
|
|
|
|
;; 1.) Add this to your init file (.emacs probably):
|
|
|
|
;;
|
|
|
|
;; (require 'org-protocol)
|
|
|
|
;;
|
|
|
|
;; 3.) Ensure emacs-server is up and running.
|
|
|
|
;; 4.) Try this from the command line (adjust the URL as needed):
|
|
|
|
;;
|
|
|
|
;; $ emacsclient \
|
2021-03-28 12:38:59 -04:00
|
|
|
;; "org-protocol://store-link?url=http:%2F%2Flocalhost%2Findex.html&title=The%20title"
|
2009-03-30 09:47:34 -04:00
|
|
|
;;
|
|
|
|
;; 5.) Optionally add custom sub-protocols and handlers:
|
|
|
|
;;
|
|
|
|
;; (setq org-protocol-protocol-alist
|
|
|
|
;; '(("my-protocol"
|
|
|
|
;; :protocol "my-protocol"
|
2010-07-16 17:23:01 -04:00
|
|
|
;; :function my-protocol-handler-function)))
|
2009-03-30 09:47:34 -04:00
|
|
|
;;
|
|
|
|
;; A "sub-protocol" will be found in URLs like this:
|
|
|
|
;;
|
2015-12-02 10:53:07 -05:00
|
|
|
;; org-protocol://sub-protocol?key=val&key2=val2
|
2009-03-30 09:47:34 -04:00
|
|
|
;;
|
|
|
|
;; If it works, you can now setup other applications for using this feature.
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
;; As of March 2009 Firefox users follow the steps documented on
|
2022-10-15 05:17:51 -04:00
|
|
|
;; https://kb.mozillazine.org/Register_protocol, Opera setup is described here:
|
2009-03-30 09:47:34 -04:00
|
|
|
;; http://www.opera.com/support/kb/view/535/
|
|
|
|
;;
|
|
|
|
;;
|
|
|
|
;; Documentation
|
|
|
|
;; -------------
|
|
|
|
;;
|
|
|
|
;; org-protocol.el comes with and installs handlers to open sources of published
|
|
|
|
;; online content, store and insert the browser's URLs and cite online content
|
|
|
|
;; by clicking on a bookmark in Firefox, Opera and probably other browsers and
|
|
|
|
;; applications:
|
|
|
|
;;
|
|
|
|
;; * `org-protocol-open-source' uses the sub-protocol \"open-source\" and maps
|
|
|
|
;; URLs to local filenames defined in `org-protocol-project-alist'.
|
|
|
|
;;
|
2016-08-23 16:13:56 -04:00
|
|
|
;; * `org-protocol-store-link' stores an Org link (if Org is present) and
|
2010-07-16 17:23:01 -04:00
|
|
|
;; pushes the browsers URL to the `kill-ring' for yanking. This handler is
|
2009-03-30 09:47:34 -04:00
|
|
|
;; triggered through the sub-protocol \"store-link\".
|
|
|
|
;;
|
2010-06-22 10:20:13 -04:00
|
|
|
;; * Call `org-protocol-capture' by using the sub-protocol \"capture\". If
|
2016-08-23 16:13:56 -04:00
|
|
|
;; Org is loaded, Emacs will pop-up a capture buffer and fill the
|
2010-07-16 17:23:01 -04:00
|
|
|
;; template with the data provided. I.e. the browser's URL is inserted as an
|
|
|
|
;; Org-link of which the page title will be the description part. If text
|
2009-03-30 09:47:34 -04:00
|
|
|
;; was select in the browser, that text will be the body of the entry.
|
|
|
|
;;
|
|
|
|
;; You may use the same bookmark URL for all those standard handlers and just
|
|
|
|
;; adjust the sub-protocol used:
|
|
|
|
;;
|
2021-04-06 10:30:06 -04:00
|
|
|
;; javascript:location.href='org-protocol://sub-protocol?'+
|
|
|
|
;; new URLSearchParams({
|
|
|
|
;; url: location.href,
|
|
|
|
;; title: document.title,
|
|
|
|
;; body: window.getSelection()})
|
|
|
|
;;
|
|
|
|
;; Alternatively use the following expression that encodes space as \"%20\"
|
|
|
|
;; instead of \"+\", so it is compatible with Org versions from 9.0 to 9.4:
|
|
|
|
;;
|
2015-12-02 10:53:07 -05:00
|
|
|
;; location.href='org-protocol://sub-protocol?url='+
|
|
|
|
;; encodeURIComponent(location.href)+'&title='+
|
|
|
|
;; encodeURIComponent(document.title)+'&body='+
|
2009-03-30 09:47:34 -04:00
|
|
|
;; encodeURIComponent(window.getSelection())
|
|
|
|
;;
|
2010-06-22 10:20:13 -04:00
|
|
|
;; The handler for the sub-protocol \"capture\" detects an optional template
|
2009-03-30 09:47:34 -04:00
|
|
|
;; char that, if present, triggers the use of a special template.
|
|
|
|
;; Example:
|
|
|
|
;;
|
2021-04-06 10:30:06 -04:00
|
|
|
;; location.href='org-protocol://capture?'+
|
|
|
|
;; new URLSearchParams({template:'x', /* ... */})
|
|
|
|
;;
|
|
|
|
;; or
|
|
|
|
;;
|
2015-12-02 10:53:07 -05:00
|
|
|
;; location.href='org-protocol://capture?template=x'+ ...
|
2009-03-30 09:47:34 -04:00
|
|
|
;;
|
2015-12-02 10:53:07 -05:00
|
|
|
;; uses template ?x.
|
2009-03-30 09:47:34 -04:00
|
|
|
;;
|
2015-12-02 10:53:07 -05:00
|
|
|
;; Note that using double slashes is optional from org-protocol.el's point of
|
2009-11-12 07:39:29 -05:00
|
|
|
;; view because emacsclient squashes the slashes to one.
|
2009-03-30 09:47:34 -04:00
|
|
|
;;
|
|
|
|
;;
|
|
|
|
;; provides: 'org-protocol
|
|
|
|
;;
|
|
|
|
;;; Code:
|
|
|
|
|
2022-08-04 09:53:05 -04:00
|
|
|
(require 'org-macs)
|
|
|
|
(org-assert-version)
|
|
|
|
|
2009-03-30 09:47:34 -04:00
|
|
|
(require 'org)
|
2018-11-26 18:04:41 -05:00
|
|
|
(require 'ol)
|
2009-03-30 09:47:34 -04:00
|
|
|
|
2016-05-14 22:56:53 -04:00
|
|
|
(declare-function org-publish-get-project-from-filename "ox-publish"
|
2009-03-31 14:39:54 -04:00
|
|
|
(filename &optional up))
|
2009-04-18 14:52:12 -04:00
|
|
|
|
2016-06-21 17:36:31 -04:00
|
|
|
(defvar org-capture-link-is-already-stored)
|
2018-12-18 03:30:32 -05:00
|
|
|
(defvar org-capture-templates)
|
2016-06-21 17:36:31 -04:00
|
|
|
|
2009-03-30 09:47:34 -04:00
|
|
|
(defgroup org-protocol nil
|
|
|
|
"Intercept calls from emacsclient to trigger custom actions.
|
|
|
|
|
2012-01-10 05:56:15 -05:00
|
|
|
This is done by advising `server-visit-files' to scan the list of filenames
|
|
|
|
for `org-protocol-the-protocol' and sub-protocols defined in
|
2009-03-30 09:47:34 -04:00
|
|
|
`org-protocol-protocol-alist' and `org-protocol-protocol-alist-default'."
|
|
|
|
:version "22.1"
|
|
|
|
:group 'convenience
|
|
|
|
:group 'org)
|
|
|
|
|
|
|
|
|
|
|
|
;;; Variables:
|
|
|
|
|
|
|
|
(defconst org-protocol-protocol-alist-default
|
2013-02-22 05:44:29 -05:00
|
|
|
'(("org-capture" :protocol "capture" :function org-protocol-capture :kill-client t)
|
2009-03-30 09:47:34 -04:00
|
|
|
("org-store-link" :protocol "store-link" :function org-protocol-store-link)
|
|
|
|
("org-open-source" :protocol "open-source" :function org-protocol-open-source))
|
|
|
|
"Default protocols to use.
|
|
|
|
See `org-protocol-protocol-alist' for a description of this variable.")
|
|
|
|
|
|
|
|
(defconst org-protocol-the-protocol "org-protocol"
|
|
|
|
"This is the protocol to detect if org-protocol.el is loaded.
|
2010-07-16 17:23:01 -04:00
|
|
|
`org-protocol-protocol-alist-default' and `org-protocol-protocol-alist' hold
|
|
|
|
the sub-protocols that trigger the required action. You will have to define
|
|
|
|
just one protocol handler OS-wide (MS-Windows) or per application (Linux).
|
|
|
|
That protocol handler should call emacsclient.")
|
2009-03-30 09:47:34 -04:00
|
|
|
|
|
|
|
;;; User variables:
|
|
|
|
|
|
|
|
(defcustom org-protocol-reverse-list-of-files t
|
2011-03-23 05:14:03 -04:00
|
|
|
"Non-nil means re-reverse the list of filenames passed on the command line.
|
2010-07-16 17:23:01 -04:00
|
|
|
The filenames passed on the command line are passed to the emacs-server in
|
|
|
|
reverse order. Set to t (default) to re-reverse the list, i.e. use the
|
|
|
|
sequence on the command line. If nil, the sequence of the filenames is
|
2009-03-30 09:47:34 -04:00
|
|
|
unchanged."
|
|
|
|
:type 'boolean)
|
|
|
|
|
|
|
|
(defcustom org-protocol-project-alist nil
|
2011-03-23 05:14:03 -04:00
|
|
|
"Map URLs to local filenames for `org-protocol-open-source' (open-source).
|
2009-03-30 09:47:34 -04:00
|
|
|
|
|
|
|
Each element of this list must be of the form:
|
|
|
|
|
|
|
|
(module-name :property value property: value ...)
|
|
|
|
|
2012-08-11 13:10:44 -04:00
|
|
|
where module-name is an arbitrary name. All the values are strings.
|
2009-03-30 09:47:34 -04:00
|
|
|
|
|
|
|
Possible properties are:
|
|
|
|
|
|
|
|
:online-suffix - the suffix to strip from the published URLs
|
|
|
|
:working-suffix - the replacement for online-suffix
|
2021-03-21 14:55:14 -04:00
|
|
|
:base-url - the base URL, e.g. https://www.example.com/project/
|
2009-03-30 09:47:34 -04:00
|
|
|
Last slash required.
|
2021-09-24 08:46:56 -04:00
|
|
|
:working-directory - the local working directory. This is what
|
|
|
|
base-url will be replaced with.
|
|
|
|
:redirects - A list of cons cells, each of which maps a
|
|
|
|
regular expression to match to a path relative
|
|
|
|
to `:working-directory'.
|
2009-03-30 09:47:34 -04:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
(setq org-protocol-project-alist
|
2018-01-16 13:42:57 -05:00
|
|
|
\\='((\"https://orgmode.org/worg/\"
|
2009-03-30 09:47:34 -04:00
|
|
|
:online-suffix \".php\"
|
|
|
|
:working-suffix \".org\"
|
2018-01-16 13:42:57 -05:00
|
|
|
:base-url \"https://orgmode.org/worg/\"
|
2009-03-30 09:47:34 -04:00
|
|
|
:working-directory \"/home/user/org/Worg/\")
|
2020-05-09 16:31:04 -04:00
|
|
|
(\"localhost org-notes/\"
|
2009-03-30 09:47:34 -04:00
|
|
|
:online-suffix \".html\"
|
|
|
|
:working-suffix \".org\"
|
|
|
|
:base-url \"http://localhost/org/\"
|
2009-11-15 06:24:40 -05:00
|
|
|
:working-directory \"/home/user/org/\"
|
2017-06-28 10:36:45 -04:00
|
|
|
:rewrites ((\"org/?$\" . \"index.php\")))
|
|
|
|
(\"Hugo based blog\"
|
|
|
|
:base-url \"https://www.site.com/\"
|
|
|
|
:working-directory \"~/site/content/post/\"
|
|
|
|
:online-suffix \".html\"
|
|
|
|
:working-suffix \".md\"
|
2020-12-19 11:26:58 -05:00
|
|
|
:rewrites ((\"\\(https://site.com/[0-9]+/[0-9]+/[0-9]+/\\)\"
|
|
|
|
. \".md\")))
|
2020-05-09 16:31:04 -04:00
|
|
|
(\"GNU emacs OpenGrok\"
|
|
|
|
:base-url \"https://opengrok.housegordon.com/source/xref/emacs/\"
|
|
|
|
:working-directory \"~/dev/gnu-emacs/\")))
|
|
|
|
|
|
|
|
The :rewrites line of \"localhost org-notes\" entry tells
|
|
|
|
`org-protocol-open-source' to open /home/user/org/index.php,
|
|
|
|
if the URL cannot be mapped to an existing file, and ends with
|
|
|
|
either \"org\" or \"org/\". The \"GNU emacs OpenGrok\" entry
|
|
|
|
does not include any suffix properties, allowing local source
|
|
|
|
file to be opened as found by OpenGrok.
|
2009-03-30 09:47:34 -04:00
|
|
|
|
2021-09-24 08:46:56 -04:00
|
|
|
Consider using the interactive functions `org-protocol-create'
|
|
|
|
and `org-protocol-create-for-org' to help you filling this
|
|
|
|
variable with valid contents."
|
2009-03-30 09:47:34 -04:00
|
|
|
:type 'alist)
|
|
|
|
|
|
|
|
(defcustom org-protocol-protocol-alist nil
|
2012-04-21 10:03:20 -04:00
|
|
|
"Register custom handlers for org-protocol.
|
2009-03-30 09:47:34 -04:00
|
|
|
|
|
|
|
Each element of this list must be of the form:
|
|
|
|
|
2009-04-03 11:36:44 -04:00
|
|
|
(module-name :protocol protocol :function func :kill-client nil)
|
2009-03-30 09:47:34 -04:00
|
|
|
|
2015-12-02 10:53:07 -05:00
|
|
|
protocol - protocol to detect in a filename without trailing
|
|
|
|
colon and slashes. See rfc1738 section 2.1 for more
|
|
|
|
on this. If you define a protocol \"my-protocol\",
|
|
|
|
`org-protocol-check-filename-for-protocol' will search
|
|
|
|
filenames for \"org-protocol:/my-protocol\" and
|
|
|
|
trigger your action for every match. `org-protocol'
|
|
|
|
is defined in `org-protocol-the-protocol'. Double and
|
|
|
|
triple slashes are compressed to one by emacsclient.
|
|
|
|
|
|
|
|
function - function that handles requests with protocol and takes
|
|
|
|
one argument. If a new-style link (key=val&key2=val2)
|
|
|
|
is given, the argument will be a property list with
|
|
|
|
the values from the link. If an old-style link is
|
|
|
|
given (val1/val2), the argument will be the filename
|
|
|
|
with all protocols stripped.
|
|
|
|
|
|
|
|
If the function returns nil, emacsclient and -server
|
|
|
|
do nothing. Any non-nil return value is considered a
|
|
|
|
valid filename and thus passed to the server.
|
|
|
|
|
|
|
|
`org-protocol.el' provides some support for handling
|
|
|
|
old-style filenames, if you follow the conventions
|
|
|
|
used for the standard handlers in
|
|
|
|
`org-protocol-protocol-alist-default'. See
|
|
|
|
`org-protocol-parse-parameters'.
|
2009-03-30 09:47:34 -04:00
|
|
|
|
2009-04-03 11:36:44 -04:00
|
|
|
kill-client - If t, kill the client immediately, once the sub-protocol is
|
2012-08-11 13:10:44 -04:00
|
|
|
detected. This is necessary for actions that can be interrupted by
|
2015-12-02 10:53:07 -05:00
|
|
|
`C-g' to avoid dangling emacsclients. Note that all other command
|
|
|
|
line arguments but the this one will be discarded. Greedy handlers
|
2009-04-03 11:36:44 -04:00
|
|
|
still receive the whole list of arguments though.
|
|
|
|
|
2009-03-30 09:47:34 -04:00
|
|
|
Here is an example:
|
|
|
|
|
|
|
|
(setq org-protocol-protocol-alist
|
2015-09-21 00:23:36 -04:00
|
|
|
\\='((\"my-protocol\"
|
2009-03-30 09:47:34 -04:00
|
|
|
:protocol \"my-protocol\"
|
2010-07-16 17:23:01 -04:00
|
|
|
:function my-protocol-handler-function)
|
2009-03-30 09:47:34 -04:00
|
|
|
(\"your-protocol\"
|
|
|
|
:protocol \"your-protocol\"
|
2010-07-16 17:23:01 -04:00
|
|
|
:function your-protocol-handler-function)))"
|
2009-03-30 09:47:34 -04:00
|
|
|
:type '(alist))
|
|
|
|
|
2010-09-01 01:15:48 -04:00
|
|
|
(defcustom org-protocol-default-template-key nil
|
2011-03-23 05:25:38 -04:00
|
|
|
"The default template key to use.
|
|
|
|
This is usually a single character string but can also be a
|
|
|
|
string with two characters."
|
2013-05-09 09:19:02 -04:00
|
|
|
:type '(choice (const nil) (string)))
|
2009-07-27 18:02:10 -04:00
|
|
|
|
2013-03-03 19:13:34 -05:00
|
|
|
(defcustom org-protocol-data-separator "/+\\|\\?"
|
2012-04-14 19:07:48 -04:00
|
|
|
"The default data separator to use.
|
2015-12-02 10:53:07 -05:00
|
|
|
This should be a single regexp string."
|
2013-03-03 19:13:34 -05:00
|
|
|
:version "24.4"
|
|
|
|
:package-version '(Org . "8.0")
|
2019-12-21 12:52:06 -05:00
|
|
|
:type 'regexp)
|
2012-04-14 19:07:48 -04:00
|
|
|
|
2009-03-30 09:47:34 -04:00
|
|
|
;;; Helper functions:
|
|
|
|
|
|
|
|
(defun org-protocol-sanitize-uri (uri)
|
2015-12-02 10:53:07 -05:00
|
|
|
"Sanitize slashes to double-slashes in URI.
|
|
|
|
Emacsclient compresses double and triple slashes."
|
2009-03-30 09:47:34 -04:00
|
|
|
(when (string-match "^\\([a-z]+\\):/" uri)
|
|
|
|
(let* ((splitparts (split-string uri "/+")))
|
Replace all uses of the old `defadvice` with the new `advice-add`
* lisp/org.el (org-run-like-in-org-mode): Strength reduce `eval`
to `cl-progv`.
(org--check-org-structure-template-alist): Strength reduce `eval`
to `symbol-value`.
(org-map-entries, org-eval-in-calendar, org-diary-sexp-entry):
Make sure we use the new lexically scoped dialect.
(org--math-always-on): New function, extracted from advice.
(org-cdlatex-mode): Use it with `advice-add`.
(org-self-insert-command): Simplify `and`+`listp` into `consp`.
(org-submit-bug-report):
Make sure we use the new lexically scoped dialect.
* lisp/org-protocol.el (org-protocol-convert-query-to-plist):
Use `cl-mapcan`.
(org--protocol-detect-protocol-server): New function, extracted
from advice.
(server-visit-files): Use it with `advice-add`.
* lisp/org-mouse.el (org--mouse-dnd-insert-text): New function, extracted
from advice.
(dnd-insert-text): Use it with `advice-add`.
(org--mouse-dnd-open-file): New function, extracted from advice.
(dnd-open-file): Use it with `advice-add`.
(org--mouse-open-at-point): New function, extracted from advice.
(org-mode-hook): Advise `org-open-at-point` with `advice-add`.
* lisp/org-ctags.el (org--ctags-load-tag-list): New function, extracted
from advice.
(visit-tags-table): Use it with `advice-add`.
(org--ctags-set-org-mark-before-finding-tag): New function, extracted
from advice.
(xref-find-definitions): Use it with `advice-add`.
* lisp/org-compat.el (org-bookmark-jump-unhide): Accept (unused) args.
(save-place-find-file-hook): Use `advice-add`.
(org--ecb-show-context): New function, extracted from advice.
(ecb-method-clicked): Use it with `advice-add`.
(org-mark-jump-unhide): Accept (unused) args.
(pop-to-mark-command, exchange-point-and-mark, pop-global-mark):
Use `advice-add`.
Along the way, remove some redundant `:group` args
(redundant because they specify the same group as would be used by
default anyway) and make a few other simplifications.
Also don't bother putting `advice-add` within an eval-after-load
since the advice machinery already takes care of handling it.
2022-04-01 01:50:01 -04:00
|
|
|
(setq uri (concat (car splitparts) "//"
|
|
|
|
(mapconcat #'identity (cdr splitparts) "/")))))
|
2009-03-30 09:47:34 -04:00
|
|
|
uri)
|
|
|
|
|
2011-03-23 05:14:03 -04:00
|
|
|
(defun org-protocol-split-data (data &optional unhexify separator)
|
2015-12-02 10:53:07 -05:00
|
|
|
"Split the DATA argument for an org-protocol handler function.
|
|
|
|
If UNHEXIFY is non-nil, hex-decode each split part. If UNHEXIFY
|
|
|
|
is a function, use that function to decode each split part. The
|
|
|
|
string is split at each occurrence of SEPARATOR (regexp). If no
|
|
|
|
SEPARATOR is specified or SEPARATOR is nil, assume \"/+\". The
|
|
|
|
results of that splitting are returned as a list."
|
2013-03-03 19:13:34 -05:00
|
|
|
(let* ((sep (or separator "/+\\|\\?"))
|
2009-03-30 09:47:34 -04:00
|
|
|
(split-parts (split-string data sep)))
|
2019-02-27 14:22:51 -05:00
|
|
|
(cond ((not unhexify) split-parts)
|
|
|
|
((fboundp unhexify) (mapcar unhexify split-parts))
|
2019-03-09 04:58:41 -05:00
|
|
|
(t (mapcar #'org-link-decode split-parts)))))
|
2009-03-30 09:47:34 -04:00
|
|
|
|
2009-04-04 17:33:24 -04:00
|
|
|
(defun org-protocol-flatten-greedy (param-list &optional strip-path replacement)
|
2015-12-02 10:53:07 -05:00
|
|
|
"Transform PARAM-LIST into a flat list for greedy handlers.
|
|
|
|
|
|
|
|
Greedy handlers might receive a list like this from emacsclient:
|
|
|
|
\((\"/dir/org-protocol:/greedy:/~/path1\" (23 . 12)) (\"/dir/param\"))
|
|
|
|
where \"/dir/\" is the absolute path to emacsclient's working directory. This
|
2023-07-05 11:50:44 -04:00
|
|
|
function transforms it into a flat list using `flatten-tree' and
|
2009-04-04 17:33:24 -04:00
|
|
|
transforms the elements of that list as follows:
|
|
|
|
|
2015-12-02 10:53:07 -05:00
|
|
|
If STRIP-PATH is non-nil, remove the \"/dir/\" prefix from all members of
|
2009-04-04 17:33:24 -04:00
|
|
|
param-list.
|
|
|
|
|
2015-12-02 10:53:07 -05:00
|
|
|
If REPLACEMENT is string, replace the \"/dir/\" prefix with it.
|
2009-04-04 17:33:24 -04:00
|
|
|
|
|
|
|
The first parameter, the one that contains the protocols, is always changed.
|
|
|
|
Everything up to the end of the protocols is stripped.
|
|
|
|
|
2009-04-05 09:28:31 -04:00
|
|
|
Note, that this function will always behave as if
|
|
|
|
`org-protocol-reverse-list-of-files' was set to t and the returned list will
|
2015-12-02 10:53:07 -05:00
|
|
|
reflect that. emacsclient's first parameter will be the first one in the
|
2009-04-05 09:28:31 -04:00
|
|
|
returned list."
|
2023-07-05 11:50:44 -04:00
|
|
|
(let* ((l (org--flatten-tree (if org-protocol-reverse-list-of-files
|
|
|
|
param-list
|
|
|
|
(reverse param-list))))
|
2012-08-11 13:10:44 -04:00
|
|
|
(trigger (car l))
|
|
|
|
(len 0)
|
|
|
|
dir
|
|
|
|
ret)
|
2019-03-04 21:00:00 -05:00
|
|
|
(when (string-match "^\\(.*\\)\\(org-protocol:/+[a-zA-Z0-9][-_a-zA-Z0-9]*:/+\\)\\(.*\\)" trigger)
|
2012-08-11 13:10:44 -04:00
|
|
|
(setq dir (match-string 1 trigger))
|
|
|
|
(setq len (length dir))
|
|
|
|
(setcar l (concat dir (match-string 3 trigger))))
|
|
|
|
(if strip-path
|
|
|
|
(progn
|
|
|
|
(dolist (e l ret)
|
|
|
|
(setq ret
|
|
|
|
(append ret
|
|
|
|
(list
|
|
|
|
(if (stringp e)
|
|
|
|
(if (stringp replacement)
|
|
|
|
(setq e (concat replacement (substring e len)))
|
|
|
|
(setq e (substring e len)))
|
|
|
|
e)))))
|
|
|
|
ret)
|
|
|
|
l)))
|
2009-04-04 17:33:24 -04:00
|
|
|
|
2023-07-05 11:50:44 -04:00
|
|
|
(define-obsolete-function-alias 'org-protocol-flatten
|
|
|
|
(if (fboundp 'flatten-tree) 'flatten-tree 'org--flatten-tree)
|
|
|
|
"9.7"
|
|
|
|
"Transform LIST into a flat list.
|
2015-12-02 10:53:07 -05:00
|
|
|
|
|
|
|
Greedy handlers might receive a list like this from emacsclient:
|
|
|
|
\((\"/dir/org-protocol:/greedy:/~/path1\" (23 . 12)) (\"/dir/param\"))
|
2010-04-15 06:24:55 -04:00
|
|
|
where \"/dir/\" is the absolute path to emacsclients working directory.
|
2023-07-05 11:50:44 -04:00
|
|
|
This function transforms it into a flat list.")
|
2015-12-02 10:53:07 -05:00
|
|
|
|
|
|
|
(defun org-protocol-parse-parameters (info &optional new-style default-order)
|
|
|
|
"Return a property list of parameters from INFO.
|
|
|
|
If NEW-STYLE is non-nil, treat INFO as a query string (ex:
|
|
|
|
url=URL&title=TITLE). If old-style links are used (ex:
|
|
|
|
org-protocol://store-link/url/title), assign them to attributes
|
|
|
|
following DEFAULT-ORDER.
|
|
|
|
|
|
|
|
If no DEFAULT-ORDER is specified, return the list of values.
|
|
|
|
|
|
|
|
If INFO is already a property list, return it unchanged."
|
|
|
|
(if (listp info)
|
|
|
|
info
|
|
|
|
(if new-style
|
|
|
|
(let ((data (org-protocol-convert-query-to-plist info))
|
|
|
|
result)
|
|
|
|
(while data
|
|
|
|
(setq result
|
2019-02-27 14:22:51 -05:00
|
|
|
(append result
|
2019-03-09 04:58:41 -05:00
|
|
|
(list (pop data) (org-link-decode (pop data))))))
|
2015-12-02 10:53:07 -05:00
|
|
|
result)
|
|
|
|
(let ((data (org-protocol-split-data info t org-protocol-data-separator)))
|
|
|
|
(if default-order
|
|
|
|
(org-protocol-assign-parameters data default-order)
|
|
|
|
data)))))
|
|
|
|
|
|
|
|
(defun org-protocol-assign-parameters (data default-order)
|
|
|
|
"Return a property list of parameters from DATA.
|
|
|
|
Key names are taken from DEFAULT-ORDER, which should be a list of
|
|
|
|
symbols. If DEFAULT-ORDER is shorter than the number of values
|
|
|
|
specified, the rest of the values are treated as :key value pairs."
|
|
|
|
(let (result)
|
|
|
|
(while default-order
|
|
|
|
(setq result
|
|
|
|
(append result
|
|
|
|
(list (pop default-order)
|
|
|
|
(pop data)))))
|
|
|
|
(while data
|
|
|
|
(setq result
|
|
|
|
(append result
|
|
|
|
(list (intern (concat ":" (pop data)))
|
|
|
|
(pop data)))))
|
|
|
|
result))
|
2011-03-23 05:14:03 -04:00
|
|
|
|
2009-03-30 09:47:34 -04:00
|
|
|
;;; Standard protocol handlers:
|
|
|
|
|
|
|
|
(defun org-protocol-store-link (fname)
|
2015-12-02 10:53:07 -05:00
|
|
|
"Process an org-protocol://store-link style url.
|
2012-08-11 13:10:44 -04:00
|
|
|
Additionally store a browser URL as an org link. Also pushes the
|
2010-07-16 17:23:01 -04:00
|
|
|
link's URL to the `kill-ring'.
|
2009-03-30 09:47:34 -04:00
|
|
|
|
2015-12-02 10:53:07 -05:00
|
|
|
Parameters: url, title (optional), body (optional)
|
|
|
|
|
|
|
|
Old-style links such as org-protocol://store-link://URL/TITLE are
|
|
|
|
also recognized.
|
|
|
|
|
2021-04-06 10:30:06 -04:00
|
|
|
The location for a browser's bookmark may look like this:
|
|
|
|
|
|
|
|
javascript:location.href = \\='org-protocol://store-link?\\=' +
|
|
|
|
new URLSearchParams({url:location.href, title:document.title});
|
|
|
|
|
|
|
|
or to keep compatibility with Org versions from 9.0 to 9.4 it may be:
|
2009-03-30 09:47:34 -04:00
|
|
|
|
2015-12-02 10:53:07 -05:00
|
|
|
javascript:location.href = \\
|
|
|
|
\\='org-protocol://store-link?url=\\=' + \\
|
|
|
|
encodeURIComponent(location.href) + \\='&title=\\=' + \\
|
|
|
|
encodeURIComponent(document.title);
|
2009-03-30 09:47:34 -04:00
|
|
|
|
2015-12-02 10:53:07 -05:00
|
|
|
Don't use `escape()'! Use `encodeURIComponent()' instead. The
|
|
|
|
title of the page could contain slashes and the location
|
2021-04-06 10:30:06 -04:00
|
|
|
definitely will. Org 9.4 and earlier could not decode \"+\"
|
|
|
|
to space, that is why less readable latter expression may be necessary
|
|
|
|
for backward compatibility.
|
2009-03-30 09:47:34 -04:00
|
|
|
|
|
|
|
The sub-protocol used to reach this function is set in
|
2015-12-02 10:53:07 -05:00
|
|
|
`org-protocol-protocol-alist'.
|
|
|
|
|
|
|
|
FNAME should be a property list. If not, an old-style link of the
|
|
|
|
form URL/TITLE can also be used."
|
|
|
|
(let* ((splitparts (org-protocol-parse-parameters fname nil '(:url :title)))
|
|
|
|
(uri (org-protocol-sanitize-uri (plist-get splitparts :url)))
|
2016-06-21 17:23:18 -04:00
|
|
|
(title (plist-get splitparts :title)))
|
|
|
|
(when (boundp 'org-stored-links)
|
|
|
|
(push (list uri title) org-stored-links))
|
2009-03-30 09:47:34 -04:00
|
|
|
(kill-new uri)
|
2019-02-27 05:06:19 -05:00
|
|
|
(message "`%s' to insert new Org link, `%s' to insert %S"
|
|
|
|
(substitute-command-keys "\\[org-insert-link]")
|
|
|
|
(substitute-command-keys "\\[yank]")
|
2009-03-30 09:47:34 -04:00
|
|
|
uri))
|
|
|
|
nil)
|
|
|
|
|
2011-03-23 05:14:03 -04:00
|
|
|
(defun org-protocol-capture (info)
|
2015-12-02 10:53:07 -05:00
|
|
|
"Process an org-protocol://capture style url with INFO.
|
2010-06-22 10:20:13 -04:00
|
|
|
|
2009-03-30 09:47:34 -04:00
|
|
|
The sub-protocol used to reach this function is set in
|
|
|
|
`org-protocol-protocol-alist'.
|
|
|
|
|
2013-02-27 18:24:46 -05:00
|
|
|
This function detects an URL, title and optional text, separated
|
2015-09-21 00:23:36 -04:00
|
|
|
by `/'. The location for a browser's bookmark looks like this:
|
2009-03-30 09:47:34 -04:00
|
|
|
|
2021-04-06 10:30:06 -04:00
|
|
|
javascript:location.href = \\='org-protocol://capture?\\=' +
|
|
|
|
new URLSearchParams({
|
|
|
|
url: location.href,
|
|
|
|
title: document.title,
|
|
|
|
body: window.getSelection()})
|
|
|
|
|
|
|
|
or to keep compatibility with Org versions from 9.0 to 9.4:
|
|
|
|
|
2015-12-02 10:53:07 -05:00
|
|
|
javascript:location.href = \\='org-protocol://capture?url=\\='+ \\
|
2021-04-19 06:53:16 -04:00
|
|
|
encodeURIComponent(location.href) + \\='&title=\\=' + \\
|
2015-12-02 10:53:07 -05:00
|
|
|
encodeURIComponent(document.title) + \\='&body=\\=' + \\
|
2009-03-30 09:47:34 -04:00
|
|
|
encodeURIComponent(window.getSelection())
|
|
|
|
|
2009-07-27 18:02:10 -04:00
|
|
|
By default, it uses the character `org-protocol-default-template-key',
|
2010-06-22 10:20:13 -04:00
|
|
|
which should be associated with a template in `org-capture-templates'.
|
2015-12-02 10:53:07 -05:00
|
|
|
You may specify the template with a template= query parameter, like this:
|
2009-03-30 09:47:34 -04:00
|
|
|
|
2015-12-02 10:53:07 -05:00
|
|
|
javascript:location.href = \\='org-protocol://capture?template=b\\='+ ...
|
2009-03-30 09:47:34 -04:00
|
|
|
|
|
|
|
Now template ?b will be used."
|
2018-12-18 03:30:32 -05:00
|
|
|
(let* ((parts
|
|
|
|
(pcase (org-protocol-parse-parameters info)
|
|
|
|
;; New style links are parsed as a plist.
|
|
|
|
((let `(,(pred keywordp) . ,_) info) info)
|
|
|
|
;; Old style links, with or without template key, are
|
|
|
|
;; parsed as a list of strings.
|
|
|
|
(p
|
|
|
|
(let ((k (if (= 1 (length (car p)))
|
|
|
|
'(:template :url :title :body)
|
|
|
|
'(:url :title :body))))
|
|
|
|
(org-protocol-assign-parameters p k)))))
|
2015-12-02 10:53:07 -05:00
|
|
|
(template (or (plist-get parts :template)
|
2010-06-22 10:20:13 -04:00
|
|
|
org-protocol-default-template-key))
|
2018-12-18 03:30:32 -05:00
|
|
|
(url (and (plist-get parts :url)
|
|
|
|
(org-protocol-sanitize-uri (plist-get parts :url))))
|
|
|
|
(type (and url
|
|
|
|
(string-match "^\\([a-z]+\\):" url)
|
|
|
|
(match-string 1 url)))
|
2015-12-02 10:53:07 -05:00
|
|
|
(title (or (plist-get parts :title) ""))
|
|
|
|
(region (or (plist-get parts :body) ""))
|
2018-12-18 03:30:32 -05:00
|
|
|
(orglink
|
|
|
|
(if (null url) title
|
2018-11-26 18:04:41 -05:00
|
|
|
(org-link-make-string url (or (org-string-nw-p title) url))))
|
2018-12-18 03:30:32 -05:00
|
|
|
;; Avoid call to `org-store-link'.
|
|
|
|
(org-capture-link-is-already-stored t))
|
|
|
|
;; Only store link if there's a URL to insert later on.
|
|
|
|
(when url (push (list url title) org-stored-links))
|
2018-11-26 18:04:41 -05:00
|
|
|
(org-link-store-props :type type
|
2010-06-22 10:20:13 -04:00
|
|
|
:link url
|
|
|
|
:description title
|
2010-06-23 10:21:22 -04:00
|
|
|
:annotation orglink
|
2013-03-03 19:13:34 -05:00
|
|
|
:initial region
|
2015-12-02 10:53:07 -05:00
|
|
|
:query parts)
|
2010-06-22 10:20:13 -04:00
|
|
|
(raise-frame)
|
2018-12-18 17:00:11 -05:00
|
|
|
(org-capture nil template)
|
|
|
|
(message "Item captured.")
|
|
|
|
;; Make sure we do not return a string, as `server-visit-files',
|
|
|
|
;; through `server-edit', would interpret it as a file name.
|
|
|
|
nil))
|
2018-12-18 03:30:32 -05:00
|
|
|
|
|
|
|
(defun org-protocol-convert-query-to-plist (query)
|
|
|
|
"Convert QUERY key=value pairs in the URL to a property list."
|
|
|
|
(when query
|
2021-04-06 10:30:06 -04:00
|
|
|
(let ((plus-decoded (replace-regexp-in-string "\\+" " " query t t)))
|
Replace all uses of the old `defadvice` with the new `advice-add`
* lisp/org.el (org-run-like-in-org-mode): Strength reduce `eval`
to `cl-progv`.
(org--check-org-structure-template-alist): Strength reduce `eval`
to `symbol-value`.
(org-map-entries, org-eval-in-calendar, org-diary-sexp-entry):
Make sure we use the new lexically scoped dialect.
(org--math-always-on): New function, extracted from advice.
(org-cdlatex-mode): Use it with `advice-add`.
(org-self-insert-command): Simplify `and`+`listp` into `consp`.
(org-submit-bug-report):
Make sure we use the new lexically scoped dialect.
* lisp/org-protocol.el (org-protocol-convert-query-to-plist):
Use `cl-mapcan`.
(org--protocol-detect-protocol-server): New function, extracted
from advice.
(server-visit-files): Use it with `advice-add`.
* lisp/org-mouse.el (org--mouse-dnd-insert-text): New function, extracted
from advice.
(dnd-insert-text): Use it with `advice-add`.
(org--mouse-dnd-open-file): New function, extracted from advice.
(dnd-open-file): Use it with `advice-add`.
(org--mouse-open-at-point): New function, extracted from advice.
(org-mode-hook): Advise `org-open-at-point` with `advice-add`.
* lisp/org-ctags.el (org--ctags-load-tag-list): New function, extracted
from advice.
(visit-tags-table): Use it with `advice-add`.
(org--ctags-set-org-mark-before-finding-tag): New function, extracted
from advice.
(xref-find-definitions): Use it with `advice-add`.
* lisp/org-compat.el (org-bookmark-jump-unhide): Accept (unused) args.
(save-place-find-file-hook): Use `advice-add`.
(org--ecb-show-context): New function, extracted from advice.
(ecb-method-clicked): Use it with `advice-add`.
(org-mark-jump-unhide): Accept (unused) args.
(pop-to-mark-command, exchange-point-and-mark, pop-global-mark):
Use `advice-add`.
Along the way, remove some redundant `:group` args
(redundant because they specify the same group as would be used by
default anyway) and make a few other simplifications.
Also don't bother putting `advice-add` within an eval-after-load
since the advice machinery already takes care of handling it.
2022-04-01 01:50:01 -04:00
|
|
|
(cl-mapcan (lambda (x)
|
|
|
|
(let ((c (split-string x "=")))
|
|
|
|
(list (intern (concat ":" (car c))) (cadr c))))
|
|
|
|
(split-string plus-decoded "&")))))
|
2010-06-22 10:20:13 -04:00
|
|
|
|
2009-03-30 09:47:34 -04:00
|
|
|
(defun org-protocol-open-source (fname)
|
2015-12-02 10:53:07 -05:00
|
|
|
"Process an org-protocol://open-source?url= style URL with FNAME.
|
2009-03-30 09:47:34 -04:00
|
|
|
|
|
|
|
Change a filename by mapping URLs to local filenames as set
|
|
|
|
in `org-protocol-project-alist'.
|
|
|
|
|
|
|
|
The location for a browser's bookmark should look like this:
|
|
|
|
|
2021-04-06 10:30:06 -04:00
|
|
|
javascript:location.href = \\='org-protocol://open-source?\\=' +
|
|
|
|
new URLSearchParams({url: location.href})
|
|
|
|
|
|
|
|
or if you prefer to keep compatibility with older Org versions (9.0 to 9.4),
|
|
|
|
consider the following expression:
|
|
|
|
|
2015-12-02 10:53:07 -05:00
|
|
|
javascript:location.href = \\='org-protocol://open-source?url=\\=' + \\
|
2009-03-30 09:47:34 -04:00
|
|
|
encodeURIComponent(location.href)"
|
|
|
|
;; As we enter this function for a match on our protocol, the return value
|
|
|
|
;; defaults to nil.
|
2021-03-11 13:07:37 -05:00
|
|
|
(let (;; (result nil)
|
2017-06-23 12:32:49 -04:00
|
|
|
(f (org-protocol-sanitize-uri
|
|
|
|
(plist-get (org-protocol-parse-parameters fname nil '(:url))
|
|
|
|
:url))))
|
2009-03-30 09:47:34 -04:00
|
|
|
(catch 'result
|
|
|
|
(dolist (prolist org-protocol-project-alist)
|
|
|
|
(let* ((base-url (plist-get (cdr prolist) :base-url))
|
|
|
|
(wsearch (regexp-quote base-url)))
|
|
|
|
|
|
|
|
(when (string-match wsearch f)
|
|
|
|
(let* ((wdir (plist-get (cdr prolist) :working-directory))
|
|
|
|
(strip-suffix (plist-get (cdr prolist) :online-suffix))
|
|
|
|
(add-suffix (plist-get (cdr prolist) :working-suffix))
|
2009-11-15 06:24:40 -05:00
|
|
|
;; Strip "[?#].*$" if `f' is a redirect with another
|
|
|
|
;; ending than strip-suffix here:
|
|
|
|
(f1 (substring f 0 (string-match "\\([\\?#].*\\)?$" f)))
|
|
|
|
(start-pos (+ (string-match wsearch f1) (length base-url)))
|
2020-05-09 16:31:04 -04:00
|
|
|
(end-pos (if strip-suffix
|
2021-09-29 03:22:47 -04:00
|
|
|
(string-match (regexp-quote strip-suffix) f1)
|
2020-05-09 16:31:04 -04:00
|
|
|
(length f1)))
|
2009-11-15 06:24:40 -05:00
|
|
|
;; We have to compare redirects without suffix below:
|
|
|
|
(f2 (concat wdir (substring f1 start-pos end-pos)))
|
2020-05-09 16:31:04 -04:00
|
|
|
(the-file (if add-suffix (concat f2 add-suffix) f2)))
|
2009-11-15 06:24:40 -05:00
|
|
|
|
|
|
|
;; Note: the-file may still contain `%C3' et al here because browsers
|
|
|
|
;; tend to encode `ä' in URLs to `%25C3' - `%25' being `%'.
|
|
|
|
;; So the results may vary.
|
|
|
|
|
|
|
|
;; -- start redirects --
|
|
|
|
(unless (file-exists-p the-file)
|
|
|
|
(message "File %s does not exist.\nTesting for rewritten URLs." the-file)
|
|
|
|
(let ((rewrites (plist-get (cdr prolist) :rewrites)))
|
|
|
|
(when rewrites
|
|
|
|
(message "Rewrites found: %S" rewrites)
|
2016-06-21 17:23:18 -04:00
|
|
|
(dolist (rewrite rewrites)
|
|
|
|
;; Try to match a rewritten URL and map it to
|
|
|
|
;; a real file. Compare redirects without
|
|
|
|
;; suffix.
|
2017-06-28 10:36:45 -04:00
|
|
|
(when (string-match (car rewrite) f1)
|
|
|
|
(let ((replacement
|
|
|
|
(concat (directory-file-name
|
|
|
|
(replace-match "" nil nil f1 1))
|
|
|
|
(cdr rewrite))))
|
|
|
|
(throw 'result (concat wdir replacement))))))))
|
2009-11-15 06:24:40 -05:00
|
|
|
;; -- end of redirects --
|
|
|
|
|
2009-03-30 09:47:34 -04:00
|
|
|
(if (file-readable-p the-file)
|
|
|
|
(throw 'result the-file))
|
|
|
|
(if (file-exists-p the-file)
|
|
|
|
(message "%s: permission denied!" the-file)
|
|
|
|
(message "%s: no such file or directory." the-file))))))
|
2021-03-11 13:07:37 -05:00
|
|
|
nil))) ;; FIXME: Really?
|
2009-03-30 09:47:34 -04:00
|
|
|
|
|
|
|
|
|
|
|
;;; Core functions:
|
|
|
|
|
2016-06-21 17:23:18 -04:00
|
|
|
(defun org-protocol-check-filename-for-protocol (fname restoffiles _client)
|
2015-12-02 10:53:07 -05:00
|
|
|
"Check if `org-protocol-the-protocol' and a valid protocol are used in FNAME.
|
2009-03-30 09:47:34 -04:00
|
|
|
Sub-protocols are registered in `org-protocol-protocol-alist' and
|
2015-12-02 10:53:07 -05:00
|
|
|
`org-protocol-protocol-alist-default'. This is how the matching is done:
|
2009-03-30 09:47:34 -04:00
|
|
|
|
2015-12-02 10:53:07 -05:00
|
|
|
(string-match \"protocol:/+sub-protocol\\\\(://\\\\|\\\\?\\\\)\" ...)
|
2009-03-30 09:47:34 -04:00
|
|
|
|
|
|
|
protocol and sub-protocol are regexp-quoted.
|
|
|
|
|
2015-12-02 10:53:07 -05:00
|
|
|
Old-style links such as \"protocol://sub-protocol://param1/param2\" are
|
|
|
|
also recognized.
|
|
|
|
|
|
|
|
If a matching protocol is found, the protocol is stripped from
|
Replace all uses of the old `defadvice` with the new `advice-add`
* lisp/org.el (org-run-like-in-org-mode): Strength reduce `eval`
to `cl-progv`.
(org--check-org-structure-template-alist): Strength reduce `eval`
to `symbol-value`.
(org-map-entries, org-eval-in-calendar, org-diary-sexp-entry):
Make sure we use the new lexically scoped dialect.
(org--math-always-on): New function, extracted from advice.
(org-cdlatex-mode): Use it with `advice-add`.
(org-self-insert-command): Simplify `and`+`listp` into `consp`.
(org-submit-bug-report):
Make sure we use the new lexically scoped dialect.
* lisp/org-protocol.el (org-protocol-convert-query-to-plist):
Use `cl-mapcan`.
(org--protocol-detect-protocol-server): New function, extracted
from advice.
(server-visit-files): Use it with `advice-add`.
* lisp/org-mouse.el (org--mouse-dnd-insert-text): New function, extracted
from advice.
(dnd-insert-text): Use it with `advice-add`.
(org--mouse-dnd-open-file): New function, extracted from advice.
(dnd-open-file): Use it with `advice-add`.
(org--mouse-open-at-point): New function, extracted from advice.
(org-mode-hook): Advise `org-open-at-point` with `advice-add`.
* lisp/org-ctags.el (org--ctags-load-tag-list): New function, extracted
from advice.
(visit-tags-table): Use it with `advice-add`.
(org--ctags-set-org-mark-before-finding-tag): New function, extracted
from advice.
(xref-find-definitions): Use it with `advice-add`.
* lisp/org-compat.el (org-bookmark-jump-unhide): Accept (unused) args.
(save-place-find-file-hook): Use `advice-add`.
(org--ecb-show-context): New function, extracted from advice.
(ecb-method-clicked): Use it with `advice-add`.
(org-mark-jump-unhide): Accept (unused) args.
(pop-to-mark-command, exchange-point-and-mark, pop-global-mark):
Use `advice-add`.
Along the way, remove some redundant `:group` args
(redundant because they specify the same group as would be used by
default anyway) and make a few other simplifications.
Also don't bother putting `advice-add` within an eval-after-load
since the advice machinery already takes care of handling it.
2022-04-01 01:50:01 -04:00
|
|
|
FNAME and the result is passed to the protocol function as the
|
2015-12-02 10:53:07 -05:00
|
|
|
first parameter. The second parameter will be non-nil if FNAME
|
|
|
|
uses key=val&key2=val2-type arguments, or nil if FNAME uses
|
|
|
|
val/val2-type arguments. If the function returns nil, the
|
|
|
|
filename is removed from the list of filenames passed from
|
|
|
|
emacsclient to the server. If the function returns a non-nil
|
|
|
|
value, that value is passed to the server as filename.
|
|
|
|
|
|
|
|
If the handler function is greedy, RESTOFFILES will also be passed to it.
|
|
|
|
|
|
|
|
CLIENT is ignored."
|
2011-03-23 05:14:03 -04:00
|
|
|
(let ((sub-protocols (append org-protocol-protocol-alist
|
|
|
|
org-protocol-protocol-alist-default)))
|
2009-03-30 09:47:34 -04:00
|
|
|
(catch 'fname
|
2017-04-17 05:03:47 -04:00
|
|
|
(let ((the-protocol (concat (regexp-quote org-protocol-the-protocol)
|
|
|
|
":/+")))
|
2009-03-30 09:47:34 -04:00
|
|
|
(when (string-match the-protocol fname)
|
|
|
|
(dolist (prolist sub-protocols)
|
2017-04-17 05:03:47 -04:00
|
|
|
(let ((proto
|
|
|
|
(concat the-protocol
|
|
|
|
(regexp-quote (plist-get (cdr prolist) :protocol))
|
2020-04-03 13:12:01 -04:00
|
|
|
"\\(:/+\\|/*\\?\\)")))
|
2009-03-30 09:47:34 -04:00
|
|
|
(when (string-match proto fname)
|
|
|
|
(let* ((func (plist-get (cdr prolist) :function))
|
|
|
|
(greedy (plist-get (cdr prolist) :greedy))
|
2011-12-15 03:37:30 -05:00
|
|
|
(split (split-string fname proto))
|
2015-12-02 10:53:07 -05:00
|
|
|
(result (if greedy restoffiles (cadr split)))
|
2021-04-04 10:44:35 -04:00
|
|
|
(new-style (not (= ?: (aref (match-string 1 fname) 0)))))
|
2009-04-18 14:52:12 -04:00
|
|
|
(when (plist-get (cdr prolist) :kill-client)
|
2012-08-11 13:10:44 -04:00
|
|
|
(message "Greedy org-protocol handler. Killing client.")
|
testing: Make all files use `lexical-binding`
Mainly, add the corresponding cookie, but also add various `require`s
so that the compiler knows which vars should be trated as dynbound.
This does not fix all the warnings, but does try to eliminate
all those about "unused" variables. For the variables truly unused,
the patch usually adds an underscore to their name to silence the warning.
Some of the fixes affect files which already used `lexical-binding`.
Not sure why the test worked before: maybe because the tests were run
without compiling them first (which could cause some of the
missing `require`d packages to be autoloaded before we got to the
problematic code, thus hiding the problem)?
I found some suspicious code, for which I added FIXMEs.
There are also a few changes to the main files.
* lisp/org-protocol.el (org-protocol-check-filename-for-protocol):
Don't call `server-edit` if it's not yet defined. [ Needed to get
the tests to pass. ]
* lisp/ob-core.el (org-babel-temporary-directory)
(org-babel-temporary-stable-directory): Always define (and use nil
if we don't want to create a directory for it). Simplify the code based
on the fact that (defvar V E) only evaluates E if V is not yet `boundp`.
(org-babel-temp-file, org-babel-temp-stable-file)
(org-babel-remove-temporary-directory)
(org-babel-remove-temporary-stable-directory): Adjust accordingly.
* lisp/org.el (org-log-beginning): Add FIXME.
* testing/org-test.el: Require `org` and `org-id`.
(org-id-locations-file): Don't `defconst` it.
(org-test-at-id, org-test-in-example-file, org-test-at-marker)
(org-test-with-temp-text, org-test-with-temp-text-in-file): Move edebug
specs into `declare` (and simplify them).
(org-test-with-tramp-remote-dir--worker): Declare dynbound tramp vars.
(org--compile-when): Fix quoting of `exp`.
(org-test-load): Tweak regexps.
* testing/org-batch-test-init.el: Tweak regexp, remove dead code and
add a FIXME about it.
* testing/lisp/test-ox.el: Require `ox` instead of
erroring out if it's not already loaded. Also require `org-inlinetask`.
(org-test-with-parsed-data): Silence warnings when `info` is not used.
(test-org-export/bind-keyword): Add FIXME.
* testing/lisp/test-ox-publish.el: Require `org-test` and `ox-publish`.
(test-org-publish/resolve-external-link): Expose lambdas to
the compiler. Remove unused var `ids`.
(test-org-publish/get-project-from-filename): Remove unused var `file`.
* testing/lisp/test-org.el: Require `org-macs`, `org`,
`org-inlinetask`, `org-refile`, and `org-agenda`.
(test-org/org-read-date): Declare `org-time-was-given` as dynbound.
(test-org/set-regexps-and-options): Add FIXME.
* testing/lisp/test-org-timer.el: Require `org-timer`.
* testing/lisp/test-org-table.el: Require `ox`.
* testing/lisp/test-org-protocol.el: Require `org-protocol` instead of
erroring out if it's not already loaded. Also require `capture`, and
add missing `provide` statement.
* testing/lisp/test-org-pcomplete.el: Require `org`.
* testing/lisp/test-org-list.el: Require `org-list` and `org`.
* testing/lisp/test-org-lint.el: Require `org-footnote` and `org-lint`.
* testing/lisp/test-org-footnote.el: Require `org-footnote`.
* testing/lisp/test-org-element.el: Require `org-element` instead of
erroring out if it's not already loaded. Also require `org` and
`org-inlinetask`.
* testing/lisp/test-org-duration.el: Require `org-duration`.
* testing/lisp/test-org-datetree.el: Require `org-datetree`.
* testing/lisp/test-org-colview.el: Require `org-colview`,
`org-duration`, and `org-inlinetask`.
* testing/lisp/test-org-clock.el: Require `org-duration` and `org-clock`.
* testing/lisp/test-org-archive.el: Require `org-archive`.
* testing/lisp/test-org-agenda.el
(test-org-agenda/bulk-custom-arg-func): Add FIXME.
* testing/lisp/test-ol.el: Require `ol` and `org-id`.
(test-org-link/store-link): Declare `org-store-link-props` and add FIXME.
* testing/lisp/test-oc.el (test-org-cite/export-capability): Add FIXME.
* testing/lisp/test-ob.el: Require `ob-core`, `org-src`, `ob-ref`,
and `org-table`.
(test-ob/eval-header-argument): Rename `foo` to `test-ob--foo` and
declare it as dynbound.
(test-ob/blocks-with-spaces, test-ob/specific-colnames): Add FIXME.
(test-ob/noweb-expansions-in-cache):
Declare `noweb-expansions-in-cache-var` as dynbound.
* testing/lisp/test-ob-tangle.el: Require `org` and `ob-tangle`.
* testing/lisp/test-ob-shell.el:
* testing/lisp/test-ob-python.el: Require `ob-core`.
* testing/lisp/test-ob-lob.el: Require `ob-lob`.
(temporary-value-for-test): Declare as dynbound.
* testing/lisp/test-ob-plantuml.el: Require `ob-plantuml` instead of
erroring out if it's not already loaded.
* testing/lisp/test-ob-lilypond.el: Require `ob-lilypond` instead of
erroring out if it's not already loaded. Use `with-current-buffer`.
* testing/lisp/test-ob-julia.el: Require `ob-core`.
* testing/lisp/test-ob-java.el (org-babel-temporary-directory):
Remove dead code now that `org-babel-temporary-directory` is always bound.
* testing/lisp/test-ob-exp.el: Require `ob-exp`, `org-src`, and `org-test`.
(ob-exp/evaluate-all-executables-in-order):
Declare `*evaluation-collector*` as dynbound.
* testing/lisp/test-ob-emacs-lisp.el (ob-emacs-lisp/dynamic-lexical-edit)
(ob-emacs-lisp/dynamic-lexical-execute):
Rename dynbound var to `ob-emacs--x` and declare it as such.
* testing/lisp/test-ob-R.el: Require `ob-core`.
(ess-ask-for-ess-directory, ess-history-file): Declare vars.
2022-09-14 17:21:37 -04:00
|
|
|
;; If not fboundp, there's no client to kill.
|
|
|
|
(if (fboundp 'server-edit) (server-edit)))
|
2009-03-30 09:47:34 -04:00
|
|
|
(when (fboundp func)
|
|
|
|
(unless greedy
|
2015-12-02 10:53:07 -05:00
|
|
|
(throw 'fname
|
2017-04-17 05:03:47 -04:00
|
|
|
(if new-style
|
|
|
|
(funcall func (org-protocol-parse-parameters
|
|
|
|
result new-style))
|
|
|
|
(warn "Please update your Org Protocol handler \
|
|
|
|
to deal with new-style links.")
|
|
|
|
(funcall func result))))
|
|
|
|
;; Greedy protocol handlers are responsible for
|
|
|
|
;; parsing their own filenames.
|
2015-12-02 10:53:07 -05:00
|
|
|
(funcall func result)
|
2009-03-30 09:47:34 -04:00
|
|
|
(throw 'fname t))))))))
|
|
|
|
fname)))
|
|
|
|
|
Replace all uses of the old `defadvice` with the new `advice-add`
* lisp/org.el (org-run-like-in-org-mode): Strength reduce `eval`
to `cl-progv`.
(org--check-org-structure-template-alist): Strength reduce `eval`
to `symbol-value`.
(org-map-entries, org-eval-in-calendar, org-diary-sexp-entry):
Make sure we use the new lexically scoped dialect.
(org--math-always-on): New function, extracted from advice.
(org-cdlatex-mode): Use it with `advice-add`.
(org-self-insert-command): Simplify `and`+`listp` into `consp`.
(org-submit-bug-report):
Make sure we use the new lexically scoped dialect.
* lisp/org-protocol.el (org-protocol-convert-query-to-plist):
Use `cl-mapcan`.
(org--protocol-detect-protocol-server): New function, extracted
from advice.
(server-visit-files): Use it with `advice-add`.
* lisp/org-mouse.el (org--mouse-dnd-insert-text): New function, extracted
from advice.
(dnd-insert-text): Use it with `advice-add`.
(org--mouse-dnd-open-file): New function, extracted from advice.
(dnd-open-file): Use it with `advice-add`.
(org--mouse-open-at-point): New function, extracted from advice.
(org-mode-hook): Advise `org-open-at-point` with `advice-add`.
* lisp/org-ctags.el (org--ctags-load-tag-list): New function, extracted
from advice.
(visit-tags-table): Use it with `advice-add`.
(org--ctags-set-org-mark-before-finding-tag): New function, extracted
from advice.
(xref-find-definitions): Use it with `advice-add`.
* lisp/org-compat.el (org-bookmark-jump-unhide): Accept (unused) args.
(save-place-find-file-hook): Use `advice-add`.
(org--ecb-show-context): New function, extracted from advice.
(ecb-method-clicked): Use it with `advice-add`.
(org-mark-jump-unhide): Accept (unused) args.
(pop-to-mark-command, exchange-point-and-mark, pop-global-mark):
Use `advice-add`.
Along the way, remove some redundant `:group` args
(redundant because they specify the same group as would be used by
default anyway) and make a few other simplifications.
Also don't bother putting `advice-add` within an eval-after-load
since the advice machinery already takes care of handling it.
2022-04-01 01:50:01 -04:00
|
|
|
(advice-add 'server-visit-files :around #'org--protocol-detect-protocol-server)
|
|
|
|
(defun org--protocol-detect-protocol-server (orig-fun files client &rest args)
|
2022-11-21 09:16:08 -05:00
|
|
|
"Advice server-visit-flist to call `org-protocol-check-filename-for-protocol'."
|
2009-03-30 09:47:34 -04:00
|
|
|
(let ((flist (if org-protocol-reverse-list-of-files
|
Replace all uses of the old `defadvice` with the new `advice-add`
* lisp/org.el (org-run-like-in-org-mode): Strength reduce `eval`
to `cl-progv`.
(org--check-org-structure-template-alist): Strength reduce `eval`
to `symbol-value`.
(org-map-entries, org-eval-in-calendar, org-diary-sexp-entry):
Make sure we use the new lexically scoped dialect.
(org--math-always-on): New function, extracted from advice.
(org-cdlatex-mode): Use it with `advice-add`.
(org-self-insert-command): Simplify `and`+`listp` into `consp`.
(org-submit-bug-report):
Make sure we use the new lexically scoped dialect.
* lisp/org-protocol.el (org-protocol-convert-query-to-plist):
Use `cl-mapcan`.
(org--protocol-detect-protocol-server): New function, extracted
from advice.
(server-visit-files): Use it with `advice-add`.
* lisp/org-mouse.el (org--mouse-dnd-insert-text): New function, extracted
from advice.
(dnd-insert-text): Use it with `advice-add`.
(org--mouse-dnd-open-file): New function, extracted from advice.
(dnd-open-file): Use it with `advice-add`.
(org--mouse-open-at-point): New function, extracted from advice.
(org-mode-hook): Advise `org-open-at-point` with `advice-add`.
* lisp/org-ctags.el (org--ctags-load-tag-list): New function, extracted
from advice.
(visit-tags-table): Use it with `advice-add`.
(org--ctags-set-org-mark-before-finding-tag): New function, extracted
from advice.
(xref-find-definitions): Use it with `advice-add`.
* lisp/org-compat.el (org-bookmark-jump-unhide): Accept (unused) args.
(save-place-find-file-hook): Use `advice-add`.
(org--ecb-show-context): New function, extracted from advice.
(ecb-method-clicked): Use it with `advice-add`.
(org-mark-jump-unhide): Accept (unused) args.
(pop-to-mark-command, exchange-point-and-mark, pop-global-mark):
Use `advice-add`.
Along the way, remove some redundant `:group` args
(redundant because they specify the same group as would be used by
default anyway) and make a few other simplifications.
Also don't bother putting `advice-add` within an eval-after-load
since the advice machinery already takes care of handling it.
2022-04-01 01:50:01 -04:00
|
|
|
(reverse files)
|
|
|
|
files)))
|
2009-03-30 09:47:34 -04:00
|
|
|
(catch 'greedy
|
|
|
|
(dolist (var flist)
|
2012-08-11 13:10:44 -04:00
|
|
|
;; `\' to `/' on windows. FIXME: could this be done any better?
|
2011-03-23 05:14:03 -04:00
|
|
|
(let ((fname (expand-file-name (car var))))
|
|
|
|
(setq fname (org-protocol-check-filename-for-protocol
|
|
|
|
fname (member var flist) client))
|
2015-05-21 13:04:45 -04:00
|
|
|
(if (eq fname t) ;; greedy? We need the t return value.
|
2009-03-30 09:47:34 -04:00
|
|
|
(progn
|
Replace all uses of the old `defadvice` with the new `advice-add`
* lisp/org.el (org-run-like-in-org-mode): Strength reduce `eval`
to `cl-progv`.
(org--check-org-structure-template-alist): Strength reduce `eval`
to `symbol-value`.
(org-map-entries, org-eval-in-calendar, org-diary-sexp-entry):
Make sure we use the new lexically scoped dialect.
(org--math-always-on): New function, extracted from advice.
(org-cdlatex-mode): Use it with `advice-add`.
(org-self-insert-command): Simplify `and`+`listp` into `consp`.
(org-submit-bug-report):
Make sure we use the new lexically scoped dialect.
* lisp/org-protocol.el (org-protocol-convert-query-to-plist):
Use `cl-mapcan`.
(org--protocol-detect-protocol-server): New function, extracted
from advice.
(server-visit-files): Use it with `advice-add`.
* lisp/org-mouse.el (org--mouse-dnd-insert-text): New function, extracted
from advice.
(dnd-insert-text): Use it with `advice-add`.
(org--mouse-dnd-open-file): New function, extracted from advice.
(dnd-open-file): Use it with `advice-add`.
(org--mouse-open-at-point): New function, extracted from advice.
(org-mode-hook): Advise `org-open-at-point` with `advice-add`.
* lisp/org-ctags.el (org--ctags-load-tag-list): New function, extracted
from advice.
(visit-tags-table): Use it with `advice-add`.
(org--ctags-set-org-mark-before-finding-tag): New function, extracted
from advice.
(xref-find-definitions): Use it with `advice-add`.
* lisp/org-compat.el (org-bookmark-jump-unhide): Accept (unused) args.
(save-place-find-file-hook): Use `advice-add`.
(org--ecb-show-context): New function, extracted from advice.
(ecb-method-clicked): Use it with `advice-add`.
(org-mark-jump-unhide): Accept (unused) args.
(pop-to-mark-command, exchange-point-and-mark, pop-global-mark):
Use `advice-add`.
Along the way, remove some redundant `:group` args
(redundant because they specify the same group as would be used by
default anyway) and make a few other simplifications.
Also don't bother putting `advice-add` within an eval-after-load
since the advice machinery already takes care of handling it.
2022-04-01 01:50:01 -04:00
|
|
|
;; FIXME: Doesn't this just ignore all the files before
|
|
|
|
;; this one (the remaining ones have been passed to
|
|
|
|
;; `org-protocol-check-filename-for-protocol' but not
|
|
|
|
;; the ones before).
|
|
|
|
(setq files nil)
|
2009-03-30 09:47:34 -04:00
|
|
|
(throw 'greedy t))
|
|
|
|
(if (stringp fname) ;; probably filename
|
|
|
|
(setcar var fname)
|
Replace all uses of the old `defadvice` with the new `advice-add`
* lisp/org.el (org-run-like-in-org-mode): Strength reduce `eval`
to `cl-progv`.
(org--check-org-structure-template-alist): Strength reduce `eval`
to `symbol-value`.
(org-map-entries, org-eval-in-calendar, org-diary-sexp-entry):
Make sure we use the new lexically scoped dialect.
(org--math-always-on): New function, extracted from advice.
(org-cdlatex-mode): Use it with `advice-add`.
(org-self-insert-command): Simplify `and`+`listp` into `consp`.
(org-submit-bug-report):
Make sure we use the new lexically scoped dialect.
* lisp/org-protocol.el (org-protocol-convert-query-to-plist):
Use `cl-mapcan`.
(org--protocol-detect-protocol-server): New function, extracted
from advice.
(server-visit-files): Use it with `advice-add`.
* lisp/org-mouse.el (org--mouse-dnd-insert-text): New function, extracted
from advice.
(dnd-insert-text): Use it with `advice-add`.
(org--mouse-dnd-open-file): New function, extracted from advice.
(dnd-open-file): Use it with `advice-add`.
(org--mouse-open-at-point): New function, extracted from advice.
(org-mode-hook): Advise `org-open-at-point` with `advice-add`.
* lisp/org-ctags.el (org--ctags-load-tag-list): New function, extracted
from advice.
(visit-tags-table): Use it with `advice-add`.
(org--ctags-set-org-mark-before-finding-tag): New function, extracted
from advice.
(xref-find-definitions): Use it with `advice-add`.
* lisp/org-compat.el (org-bookmark-jump-unhide): Accept (unused) args.
(save-place-find-file-hook): Use `advice-add`.
(org--ecb-show-context): New function, extracted from advice.
(ecb-method-clicked): Use it with `advice-add`.
(org-mark-jump-unhide): Accept (unused) args.
(pop-to-mark-command, exchange-point-and-mark, pop-global-mark):
Use `advice-add`.
Along the way, remove some redundant `:group` args
(redundant because they specify the same group as would be used by
default anyway) and make a few other simplifications.
Also don't bother putting `advice-add` within an eval-after-load
since the advice machinery already takes care of handling it.
2022-04-01 01:50:01 -04:00
|
|
|
(setq files (delq var files)))))))
|
|
|
|
(apply orig-fun files client args)))
|
2009-03-30 09:47:34 -04:00
|
|
|
|
|
|
|
;;; Org specific functions:
|
|
|
|
|
|
|
|
(defun org-protocol-create-for-org ()
|
2018-02-16 15:16:15 -05:00
|
|
|
"Create an Org protocol project for the current file's project.
|
2013-02-27 18:28:17 -05:00
|
|
|
The visited file needs to be part of a publishing project in
|
|
|
|
`org-publish-project-alist' for this to work. The function
|
|
|
|
delegates most of the work to `org-protocol-create'."
|
2009-03-30 09:47:34 -04:00
|
|
|
(interactive)
|
2017-02-28 07:37:48 -05:00
|
|
|
(require 'ox-publish)
|
2009-03-30 09:47:34 -04:00
|
|
|
(let ((all (or (org-publish-get-project-from-filename buffer-file-name))))
|
|
|
|
(if all (org-protocol-create (cdr all))
|
2017-02-28 07:37:48 -05:00
|
|
|
(message "%s"
|
|
|
|
(substitute-command-keys
|
|
|
|
"Not in an Org project. \
|
|
|
|
Did you mean `\\[org-protocol-create]'?")))))
|
2009-03-30 09:47:34 -04:00
|
|
|
|
2011-03-23 05:14:03 -04:00
|
|
|
(defun org-protocol-create (&optional project-plist)
|
2009-03-30 09:47:34 -04:00
|
|
|
"Create a new org-protocol project interactively.
|
2013-02-27 18:28:17 -05:00
|
|
|
An org-protocol project is an entry in
|
|
|
|
`org-protocol-project-alist' which is used by
|
|
|
|
`org-protocol-open-source'. Optionally use PROJECT-PLIST to
|
|
|
|
initialize the defaults for this project. If PROJECT-PLIST is
|
|
|
|
the cdr of an element in `org-publish-project-alist', reuse
|
2009-03-30 09:47:34 -04:00
|
|
|
:base-directory, :html-extension and :base-extension."
|
|
|
|
(interactive)
|
2011-03-23 05:14:03 -04:00
|
|
|
(let ((working-dir (expand-file-name
|
|
|
|
(or (plist-get project-plist :base-directory)
|
|
|
|
default-directory)))
|
2018-01-16 13:42:57 -05:00
|
|
|
(base-url "https://orgmode.org/worg/")
|
2009-03-30 09:47:34 -04:00
|
|
|
(strip-suffix (or (plist-get project-plist :html-extension) ".html"))
|
|
|
|
(working-suffix (if (plist-get project-plist :base-extension)
|
|
|
|
(concat "." (plist-get project-plist :base-extension))
|
|
|
|
".org"))
|
|
|
|
(insert-default-directory t)
|
|
|
|
(minibuffer-allow-text-properties nil))
|
|
|
|
|
|
|
|
(setq base-url (read-string "Base URL of published content: " base-url nil base-url t))
|
2016-08-24 11:05:54 -04:00
|
|
|
(or (string-suffix-p "/" base-url)
|
|
|
|
(setq base-url (concat base-url "/")))
|
2009-03-30 09:47:34 -04:00
|
|
|
|
|
|
|
(setq working-dir
|
|
|
|
(expand-file-name
|
|
|
|
(read-directory-name "Local working directory: " working-dir working-dir t)))
|
2016-08-24 11:05:54 -04:00
|
|
|
(or (string-suffix-p "/" working-dir)
|
|
|
|
(setq working-dir (concat working-dir "/")))
|
2009-03-30 09:47:34 -04:00
|
|
|
|
|
|
|
(setq strip-suffix
|
|
|
|
(read-string
|
2011-03-23 05:14:03 -04:00
|
|
|
(concat "Extension to strip from published URLs (" strip-suffix "): ")
|
2012-08-11 13:10:44 -04:00
|
|
|
strip-suffix nil strip-suffix t))
|
2009-03-30 09:47:34 -04:00
|
|
|
|
|
|
|
(setq working-suffix
|
|
|
|
(read-string
|
2011-03-23 05:14:03 -04:00
|
|
|
(concat "Extension of editable files (" working-suffix "): ")
|
2012-08-11 13:10:44 -04:00
|
|
|
working-suffix nil working-suffix t))
|
2009-03-30 09:47:34 -04:00
|
|
|
|
2009-11-15 06:24:40 -05:00
|
|
|
(when (yes-or-no-p "Save the new org-protocol-project to your init file? ")
|
2009-03-30 09:47:34 -04:00
|
|
|
(setq org-protocol-project-alist
|
|
|
|
(cons `(,base-url . (:base-url ,base-url
|
2012-08-11 13:10:44 -04:00
|
|
|
:working-directory ,working-dir
|
|
|
|
:online-suffix ,strip-suffix
|
|
|
|
:working-suffix ,working-suffix))
|
2009-03-30 09:47:34 -04:00
|
|
|
org-protocol-project-alist))
|
2009-07-27 18:02:10 -04:00
|
|
|
(customize-save-variable 'org-protocol-project-alist org-protocol-project-alist))))
|
2009-03-30 09:47:34 -04:00
|
|
|
|
|
|
|
(provide 'org-protocol)
|
2009-08-08 00:34:24 -04:00
|
|
|
|
2009-03-30 09:47:34 -04:00
|
|
|
;;; org-protocol.el ends here
|