Browse Source

Footnotes: Activate labels as links

This commit add a new face for footnote labels, and activates footnote
labels for mouse clicks and for `C-c C-o', to jump to the
corresponding reference or definition.
Carsten Dominik 16 years ago
parent
commit
3559b2dc93
6 changed files with 78 additions and 28 deletions
  1. 21 21
      ORGWEBPAGE/Changes.org
  2. 6 0
      doc/org.texi
  3. 9 0
      lisp/ChangeLog
  4. 7 0
      lisp/org-faces.el
  5. 5 1
      lisp/org-footnote.el
  6. 30 6
      lisp/org.el

+ 21 - 21
ORGWEBPAGE/Changes.org

@@ -26,9 +26,9 @@ reference is simply the marker in square brackets inside text.
 For example:
 For example:
 
 
 #+begin_src org
 #+begin_src org
- The Org homepage[1] now looks a lot better than it used to.
+ The Org homepage[fn:1] now looks a lot better than it used to.
  ...
  ...
- [1] The link is: http://orgmode.org
+ [fn:1] The link is: http://orgmode.org
 #+end_src
 #+end_src
 
 
 Org-mode extends the number-based syntax to /named/ footnotes and
 Org-mode extends the number-based syntax to /named/ footnotes and
@@ -43,15 +43,14 @@ references:
      unique label word or, for simplicity of automatic creation,
      unique label word or, for simplicity of automatic creation,
      a number. 
      a number. 
      
      
-- [fn:: This is the inline definition of this footnote] ::
-     A LaTeX-like anonymous footnote where the definition is given
+- [fn:: This is the inline definition of this footnote] :: A
+     LaTeX-like anonymous footnote where the definition is given
      directly at the reference point.
      directly at the reference point.
 
 
-- [fn:name: a definition] ::
-     An inline definition of a footnote, which also specifies a name
-     for the note.  Since Org allows multiple references to the same
-     note, you can then use use `[fn:name]' to create additional
-     references.
+- [fn:name: a definition] :: An inline definition of a footnote,
+     which also specifies a name for the note.  Since Org allows
+     multiple references to the same note, you can then use use
+     `[fn:name]' to create additional references.
 
 
 Footnote labels can be created automatically, or you create names
 Footnote labels can be created automatically, or you create names
 yourself.  This is handled by the variable
 yourself.  This is handled by the variable
@@ -60,19 +59,17 @@ keywords, see the docstring of that variable for details.
 
 
 The following command handles footnotes:
 The following command handles footnotes:
 
 
-- C-c C-x f ::
-     The footnote action command.  When the cursor is on a
-     footnote reference, jump to the definition.  When it is at a
-     definition, jump to the (first) reference.  Otherwise,
+- C-c C-x f :: The footnote action command.  When the cursor is
+     on a footnote reference, jump to the definition.  When it is
+     at a definition, jump to the (first) reference.  Otherwise,
      create a new footnote.  Depending on the variable
      create a new footnote.  Depending on the variable
      `org-footnote-define-inline' (with associated =#+STARTUP=
      `org-footnote-define-inline' (with associated =#+STARTUP=
      options =fninline= and =nofninline=), the definitions will
      options =fninline= and =nofninline=), the definitions will
      be placed locally, or into the nearest outline section with
      be placed locally, or into the nearest outline section with
      the heading `Footnotes'.  If no such section is found after
      the heading `Footnotes'.  If no such section is found after
      the reference point, one will be created at the end of the
      the reference point, one will be created at the end of the
-     file.
-     When this command is called with a prefix argument, a menu of
-     additional options is offered:
+     file.  When this command is called with a prefix argument, a
+     menu of additional options is offered:
      - s :: Sort the footnote definitions by reference sequence.
      - s :: Sort the footnote definitions by reference sequence.
             During editing, Org makes no effort to sort
             During editing, Org makes no effort to sort
             footnote definitions into a particular sequence.
             footnote definitions into a particular sequence.
@@ -87,11 +84,14 @@ The following command handles footnotes:
             something like `message-send-hook'.
             something like `message-send-hook'.
      - d :: Delete the footnote at point, and all references to it.
      - d :: Delete the footnote at point, and all references to it.
      
      
-- C-c C-c ::
-     If the cursor is on a footnote reference, jump to the definition.
-     If it is a the definition, jump back to the reference.  When
-     called with a prefix argument at either location, offer the
-     same menu as `C-u C-c C-x f'.
+- C-c C-c :: If the cursor is on a footnote reference, jump to
+     the definition.  If it is a the definition, jump back to the
+     reference.  When called with a prefix argument at either
+     location, offer the same menu as `C-u C-c C-x f'.
+
+- C-c C-o or mouse-1/2 :: Footnote labels are also links to the
+     corresponding definition/reference, and you can use the
+     usual commands to follow these links.
 
 
 Org-mode's footnote support is designed so that it should also
 Org-mode's footnote support is designed so that it should also
 work in buffers that are not in Org-mode, for example in email
 work in buffers that are not in Org-mode, for example in email

+ 6 - 0
doc/org.texi

@@ -1443,6 +1443,12 @@ d   @r{Delete the footnote at point, and all definitions of and references}
 If the cursor is on a footnote reference, jump to the definition.  If it is a
 If the cursor is on a footnote reference, jump to the definition.  If it is a
 the definition, jump back to the reference.  When called at a footnote
 the definition, jump back to the reference.  When called at a footnote
 location with a prefix argument, offer the same menu as @kbd{C-c C-x f}.
 location with a prefix argument, offer the same menu as @kbd{C-c C-x f}.
+@kindex C-c C-o
+@kindex mouse-1
+@kindex mouse-2
+@item C-c C-c  @r{or} mouse-1/2
+Footnote labels are also links to the corresponding definition/reference, and
+you can use the usual commands to follow these links.
 @end table
 @end table
 
 
 @node Orgstruct mode,  , Footnotes, Document Structure
 @node Orgstruct mode,  , Footnotes, Document Structure

+ 9 - 0
lisp/ChangeLog

@@ -1,3 +1,12 @@
+2009-01-02  Carsten Dominik  <carsten.dominik@gmail.com>
+
+	* org.el (org-set-font-lock-defaults): Trigger footnote
+	fontification.
+	(org-activate-footnote-links): New function.
+	(org-activate-links): New entry `footnote'.
+
+	* org-faces.el (org-footnote): New face.
+
 2009-01-01  Carsten Dominik  <carsten.dominik@gmail.com>
 2009-01-01  Carsten Dominik  <carsten.dominik@gmail.com>
 
 
 	* org-macs.el (org-re): Handle the [:word:] class.
 	* org-macs.el (org-re): Handle the [:word:] class.

