Rewrite `org-edit-special' with Elements
* lisp/org.el (org-edit-special): Rewrite `org-edit-special' using Org Elements tools. Behaviour should be unchanged.
This commit is contained in:
parent
2fd88bfd56
commit
3ea93df5a6
66
lisp/org.el
66
lisp/org.el
|
@ -143,7 +143,7 @@ Stars are put in group 1 and the trimmed body in group 2.")
|
||||||
|
|
||||||
(declare-function org-element-at-point "org-element" (&optional keep-trail))
|
(declare-function org-element-at-point "org-element" (&optional keep-trail))
|
||||||
(declare-function org-element-type "org-element" (element))
|
(declare-function org-element-type "org-element" (element))
|
||||||
(declare-function org-element-context "org-element" ())
|
(declare-function org-element-context "org-element" (&optional element))
|
||||||
(declare-function org-element-contents "org-element" (element))
|
(declare-function org-element-contents "org-element" (element))
|
||||||
(declare-function org-element-property "org-element" (property element))
|
(declare-function org-element-property "org-element" (property element))
|
||||||
(declare-function org-element-map "org-element" (data types fun &optional info first-match no-recursion))
|
(declare-function org-element-map "org-element" (data types fun &optional info first-match no-recursion))
|
||||||
|
@ -19441,38 +19441,48 @@ See the individual commands for more information."
|
||||||
(eq 'fixed-width (org-element-type (org-element-at-point)))))
|
(eq 'fixed-width (org-element-type (org-element-at-point)))))
|
||||||
|
|
||||||
(defun org-edit-special (&optional arg)
|
(defun org-edit-special (&optional arg)
|
||||||
"Call a special editor for the stuff at point.
|
"Call a special editor for the element at point.
|
||||||
When at a table, call the formula editor with `org-table-edit-formulas'.
|
When at a table, call the formula editor with `org-table-edit-formulas'.
|
||||||
When in a source code block, call `org-edit-src-code'.
|
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 a fixed-width region, call `org-edit-fixed-width-region'.
|
||||||
When in an #+include line, visit the included file.
|
When at an #+INCLUDE keyword, visit the included file.
|
||||||
On a link, call `ffap' to visit the link at point.
|
On a link, call `ffap' to visit the link at point.
|
||||||
Otherwise, return a user error."
|
Otherwise, return an user error."
|
||||||
(interactive)
|
(interactive)
|
||||||
;; possibly prep session before editing source
|
(let ((element (org-element-at-point)))
|
||||||
(when (and (org-in-src-block-p) arg)
|
(case (org-element-type element)
|
||||||
(let* ((info (org-babel-get-src-block-info))
|
(src-block
|
||||||
(lang (nth 0 info))
|
(if (not arg) (org-edit-src-code)
|
||||||
(params (nth 2 info))
|
(let* ((info (org-babel-get-src-block-info))
|
||||||
(session (cdr (assoc :session params))))
|
(lang (nth 0 info))
|
||||||
(when (and info session) ;; we are in a source-code block with a session
|
(params (nth 2 info))
|
||||||
(funcall
|
(session (cdr (assq :session params))))
|
||||||
(intern (concat "org-babel-prep-session:" lang)) session params))))
|
(if (not session) (org-edit-src-code)
|
||||||
(cond ;; proceed with `org-edit-special'
|
;; At a src-block with a session and function called with
|
||||||
((save-excursion
|
;; an ARG: switch to the buffer related to the inferior
|
||||||
(beginning-of-line 1)
|
;; process.
|
||||||
(looking-at "\\(?:#\\+\\(?:setupfile\\|include\\):?[ \t]+\"?\\|[ \t]*<include\\>.*?file=\"\\)\\([^\"\n>]+\\)"))
|
(funcall (intern (concat "org-babel-prep-session:" lang))
|
||||||
(find-file (org-trim (match-string 1))))
|
session params)))))
|
||||||
((org-at-table.el-p) (org-edit-src-code))
|
(keyword
|
||||||
((or (org-at-table-p)
|
(if (equal (org-element-property :key element) "INCLUDE")
|
||||||
(save-excursion
|
(find-file
|
||||||
(beginning-of-line 1)
|
(org-remove-double-quotes
|
||||||
(let ((case-fold-search )) (looking-at "[ \t]*#\\+tblfm:"))))
|
(car (org-split-string (org-element-property :value element)))))
|
||||||
(call-interactively 'org-table-edit-formulas))
|
(user-error "No special environment to edit here")))
|
||||||
((org-in-block-p '("src" "example" "latex" "html")) (org-edit-src-code))
|
(table
|
||||||
((org-in-fixed-width-region-p) (org-edit-fixed-width-region))
|
(if (eq (org-element-property :type element) 'table.el)
|
||||||
((org-at-regexp-p org-any-link-re) (call-interactively 'ffap))
|
(org-edit-src-code)
|
||||||
(t (user-error "No special environment to edit here"))))
|
(call-interactively 'org-table-edit-formulas)))
|
||||||
|
;; Only Org tables contain `table-row' type elements.
|
||||||
|
(table-row (call-interactively 'org-table-edit-formulas))
|
||||||
|
((example-block export-block) (org-edit-src-code))
|
||||||
|
(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"))))))
|
||||||
|
|
||||||
(defvar org-table-coordinate-overlays) ; defined in org-table.el
|
(defvar org-table-coordinate-overlays) ; defined in org-table.el
|
||||||
(defun org-ctrl-c-ctrl-c (&optional arg)
|
(defun org-ctrl-c-ctrl-c (&optional arg)
|
||||||
|
|
Loading…
Reference in New Issue