Browse Source

Store link to referenced entries in agenda

Peter Westlake writes:

> Could I request this as a small feature enhancement, please?
> Commands like org-refile have an agenda equivalent so that
> the same keys work in the agenda, and it would be very nice
> to be able to store a link to an item that way as well.
Carsten Dominik 15 years ago
parent
commit
0054bf1105
4 changed files with 24 additions and 0 deletions
  1. 5 0
      doc/org.texi
  2. 8 0
      lisp/ChangeLog
  3. 1 0
      lisp/org-macs.el
  4. 10 0
      lisp/org.el

+ 5 - 0
doc/org.texi

@@ -2973,6 +2973,11 @@ search string.  If the automatically created link is not working correctly or
 accurately enough, you can write custom functions to select the search string
 and to do the search for particular file types---see @ref{Custom searches}.
 The key binding @kbd{C-c l} is only a suggestion---see @ref{Installation}.
+
+@b{Agenda view}@*
+When the cursor is in an agenda view, the created link points to the
+entry referenced by the current line.
+
 @c
 @kindex C-c C-l
 @cindex link completion

+ 8 - 0
lisp/ChangeLog

@@ -1,3 +1,11 @@
+2009-09-12  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org.el (org-store-link): When in agenda buffer, link to
+	referenced entry.
+
+	* org-macs.el (org-with-point-at): Add a `lisp-indent-function'
+	property.
+
 2009-09-10  Carsten Dominik  <carsten.dominik@gmail.com>
 
 	* org-latex.el (org-export-latex-first-lines): Fix problem with

+ 1 - 0
lisp/org-macs.el

@@ -102,6 +102,7 @@ We use a macro so that the test can happen at compilation time."
      (save-excursion
        (goto-char (or ,pom (point)))
        ,@body)))
+(put 'org-with-point-at 'lisp-indent-function 1)
 
 (defmacro org-no-warnings (&rest body)
   (cons (if (fboundp 'with-no-warnings) 'with-no-warnings 'progn) body))

+ 10 - 0
lisp/org.el

@@ -7141,6 +7141,8 @@ type.  For a simple example of an export function, see `org-bbdb.el'."
       (setcdr (assoc type org-link-protocols) (list follow export))
     (push (list type follow export) org-link-protocols)))
 
+(defvar org-agenda-buffer-name)
+
 ;;;###autoload
 (defun org-store-link (arg)
   "\\<org-mode-map>Store an org-link to the current location.
@@ -7180,6 +7182,14 @@ For file links, arg negates `org-context-in-file-links'."
 	(insert link)
 	(setq link (concat "(" label ")") desc nil)))
 
+     ((equal (org-bound-and-true-p org-agenda-buffer-name) (buffer-name))
+      ;; We are in the agenda, link to referenced location
+      (let ((m (or (get-text-property (point) 'org-hd-marker)
+		   (get-text-property (point) 'org-marker))))
+	(unless m (error "Don't know what location to link to"))
+	(org-with-point-at m
+	  (call-interactively 'org-store-link))))
+
      ((eq major-mode 'calendar-mode)
       (let ((cd (calendar-cursor-to-date)))
 	(setq link