+ 7 - 0
lisp/org-faces.el

@@ -239,6 +239,13 @@ column view defines special faces for each outline level.  See the file
   "Face for links."
   "Face for links."
   :group 'org-faces)
   :group 'org-faces)
 
 
+(defface org-footnote
+  '((((class color) (background light)) (:foreground "Purple" :underline t))
+    (((class color) (background dark)) (:foreground "Cyan" :underline t))
+    (t (:underline t)))
+  "Face for links."
+  :group 'org-faces)
+
 (defface org-ellipsis
 (defface org-ellipsis
   '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
   '((((class color) (background light)) (:foreground "DarkGoldenrod" :underline t))
     (((class color) (background dark)) (:foreground "LightGoldenrod" :underline t))
     (((class color) (background dark)) (:foreground "LightGoldenrod" :underline t))

+ 5 - 1
lisp/org-footnote.el

@@ -148,6 +148,7 @@ with start and label of the footnote if there is a definition at point."
     (if (not pos)
     (if (not pos)
 	(error "Cannot find definition of footnote %s" label)
 	(error "Cannot find definition of footnote %s" label)
       (goto-char pos)
       (goto-char pos)
+      (org-show-context 'link-search)
       (message "Edit definition and go back with `C-c &' or, if unique, with `C-c C-c'."))))
       (message "Edit definition and go back with `C-c &' or, if unique, with `C-c C-c'."))))
 
 
 (defun org-footnote-goto-next-reference (label)
 (defun org-footnote-goto-next-reference (label)
@@ -166,7 +167,10 @@ with start and label of the footnote if there is a definition at point."
 			 (re-search-forward re nil t))
 			 (re-search-forward re nil t))
 		    (and (goto-char (point-min))
 		    (and (goto-char (point-min))
 			 (re-search-forward re nil t)))))
 			 (re-search-forward re nil t)))))
-    (if pos (goto-char pos)
+    (if pos
+	(progn
+	  (goto-char pos)
+	  (org-show-context 'link-search))
       (error "Cannot find reference of footnote %s" label))))
       (error "Cannot find reference of footnote %s" label))))
 
 
 (defun org-footnote-normalize-label (label)
 (defun org-footnote-normalize-label (label)

+ 30 - 6
lisp/org.el

@@ -888,7 +888,7 @@ adaptive  Use relative path for files in the current directory and sub-
 	  (const noabbrev)
 	  (const noabbrev)
 	  (const adaptive)))
 	  (const adaptive)))
 
 
