diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index df3406780..806b04fc7 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -63,6 +63,12 @@ to the following list as their first argument. ** New features +*** ~org-edit-special~ can edit LaTeX environments + +Using ~C-c '~ on a LaTeX environment opens a sub-editing buffer. By +default, major mode in that buffer is ~latex-mode~, but it can be +changed by configuring ~org-src-lang-modes~. + *** Agenda **** New variable : ~org-agenda-show-future-repeats~ **** New variable : ~org-agenda-prefer-last-repeat~ diff --git a/lisp/org-src.el b/lisp/org-src.el index b45306ef4..d07655e6a 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -332,7 +332,7 @@ where BEG and END are buffer positions and CONTENTS is a string." (skip-chars-backward " \r\t\n") (line-beginning-position 1)) (org-element-property :value datum))) - ((memq type '(fixed-width table)) + ((memq type '(fixed-width latex-environment table)) (let ((beg (org-element-property :post-affiliated datum)) (end (progn (goto-char (org-element-property :end datum)) (skip-chars-backward " \r\t\n") @@ -853,6 +853,28 @@ Throw an error when not at such a table." (table-recognize) t)) +(defun org-edit-latex-environment () + "Edit LaTeX environment at point. +\\ +The LaTeX environment is copied into a new buffer. Major mode is +set to the one associated to \"latex\" in `org-src-lang-modes', +or to `latex-mode' if there is none. + +When done, exit with `\\[org-edit-src-exit]'. The edited text \ +will then replace +the LaTeX environment in the Org mode buffer." + (interactive) + (let ((element (org-element-at-point))) + (unless (and (eq (org-element-type element) 'latex-environment) + (org-src--on-datum-p element)) + (user-error "Not in a LaTeX environment")) + (org-src--edit-element + element + (org-src--construct-edit-buffer-name (buffer-name) "LaTeX environment") + (org-src--get-lang-mode "latex") + t) + t)) + (defun org-edit-export-block () "Edit export block at point. \\ diff --git a/lisp/org.el b/lisp/org.el index 38fce7054..8eca95839 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -20920,6 +20920,7 @@ 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 fixed-width region, call `org-edit-fixed-width-region'. When in an export block, call `org-edit-export-block'. +When in a LaTeX environment, call `org-edit-latex-environment'. 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. @@ -20964,6 +20965,7 @@ Otherwise, return a user error." (`example-block (org-edit-src-code)) (`export-block (org-edit-export-block)) (`fixed-width (org-edit-fixed-width-region)) + (`latex-environment (org-edit-latex-environment)) (_ ;; No notable element at point. Though, we may be at a link or ;; a footnote reference, which are objects. Thus, scan deeper.