summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2015-11-08 20:55:31 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2015-11-08 20:55:31 +0100
commit6c1f63b6a6af46dc2c6c5a1df14c99f637c1bbd1 (patch)
tree6e16ccb21b54782b45ccef5e1fe30d9869b147e8
parent10173ad6d610b6a98976950dd4ab21fcb2d967ac (diff)
downloadorg-mode-6c1f63b6a6af46dc2c6c5a1df14c99f637c1bbd1.tar.gz
org-src: Allow to edit remotely inline src blocks
* lisp/org-src.el (org-edit-inline-src-code): New function. (org-src--contents-area): Handle inline src blocks. * lisp/org.el (org-edit-special): When on an inline src block, edit it.
-rw-r--r--lisp/org-src.el44
-rwxr-xr-xlisp/org.el45
2 files changed, 67 insertions, 22 deletions
diff --git a/lisp/org-src.el b/lisp/org-src.el
index b660a26..e4b0d1c 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -292,6 +292,12 @@ where BEG and END are buffer positions and CONTENTS is a string."
(search-forward "]")))
(end (or (org-element-property :contents-end datum) beg)))
(list beg end (buffer-substring-no-properties beg end))))
+ ((eq type 'inline-src-block)
+ (let ((beg (progn (goto-char (org-element-property :begin datum))
+ (search-forward "{" (line-end-position) t)))
+ (end (progn (goto-char (org-element-property :end datum))
+ (search-backward "}" (line-beginning-position) t))))
+ (list beg end (buffer-substring-no-properties beg end))))
((org-element-property :contents-begin datum)
(let ((beg (org-element-property :contents-begin datum))
(end (org-element-property :contents-end datum)))
@@ -871,6 +877,44 @@ name of the sub-editing buffer."
(funcall edit-prep-func babel-info))))
t)))
+(defun org-edit-inline-src-code ()
+ "Edit inline source code at point."
+ (interactive)
+ (let ((context (org-element-context)))
+ (unless (and (eq (org-element-type context) 'inline-src-block)
+ (org-src--on-datum-p context))
+ (user-error "Not on inline source code"))
+ (let* ((lang (org-element-property :language context))
+ (lang-f (org-src--get-lang-mode lang))
+ (babel-info (org-babel-get-src-block-info 'light))
+ (ind (save-excursion
+ (goto-char (org-element-property :begin context))
+ (search-forward "{" (line-end-position) t)
+ (current-column)))
+ deactivate-mark)
+ (unless (functionp lang-f) (error "No such language mode: %s" lang-f))
+ (org-src--edit-element
+ context
+ (org-src--construct-edit-buffer-name (buffer-name) lang)
+ lang-f
+ (lambda ()
+ ;; Inline src blocks are limited to one line.
+ (while (re-search-forward "\n[ \t]*" nil t) (replace-match " "))
+ ;; Trim contents.
+ (goto-char (point-min))
+ (skip-chars-forward " \t")
+ (delete-region (point-min) (point))
+ (goto-char (point-max))
+ (skip-chars-backward " \t")
+ (delete-region (point) (point-max))))
+ ;; Finalize buffer.
+ (setq-local org-src--babel-info babel-info)
+ (setq-local org-src--preserve-indentation t)
+ (let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang))))
+ (when (fboundp edit-prep-func) (funcall edit-prep-func babel-info)))
+ ;; Return success.
+ t)))
+
(defun org-edit-fixed-width-region ()
"Edit the fixed-width ASCII drawing at point.
diff --git a/lisp/org.el b/lisp/org.el
index 6e641c3..416e573 100755
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -20987,21 +20987,21 @@ Otherwise, return a user error."
(let ((element (org-element-at-point)))
(assert (not buffer-read-only) nil
"Buffer is read-only: %s" (buffer-name))
- (case (org-element-type element)
- (src-block
+ (pcase (org-element-type element)
+ (`src-block
(if (not arg) (org-edit-src-code)
- (let* ((info (org-babel-get-src-block-info))
- (lang (nth 0 info))
- (params (nth 2 info))
- (session (cdr (assq :session params))))
- (if (not session) (org-edit-src-code)
- ;; At a src-block with a session and function called with
- ;; an ARG: switch to the buffer related to the inferior
- ;; process.
- (switch-to-buffer
+ (let* ((info (org-babel-get-src-block-info))
+ (lang (nth 0 info))
+ (params (nth 2 info))
+ (session (cdr (assq :session params))))
+ (if (not session) (org-edit-src-code)
+ ;; At a src-block with a session and function called with
+ ;; an ARG: switch to the buffer related to the inferior
+ ;; process.
+ (switch-to-buffer
(funcall (intern (concat "org-babel-prep-session:" lang))
session params))))))
- (keyword
+ (`keyword
(if (member (org-element-property :key element) '("INCLUDE" "SETUPFILE"))
(org-open-link-from-string
(format "[[%s]]"
@@ -21015,23 +21015,24 @@ Otherwise, return a user error."
(match-string 0 value))
(t (user-error "No valid file specified")))))))
(user-error "No special environment to edit here")))
- (table
+ (`table
(if (eq (org-element-property :type element) 'table.el)
(org-edit-table.el)
(call-interactively 'org-table-edit-formulas)))
;; Only Org tables contain `table-row' type elements.
- (table-row (call-interactively 'org-table-edit-formulas))
- (example-block (org-edit-src-code))
- (export-block (org-edit-export-block))
- (fixed-width (org-edit-fixed-width-region))
- (otherwise
+ (`table-row (call-interactively 'org-table-edit-formulas))
+ (`example-block (org-edit-src-code))
+ (`export-block (org-edit-export-block))
+ (`fixed-width (org-edit-fixed-width-region))
+ (_
;; 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"))))))))
+ (pcase (org-element-type context)
+ (`footnote-reference (org-edit-footnote-reference))
+ (`inline-src-block (org-edit-inline-src-code))
+ (`link (call-interactively #'ffap))
+ (_ (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)