emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: James TD Smith <ahktenzero@dsl.pipex.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH 5/5] clipboard handling in remember templats
Date: Sun, 16 Mar 2008 16:31:12 +0000	[thread overview]
Message-ID: <20080316163020.23004.90078.stgit@nyarlathotep.internal> (raw)
In-Reply-To: <20080316162417.23004.16993.stgit@nyarlathotep.internal>

From: James TD Smith <ahktenzero@usa.net>

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

  parent reply	other threads:[~2008-03-16 17:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-16 16:27 [PATCH 0/5] Various patches James TD Smith
2008-03-16 16:28 ` [PATCH 1/5] Hide drawers after displaying an entry using org-clock-goto James TD Smith
2008-03-16 16:29 ` [PATCH 2/5] Add a way to set a user-defined function to generate descriptions for links James TD Smith
2008-04-09 15:15   ` Carsten Dominik
2008-03-16 16:29 ` [PATCH 3/5] Some improvements to org-table-export James TD Smith
2008-04-09 15:59   ` Carsten Dominik
2008-03-16 16:30 ` [PATCH 4/5] Add a new sort option, which sorts items by todo keyword James TD Smith, James TD Smith
2008-04-09 15:40   ` Carsten Dominik
2008-03-16 16:31 ` James TD Smith [this message]
2008-04-09 15:32   ` [PATCH 5/5] clipboard handling in remember templats Carsten Dominik
2008-04-09 17:35     ` James TD Smith
2008-03-16 18:29 ` [PATCH 4/5] Various patches James TD Smith

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080316163020.23004.90078.stgit@nyarlathotep.internal \
    --to=ahktenzero@dsl.pipex.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).