-(defcustom org-activate-links '(bracket angle plain radio tag date)
+(defcustom org-activate-links '(bracket angle plain radio tag date footnote)
   "Types of links that should be activated in Org-mode files.
   "Types of links that should be activated in Org-mode files.
 This is a list of symbols, each leading to the activation of a certain link
 This is a list of symbols, each leading to the activation of a certain link
 type.  In principle, it does not hurt to turn on most link types - there may
 type.  In principle, it does not hurt to turn on most link types - there may
@@ -901,15 +901,18 @@ plain     Plain links in normal text, no whitespace, like http://google.com.
 radio     Text that is matched by a radio target, see manual for details.
 radio     Text that is matched by a radio target, see manual for details.
 tag       Tag settings in a headline (link to tag search).
 tag       Tag settings in a headline (link to tag search).
 date      Time stamps (link to calendar).
 date      Time stamps (link to calendar).
+footnote  Footnote labels.
 
 
 Changing this variable requires a restart of Emacs to become effective."
 Changing this variable requires a restart of Emacs to become effective."
   :group 'org-link
   :group 'org-link
-  :type '(set (const :tag "Double bracket links (new style)" bracket)
+  :type '(set :greedy t
+	      (const :tag "Double bracket links (new style)" bracket)
 	      (const :tag "Angular bracket links (old style)" angular)
 	      (const :tag "Angular bracket links (old style)" angular)
 	      (const :tag "Plain text links" plain)
 	      (const :tag "Plain text links" plain)
 	      (const :tag "Radio target matches" radio)
 	      (const :tag "Radio target matches" radio)
 	      (const :tag "Tags" tag)
 	      (const :tag "Tags" tag)
-	      (const :tag "Timestamps" date)))
+	      (const :tag "Timestamps" date)
+	      (const :tag "Footnotes" footnote)))
 
 
 (defcustom org-make-link-description-function nil
 (defcustom org-make-link-description-function nil
   "Function to use to generate link descriptions from links. If
   "Function to use to generate link descriptions from links. If
@@ -3749,6 +3752,22 @@ will be prompted for."
 				   ))
 				   ))
 	t)))
 	t)))
 
 
+(defun org-activate-footnote-links (limit)
+  "Run through the buffer and add overlays to links."
+  (if (re-search-forward "\\[\\([0-9]+\\]\\|fn:[^ \t\r\n:]+?[]:]\\)" 
+			 limit t)
+      (progn
+	(add-text-properties (match-beginning 0) (match-end 0)
+			     (list 'mouse-face 'highlight
+				   'rear-nonsticky org-nonsticky-props
+				   'keymap org-mouse-map
+				   'help-echo
+				   (if (= (point-at-bol) (match-beginning 0))
+				       "Footnote definition"
+				     "Footnote reference")
+				   ))
+	t)))
+
 (defun org-activate-bracket-links (limit)
 (defun org-activate-bracket-links (limit)
   "Run through the buffer and add overlays to bracketed links."
   "Run through the buffer and add overlays to bracketed links."
   (if (re-search-forward org-bracket-link-regexp limit t)
   (if (re-search-forward org-bracket-link-regexp limit t)
@@ -4003,6 +4022,8 @@ between words."
 	   (if (memq 'bracket lk) '(org-activate-bracket-links (0 'org-link t)))
 	   (if (memq 'bracket lk) '(org-activate-bracket-links (0 'org-link t)))
 	   (if (memq 'radio lk) '(org-activate-target-links (0 'org-link t)))
 	   (if (memq 'radio lk) '(org-activate-target-links (0 'org-link t)))
 	   (if (memq 'date lk) '(org-activate-dates (0 'org-date t)))
 	   (if (memq 'date lk) '(org-activate-dates (0 'org-date t)))
+	   (if (memq 'footnote lk) '(org-activate-footnote-links
+				     (0 'org-footnote t)))
 	   '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t))
 	   '("^&?%%(.*\\|<%%([^>\n]*?>" (0 'org-sexp-date t))
 	   '(org-hide-wide-columns (0 nil append))
 	   '(org-hide-wide-columns (0 nil append))
 	   ;; TODO lines
 	   ;; TODO lines
@@ -6913,8 +6934,11 @@ application the system uses for this file type."
   (move-marker org-open-link-marker (point))
   (move-marker org-open-link-marker (point))
   (setq org-window-config-before-follow-link (current-window-configuration))
   (setq org-window-config-before-follow-link (current-window-configuration))
   (org-remove-occur-highlights nil nil t)
   (org-remove-occur-highlights nil nil t)
-  (if (org-at-timestamp-p t)
-      (org-follow-timestamp-link)
+  (cond
+   ((org-at-timestamp-p t) (org-follow-timestamp-link))
+   ((or (org-footnote-at-reference-p) (org-footnote-at-definition-p))
+    (org-footnote-action))
+   (t 
     (let (type path link line search (pos (point)))
     (let (type path link line search (pos (point)))
       (catch 'match
       (catch 'match
 	(save-excursion
 	(save-excursion
@@ -7060,7 +7084,7 @@ application the system uses for this file type."
 	    (error "Abort"))))
 	    (error "Abort"))))
 
 
        (t
        (t
-	(browse-url-at-point)))))
+	(browse-url-at-point))))))
   (move-marker org-open-link-marker nil)
   (move-marker org-open-link-marker nil)
   (run-hook-with-args 'org-follow-link-hook))
   (run-hook-with-args 'org-follow-link-hook))