From: James TD Smith <[EMAIL PROTECTED]>

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))



_______________________________________________
Emacs-orgmode mailing list
Remember: use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

Reply via email to