summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2015-04-26 10:40:30 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2015-04-26 11:44:35 +0200
commitca2b398396f701f127a1a758e8be0ffc03c18286 (patch)
tree62776a4ae006b7fe9e75b59c76bc3c594f1dedec
parent58af85a4a2a11bb2ff611786ee921cd12aeba187 (diff)
downloadorg-mode-ca2b398396f701f127a1a758e8be0ffc03c18286.tar.gz
org-src: Allow editing footnote definitions
* lisp/org-src.el (org-src--element-contents-area): Make a special case for footnote definitions. (org-edit-footnote-reference): New function. * lisp/org.el (org-edit-special): Use new function.
-rw-r--r--lisp/org-src.el73
-rwxr-xr-xlisp/org.el15
2 files changed, 73 insertions, 15 deletions
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 11354d5..b97c38b 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -271,15 +271,30 @@ which see. BEG and END are buffer positions."
"Return contents boundaries of ELEMENT.
Return value is a pair (BEG . END) where BEG and END are buffer
positions."
- (let ((blockp (memq (org-element-type element)
- '(example-block export-block src-block))))
- (cons (org-with-wide-buffer
- (goto-char (org-element-property :post-affiliated element))
- (if blockp (line-beginning-position 2) (point)))
- (org-with-wide-buffer
- (goto-char (org-element-property :end element))
- (skip-chars-backward " \r\t\n")
- (line-beginning-position (if blockp 1 2))))))
+ (let ((type (org-element-type element)))
+ (cond
+ ((eq type 'footnote-definition)
+ (cons (org-with-wide-buffer
+ (goto-char (org-element-property :post-affiliated element))
+ (search-forward "]"))
+ (org-element-property :contents-end element)))
+ ((org-element-property :contents-begin element)
+ (cons (org-element-property :contents-begin element)
+ (org-element-property :contents-end element)))
+ ((memq type '(example-block export-block src-block))
+ (cons (org-with-wide-buffer
+ (goto-char (org-element-property :post-affiliated element))
+ (line-beginning-position 2))
+ (org-with-wide-buffer
+ (goto-char (org-element-property :end element))
+ (skip-chars-backward " \r\t\n")
+ (line-beginning-position 1))))
+ (t
+ (cons (org-element-property :post-affiliated element)
+ (org-with-wide-buffer
+ (goto-char (org-element-property :end element))
+ (skip-chars-backward " \r\t\n")
+ (line-beginning-position 2)))))))
(defun org-src--make-source-overlay (beg end edit-buffer)
"Create overlay between BEG and END positions and return it.
@@ -662,6 +677,46 @@ If BUFFER is non-nil, test it instead."
org-src-window-setup)
(org-pop-to-buffer-same-window buffer))))
+(defun org-edit-footnote-reference ()
+ "Edit definition of footnote reference at point."
+ (interactive)
+ (let ((context (org-element-context)))
+ (cond ((not (and (eq (org-element-type context) 'footnote-reference)
+ (< (point)
+ (org-with-wide-buffer
+ (goto-char (org-element-property :end context))
+ (skip-chars-backward " \t")
+ (point)))))
+ (user-error "Not on a footnote reference"))
+ ((eq (org-element-property :type context) 'inline)
+ (user-error "Cannot edit inline footnotes"))
+ (t
+ (let* ((label (org-element-property :label context))
+ (definition
+ (org-with-wide-buffer
+ (org-footnote-goto-definition label)
+ (beginning-of-line)
+ (org-element-at-point))))
+ (org-src--edit-element
+ definition (format "*Edit footnote [%s]*" label)
+ #'org-mode
+ (lambda () (delete-region (point) (search-forward "]")))
+ (concat
+ (org-propertize (format "[%s]" label)
+ 'read-only "Cannot edit footnote label"
+ 'front-sticky t
+ 'rear-nonsticky t)
+ (org-with-wide-buffer
+ (buffer-substring-no-properties
+ (progn
+ (goto-char (org-element-property :contents-begin definition))
+ (skip-chars-backward " \r\t\n")
+ (point))
+ (org-element-property :contents-end definition))))
+ 'remote))
+ ;; Report success.
+ t))))
+
(defun org-edit-table.el ()
"Edit \"table.el\" table at point.
diff --git a/lisp/org.el b/lisp/org.el
index 526bfc9..606477b 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -20868,6 +20868,7 @@ When in a source code block, call `org-edit-src-code'.
When in a fixed-width region, call `org-edit-fixed-width-region'.
When in an export block, call `org-edit-export-block'.
When at an #+INCLUDE keyword, visit the included file.
+When at a footnote reference, call `org-edit-footnote-reference'
On a link, call `ffap' to visit the link at point.
Otherwise, return a user error."
(interactive "P")
@@ -20908,15 +20909,17 @@ Otherwise, return a user error."
(call-interactively 'org-table-edit-formulas)))
;; Only Org tables contain `table-row' type elements.
(table-row (call-interactively 'org-table-edit-formulas))
- ((example-block src-block) (org-edit-src-code))
+ (example-block (org-edit-src-code))
(export-block (org-edit-export-block))
(fixed-width (org-edit-fixed-width-region))
(otherwise
- ;; No notable element at point. Though, we may be at a link,
- ;; which is an object. Thus, scan deeper.
- (if (eq (org-element-type (org-element-context element)) 'link)
- (call-interactively 'ffap)
- (user-error "No special environment to edit here"))))))
+ ;; No notable element at point. Though, we may be at a link or
+ ;; a footnote reference, which are objects. Thus, scan deeper.
+ (let ((context (org-element-context element)))
+ (case (org-element-type context)
+ (link (call-interactively #'ffap))
+ (footnote-reference (org-edit-footnote-reference))
+ (t (user-error "No special environment to edit here"))))))))
(defvar org-table-coordinate-overlays) ; defined in org-table.el
(defun org-ctrl-c-ctrl-c (&optional arg)