Function: org-protocol-flatten-greedy

org-protocol-flatten-greedy is a byte-compiled function defined in org-protocol.el.gz.

Signature

(org-protocol-flatten-greedy PARAM-LIST &optional STRIP-PATH REPLACEMENT)

Documentation

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 function transforms it into a flat list using org-protocol-flatten and transforms the elements of that list as follows:

If STRIP-PATH is non-nil, remove the "/dir/" prefix from all members of param-list.

If REPLACEMENT is string, replace the "/dir/" prefix with it.

The first parameter, the one that contains the protocols, is always changed. Everything up to the end of the protocols is stripped.

Note, that this function will always behave as if org-protocol-reverse-list-of-files was set to t and the returned list will reflect that. emacsclient's first parameter will be the first one in the returned list.

Source Code

;; Defined in /usr/src/emacs/lisp/org/org-protocol.el.gz
(defun org-protocol-flatten-greedy (param-list &optional strip-path replacement)
  "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
function transforms it into a flat list using `org-protocol-flatten' and
transforms the elements of that list as follows:

If STRIP-PATH is non-nil, remove the \"/dir/\" prefix from all members of
param-list.

If REPLACEMENT is string, replace the \"/dir/\" prefix with it.

The first parameter, the one that contains the protocols, is always changed.
Everything up to the end of the protocols is stripped.

Note, that this function will always behave as if
`org-protocol-reverse-list-of-files' was set to t and the returned list will
reflect that.  emacsclient's first parameter will be the first one in the
returned list."
  (let* ((l (org-protocol-flatten (if org-protocol-reverse-list-of-files
				      param-list
				    (reverse param-list))))
	 (trigger (car l))
	 (len 0)
	 dir
	 ret)
    (when (string-match "^\\(.*\\)\\(org-protocol:/+[a-zA-Z0-9][-_a-zA-Z0-9]*:/+\\)\\(.*\\)" trigger)
      (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)))