From mboxrd@z Thu Jan 1 00:00:00 1970 From: James TD Smith Subject: [PATCH 5/5] clipboard handling in remember templats Date: Sun, 16 Mar 2008 16:31:12 +0000 Message-ID: <20080316163020.23004.90078.stgit@nyarlathotep.internal> References: <20080316162417.23004.16993.stgit@nyarlathotep.internal> Mime-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JawJg-0001Yk-HI for emacs-orgmode@gnu.org; Sun, 16 Mar 2008 13:06:36 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JawJf-0001Y6-P3 for emacs-orgmode@gnu.org; Sun, 16 Mar 2008 13:06:36 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JawJf-0001Xv-JP for emacs-orgmode@gnu.org; Sun, 16 Mar 2008 13:06:35 -0400 Received: from 81-86-40-42.dsl.pipex.com ([81.86.40.42] helo=yog-sothoth.internal) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JawJd-0007u7-Ug for emacs-orgmode@gnu.org; Sun, 16 Mar 2008 13:06:35 -0400 Received: from nyarlathotep.internal (Debian-exim@nyarlathotep.internal [10.0.0.5]) by yog-sothoth.internal (8.13.4/8.13.4) with ESMTP id m2GGVCRx015309 for ; Sun, 16 Mar 2008 16:31:12 GMT (envelope-from ahktenzero@dsl.pipex.com) Received: from [127.0.0.1] (helo=nyarlathotep.internal ident=ahktenzero) by nyarlathotep.internal with esmtp (Exim 4.69) (envelope-from ) id 1JavlQ-0006KI-G4 for emacs-orgmode@gnu.org; Sun, 16 Mar 2008 16:31:12 +0000 In-Reply-To: <20080316162417.23004.16993.stgit@nyarlathotep.internal> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org From: James TD Smith Fix the X clipboard handling so it works properly, and so it works in XEmacs,and add a new % expansion for adding links. This patch reverts the %c expansion to its original function (head of kill ring), and adds three new % expansions as follows: %x - Contents of the X clipboard. This is the first non-empty value from the PRIMARY, SECONDARY and CLIPBOARD X clipboards. %^C - This allows the user to choose between any of the clipboard values available, the kill ring head, and the initial region if set. %^L - Like %^C, but this inserts an org link using the selected value. --- org.el | 56 +++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 41 insertions(+), 15 deletions(-) diff --git a/org.el b/org.el index d67024f..0e5fa6a 100644 --- a/org.el +++ b/org.el @@ -12509,7 +12509,7 @@ This command can be called in any mode to insert a link in Org-mode syntax." (org-load-modules-maybe) (org-run-like-in-org-mode 'org-insert-link)) -(defun org-insert-link (&optional complete-file) +(defun org-insert-link (&optional complete-file link-location) "Insert a link. At the prompt, enter the link. Completion can be used to select a link previously stored with @@ -12538,7 +12538,10 @@ three \\[universal-argument] prefixes, negate the meaning of If `org-make-link-description' is non-nil, this function will be called with the link target, and the result will be the default -link description." +link description. + +If the `link-location' parameter is non-nil, this value will be +used as the link location instead of reading one interactively" (interactive "P") (let* ((wcf (current-window-configuration)) (region (if (org-region-active-p) @@ -12546,7 +12549,8 @@ link description." (remove (and region (list (region-beginning) (region-end)))) (desc region) tmphist ; byte-compile incorrectly complains about this - link entry file) + (link link-location) + entry file) (cond ((org-in-regexp org-bracket-link-regexp 1) ;; We do have a link at point, and we are going to edit it. @@ -12579,7 +12583,7 @@ link description." (setq link (org-make-link "file:" (match-string 1 (expand-file-name file))))) (t (setq link (org-make-link "file:" file)))))) - (t + ((not link) ;; Read link, with completion for stored links. (with-output-to-temp-buffer "*Org Links*" (princ "Insert a link. Use TAB to complete valid link prefixes.\n") @@ -13399,8 +13403,12 @@ RET at beg-of-buf -> Append to file as level 2 headline char0)))))) (cddr (assoc char templates))))) -(defvar x-last-selected-text) -(defvar x-last-selected-text-primary) +(defun org-get-x-clipboard (value) + (if (eq window-system 'x) + (let ((x (if org-xemacs-p + (get-selection-no-error value) + (x-selection-value value)))) + (and (> (length x) 0) (set-text-properties 0 (length x) nil x) x)))) ;;;###autoload (defun org-remember-apply-template (&optional use-char skip-interactive) @@ -13416,12 +13424,10 @@ to be run from that hook to function properly." (nth 1 entry) org-default-notes-file)) (headline (nth 2 entry)) - (v-c (or (and (eq window-system 'x) - (fboundp 'x-cut-buffer-or-selection-value) - (x-cut-buffer-or-selection-value)) - (org-bound-and-true-p x-last-selected-text) - (org-bound-and-true-p x-last-selected-text-primary) - (and (> (length kill-ring) 0) (current-kill 0)))) + (v-c (and (> (length kill-ring) 0) (current-kill 0))) + (v-x (or (org-get-x-clipboard 'PRIMARY) + (org-get-x-clipboard 'CLIPBOARD) + (org-get-x-clipboard 'SECONDARY))) (v-t (format-time-string (car org-time-stamp-formats) (org-current-time))) (v-T (format-time-string (cdr org-time-stamp-formats) (org-current-time))) (v-u (concat "[" (substring v-t 1 -1) "]")) @@ -13431,6 +13437,11 @@ to be run from that hook to function properly." (v-a (if (and (boundp 'annotation) annotation) (if (equal annotation "[[]]") "" annotation) "")) + (clipboards (remove nil (list v-i + (org-get-x-clipboard 'PRIMARY) + (org-get-x-clipboard 'CLIPBOARD) + (org-get-x-clipboard 'SECONDARY) + v-c))) (v-A (if (and v-a (string-match "\\[\\(\\[.*?\\]\\)\\(\\[.*?\\]\\)?\\]" v-a)) (replace-match "[\\1[%^{Link description}]]" nil nil v-a) @@ -13459,7 +13470,7 @@ to be run from that hook to function properly." (or (cdr org-remember-previous-location) "???")))) (insert tpl) (goto-char (point-min)) ;; Simple %-escapes - (while (re-search-forward "%\\([tTuUaiAc]\\)" nil t) + (while (re-search-forward "%\\([tTuUaiAcx]\\)" nil t) (when (and initial (equal (match-string 0) "%i")) (save-match-data (let* ((lead (buffer-substring @@ -13513,7 +13524,7 @@ to be run from that hook to function properly." (org-set-local 'org-remember-default-headline headline)) ;; Interactive template entries (goto-char (point-min)) - (while (re-search-forward "%^\\({\\([^}]*\\)}\\)?\\([gGuUtT]\\)?" nil t) + (while (re-search-forward "%^\\({\\([^}]*\\)}\\)?\\([gGuUtTCL]\\)?" nil t) (setq char (if (match-end 3) (match-string 3)) prompt (if (match-end 2) (match-string 2))) (goto-char (match-beginning 0)) @@ -13544,7 +13555,22 @@ to be run from that hook to function properly." (or (equal (char-before) ?:) (insert ":")) (insert ins) (or (equal (char-after) ?:) (insert ":"))))) - (char + ((equal char "C") + (cond ((= (length clipboards) 1) (insert (car clipboards))) + ((> (length clipboards) 1) + (insert (read-string "Clipboard/kill value: " + (car clipboards) '(clipboards . 1) + (car clipboards)))))) + ((equal char "L") + (cond ((= (length clipboards) 1) + (org-insert-link 0 (car clipboards))) + ((> (length clipboards) 1) + (org-insert-link 0 (read-string "Clipboard/kill value: " + (car clipboards) + '(clipboards . 1) + (car clipboards)))))) + + (char (setq org-time-was-given (equal (upcase char) char)) (setq time (org-read-date (equal (upcase char) "U") t nil prompt))