Browse Source

Agenda: Make `C-c C-o' and RET opening links in clocktables in the agenda

RET will only do this if the cursor is on the link and
`org-return-follows-link' is set.  `C-c C-o' will work anywhere in the
line.

Requested by Chris Leyon.
Carsten Dominik 15 years ago
parent
commit
ba1e90893d
2 changed files with 41 additions and 22 deletions
  1. 8 0
      lisp/ChangeLog
  2. 33 22
      lisp/org-agenda.el

+ 8 - 0
lisp/ChangeLog

@@ -1,3 +1,11 @@
+2009-11-02  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org-agenda.el (org-agenda-open-link): Make this work in agenda
+	clocktables.
+	(org-agenda-switch-to): Follow a link at point if
+	org-return-follows-link' is set and there is nothing else to do in
+	this line.
+
 2009-11-01  Dan Davison  <davison@stats.ox.ac.uk>
 
 	* org-exp-blocks.el: Modify split separator regexp to avoid empty

+ 33 - 22
lisp/org-agenda.el

@@ -5851,7 +5851,7 @@ If this information is not given, the function uses the tree at point."
 
 (defun org-agenda-open-link (&optional arg)
   "Follow the link in the current line, if any.
-This looks for a link in the displayed lin in the agenda.  It also looks
+This looks for a link in the displayed line in the agenda.  It also looks
 at the text of the entry itself."
   (interactive "P")
   (let* ((marker (or (org-get-at-bol 'org-hd-marker)
@@ -5860,14 +5860,21 @@ at the text of the entry itself."
 	 (prefix (buffer-substring
 		  (point-at-bol)
 		  (+ (point-at-bol)
-		     (org-get-at-bol 'prefix-length)))))
-    (unless buffer (error "Don't know where to look for links"))
-    (with-current-buffer buffer
-      (save-excursion
-	(save-restriction
-	  (widen)
-	  (goto-char marker)
-	  (org-offer-links-in-entry arg prefix))))))
+		     (or (org-get-at-bol 'prefix-length) 0)))))
+    (cond
+     (buffer
+      (with-current-buffer buffer
+	(save-excursion
+	  (save-restriction
+	    (widen)
+	    (goto-char marker)
+	    (org-offer-links-in-entry arg prefix)))))
+     ((or (org-in-regexp (concat "\\(" org-bracket-link-regexp "\\)"))
+	  (save-excursion
+	    (beginning-of-line 1)
+	    (looking-at (concat ".*?\\(" org-bracket-link-regexp "\\)"))))
+      (org-open-link-from-string (match-string 1)))
+     (t (error "No link to open here")))))
 
 (defun org-agenda-copy-local-variable (var)
   "Get a variable from a referenced buffer and install it here."
@@ -5879,19 +5886,23 @@ at the text of the entry itself."
 (defun org-agenda-switch-to (&optional delete-other-windows)
   "Go to the Org-mode file which contains the item at point."
   (interactive)
-  (let* ((marker (or (org-get-at-bol 'org-marker)
-		     (org-agenda-error)))
-	 (buffer (marker-buffer marker))
-	 (pos (marker-position marker)))
-    (switch-to-buffer buffer)
-    (and delete-other-windows (delete-other-windows))
-    (widen)
-    (goto-char pos)
-    (when (org-mode-p)
-      (org-show-context 'agenda)
-      (save-excursion
-	(and (outline-next-heading)
-	     (org-flag-heading nil))))))  ; show the next heading
+  (if (and org-return-follows-link
+	   (not (org-get-at-bol 'org-marker))
+	   (org-in-regexp org-bracket-link-regexp))
+      (org-open-link-from-string (match-string 0))
+    (let* ((marker (or (org-get-at-bol 'org-marker)
+		       (org-agenda-error)))
+	   (buffer (marker-buffer marker))
+	   (pos (marker-position marker)))
+      (switch-to-buffer buffer)
+      (and delete-other-windows (delete-other-windows))
+      (widen)
+      (goto-char pos)
+      (when (org-mode-p)
+	(org-show-context 'agenda)
+	(save-excursion
+	  (and (outline-next-heading)
+	       (org-flag-heading nil)))))))  ; show the next heading
 
 (defun org-agenda-goto-mouse (ev)
   "Go to the Org-mode file which contains the item at the mouse click."