summaryrefslogtreecommitdiff
path: root/lisp/org/org-protocol.el
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2022-11-29 23:05:53 -0500
committerKyle Meyer <kyle@kyleam.com>2022-11-29 23:05:53 -0500
commit0625651e8a61c9effc31ff771f15885a3a37c6e6 (patch)
treedb4c09e8ef119ad4a9a4028c5e615fd58d2dee69 /lisp/org/org-protocol.el
parentedd64e64a389e0f0e6ce670846d4fae79a9d8b35 (diff)
downloademacs-0625651e8a61c9effc31ff771f15885a3a37c6e6.tar.gz
Update to Org 9.6-3-ga4d38e
Diffstat (limited to 'lisp/org/org-protocol.el')
-rw-r--r--lisp/org/org-protocol.el43
1 files changed, 24 insertions, 19 deletions
diff --git a/lisp/org/org-protocol.el b/lisp/org/org-protocol.el
index cd99f30e7bd..9ce21cf2ac2 100644
--- a/lisp/org/org-protocol.el
+++ b/lisp/org/org-protocol.el
@@ -128,12 +128,14 @@
;;
;;; Code:
+(require 'org-macs)
+(org-assert-version)
+
(require 'org)
(require 'ol)
(declare-function org-publish-get-project-from-filename "ox-publish"
(filename &optional up))
-(declare-function server-edit "server" (&optional arg))
(defvar org-capture-link-is-already-stored)
(defvar org-capture-templates)
@@ -173,7 +175,6 @@ 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
unchanged."
- :group 'org-protocol
:type 'boolean)
(defcustom org-protocol-project-alist nil
@@ -232,7 +233,6 @@ Example:
Consider using the interactive functions `org-protocol-create'
and `org-protocol-create-for-org' to help you filling this
variable with valid contents."
- :group 'org-protocol
:type 'alist)
(defcustom org-protocol-protocol-alist nil
@@ -283,20 +283,17 @@ Here is an example:
(\"your-protocol\"
:protocol \"your-protocol\"
:function your-protocol-handler-function)))"
- :group 'org-protocol
:type '(alist))
(defcustom org-protocol-default-template-key nil
"The default template key to use.
This is usually a single character string but can also be a
string with two characters."
- :group 'org-protocol
:type '(choice (const nil) (string)))
(defcustom org-protocol-data-separator "/+\\|\\?"
"The default data separator to use.
This should be a single regexp string."
- :group 'org-protocol
:version "24.4"
:package-version '(Org . "8.0")
:type 'regexp)
@@ -308,7 +305,8 @@ This should be a single regexp string."
Emacsclient compresses double and triple slashes."
(when (string-match "^\\([a-z]+\\):/" uri)
(let* ((splitparts (split-string uri "/+")))
- (setq uri (concat (car splitparts) "//" (mapconcat 'identity (cdr splitparts) "/")))))
+ (setq uri (concat (car splitparts) "//"
+ (mapconcat #'identity (cdr splitparts) "/")))))
uri)
(defun org-protocol-split-data (data &optional unhexify separator)
@@ -370,6 +368,7 @@ returned list."
ret)
l)))
+;; `flatten-tree' was added in Emacs 27.1.
(defalias 'org-protocol-flatten
(if (fboundp 'flatten-tree) 'flatten-tree
(lambda (list)
@@ -548,10 +547,10 @@ Now template ?b will be used."
"Convert QUERY key=value pairs in the URL to a property list."
(when query
(let ((plus-decoded (replace-regexp-in-string "\\+" " " query t t)))
- (apply 'append (mapcar (lambda (x)
- (let ((c (split-string x "=")))
- (list (intern (concat ":" (car c))) (cadr c))))
- (split-string plus-decoded "&"))))))
+ (cl-mapcan (lambda (x)
+ (let ((c (split-string x "=")))
+ (list (intern (concat ":" (car c))) (cadr c))))
+ (split-string plus-decoded "&")))))
(defun org-protocol-open-source (fname)
"Process an org-protocol://open-source?url= style URL with FNAME.
@@ -640,7 +639,7 @@ Old-style links such as \"protocol://sub-protocol://param1/param2\" are
also recognized.
If a matching protocol is found, the protocol is stripped from
-fname and the result is passed to the protocol function as the
+FNAME and the result is passed to the protocol function as the
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
@@ -670,7 +669,8 @@ CLIENT is ignored."
(new-style (not (= ?: (aref (match-string 1 fname) 0)))))
(when (plist-get (cdr prolist) :kill-client)
(message "Greedy org-protocol handler. Killing client.")
- (server-edit))
+ ;; If not fboundp, there's no client to kill.
+ (if (fboundp 'server-edit) (server-edit)))
(when (fboundp func)
(unless greedy
(throw 'fname
@@ -686,12 +686,12 @@ to deal with new-style links.")
(throw 'fname t))))))))
fname)))
-(defadvice server-visit-files (before org-protocol-detect-protocol-server activate)
+(advice-add 'server-visit-files :around #'org--protocol-detect-protocol-server)
+(defun org--protocol-detect-protocol-server (orig-fun files client &rest args)
"Advice server-visit-flist to call `org-protocol-check-filename-for-protocol'."
(let ((flist (if org-protocol-reverse-list-of-files
- (reverse (ad-get-arg 0))
- (ad-get-arg 0)))
- (client (ad-get-arg 1)))
+ (reverse files)
+ files)))
(catch 'greedy
(dolist (var flist)
;; `\' to `/' on windows. FIXME: could this be done any better?
@@ -700,11 +700,16 @@ to deal with new-style links.")
fname (member var flist) client))
(if (eq fname t) ;; greedy? We need the t return value.
(progn
- (ad-set-arg 0 nil)
+ ;; 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)
(throw 'greedy t))
(if (stringp fname) ;; probably filename
(setcar var fname)
- (ad-set-arg 0 (delq var (ad-get-arg 0))))))))))
+ (setq files (delq var files)))))))
+ (apply orig-fun files client args)))
;;; Org specific functions: