update packages

This commit is contained in:
2025-06-22 17:08:08 +02:00
parent 54e5633369
commit 16a0a6db93
558 changed files with 68349 additions and 26568 deletions

View File

@@ -1,11 +1,11 @@
;;; org-src.el --- Source code examples in Org -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2004-2023 Free Software Foundation, Inc.
;; Copyright (C) 2004-2025 Free Software Foundation, Inc.
;;
;; Author: Carsten Dominik <carsten.dominik@gmail.com>
;; Bastien Guerry <bzg@gnu.org>
;; Dan Davison <davison at stats dot ox dot ac dot uk>
;; Keywords: outlines, hypermedia, calendar, wp
;; Keywords: outlines, hypermedia, calendar, text
;; URL: https://orgmode.org
;;
;; This file is part of GNU Emacs.
@@ -39,6 +39,7 @@
(require 'org-macs)
(require 'org-compat)
(require 'org-keys)
(require 'sh-script)
(declare-function org--get-expected-indentation "org" (element contentsp))
(declare-function org-mode "org" ())
@@ -47,11 +48,19 @@
(declare-function org-element-at-point "org-element" (&optional pom cached-only))
(declare-function org-element-class "org-element" (datum &optional parent))
(declare-function org-element-context "org-element" (&optional element))
(declare-function org-element-lineage "org-element"
(declare-function org-element-lineage "org-element-ast"
(blob &optional types with-self))
(declare-function org-element--parse-paired-brackets "org-element" (char))
(declare-function org-element-property "org-element" (property element))
(declare-function org-element-type "org-element" (element))
(declare-function org-element-property "org-element-ast" (property node))
(declare-function org-element-begin "org-element" (node))
(declare-function org-element-end "org-element" (node))
(declare-function org-element-contents-begin "org-element" (node))
(declare-function org-element-contents-end "org-element" (node))
(declare-function org-element-post-affiliated "org-element" (node))
(declare-function org-element-post-blank "org-element" (node))
(declare-function org-element-parent "org-element-ast" (node))
(declare-function org-element-type "org-element-ast" (node &optional anonymous))
(declare-function org-element-type-p "org-element-ast" (node types))
(declare-function org-footnote-goto-definition "org-footnote"
(label &optional location))
@@ -110,15 +119,16 @@ These are the regions where each line starts with a colon."
(defcustom org-src-preserve-indentation nil
"If non-nil preserve leading whitespace characters on export.
\\<org-mode-map>
If non-nil leading whitespace characters in source code blocks
are preserved on export, and when switching between the org
buffer and the language mode edit buffer.
When this variable is nil, after editing with `\\[org-edit-src-code]',
the minimum (across-lines) number of leading whitespace characters
are removed from all lines, and the code block is uniformly indented
according to the value of `org-edit-src-content-indentation'."
If non-nil leading whitespace characters in source code blocks are
preserved on export, or adjusted while indenting or when switching
between the org buffer and the language mode edit buffer.
When this variable is nil, while indenting with `\\[org-indent-block]'
or after editing with `\\[org-edit-src-code]', the minimum (across-lines)
number of leading whitespace characters are removed from all lines,
and the code block is uniformly indented according to the value of
`org-edit-src-content-indentation'."
:group 'org-edit-structure
:type 'boolean)
@@ -194,11 +204,17 @@ You may want to use this hook for example to turn off `outline-minor-mode'
or similar things which you want to have when editing a source code file,
but which mess up the display of a snippet in Org exported files.")
(defun org-src--get-known-shells ()
"List all the shells in `sh-ancestor-alist' for `org-src-lang-modes'.
The shells are associated with `sh-mode'."
(mapcar
(lambda (shell) (cons (symbol-name shell) 'sh))
(delete-dups (org--flatten-tree sh-ancestor-alist))))
(defcustom org-src-lang-modes
'(("C" . c)
`(("C" . c)
("C++" . c++)
("asymptote" . asy)
("bash" . sh)
("beamer" . latex)
("calc" . fundamental)
("cpp" . c++)
@@ -208,9 +224,10 @@ but which mess up the display of a snippet in Org exported files.")
("elisp" . emacs-lisp)
("ocaml" . tuareg)
("screen" . shell-script)
("shell" . sh)
("sqlite" . sql)
("toml" . conf-toml))
("toml" . conf-toml)
("shell" . sh)
,@(org-src--get-known-shells))
"Alist mapping languages to their major mode.
The key is the language name. The value is the mode name, as
@@ -221,11 +238,11 @@ not the case, this variable provides a way to simplify things on
the user side. For example, there is no `ocaml-mode' in Emacs,
but the mode to use is `tuareg-mode'."
:group 'org-edit-structure
:package-version '(Org . "9.6")
:package-version '(Org . "9.7")
:type '(repeat
(cons
(string "Language name")
(symbol "Major mode"))))
(string :tag "Language name")
(symbol :tag "Major mode"))))
(defcustom org-src-block-faces nil
"Alist of faces to be used for source-block.
@@ -233,7 +250,8 @@ Each element is a cell of the format
(\"language\" FACE)
Where FACE is either a defined face or an anonymous face.
Where FACE is either a defined face or an anonymous face. Empty
language string refers to source blocks without specified language.
For instance, the following would color the background of
emacs-lisp source blocks and python source blocks in purple and
@@ -247,7 +265,6 @@ green, respectability.
(choice
(face :tag "Face")
(sexp :tag "Anonymous face"))))
:version "26.1"
:package-version '(Org . "9.0"))
(defcustom org-src-tab-acts-natively t
@@ -310,9 +327,6 @@ is 0.")
"File name associated to Org source buffer, or nil.")
(put 'org-src-source-file-name 'permanent-local t)
(defvar-local org-src--preserve-blank-line nil)
(put 'org-src--preserve-blank-line 'permanent-local t)
(defun org-src--construct-edit-buffer-name (org-buffer-name lang)
"Construct the buffer name for a source editing buffer.
Format is \"*Org Src ORG-BUFFER-NAME[ LANG ]*\"."
@@ -369,36 +383,36 @@ where BEG and END are buffer positions and CONTENTS is a string."
(cond
((eq type 'footnote-definition)
(let* ((beg (progn
(goto-char (org-element-property :post-affiliated datum))
(goto-char (org-element-post-affiliated datum))
(search-forward "]")))
(end (or (org-element-property :contents-end datum) beg)))
(end (or (org-element-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))
(let ((beg (progn (goto-char (org-element-begin datum))
(search-forward "{" (line-end-position) t)))
(end (progn (goto-char (org-element-property :end datum))
(end (progn (goto-char (org-element-end datum))
(search-backward "}" (line-beginning-position) t))))
(list beg end (buffer-substring-no-properties beg end))))
((eq type 'latex-fragment)
(let ((beg (org-element-property :begin datum))
(end (org-with-point-at (org-element-property :end datum)
(let ((beg (org-element-begin datum))
(end (org-with-point-at (org-element-end datum)
(skip-chars-backward " \t")
(point))))
(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)))
((org-element-contents-begin datum)
(let ((beg (org-element-contents-begin datum))
(end (org-element-contents-end datum)))
(list beg end (buffer-substring-no-properties beg end))))
((memq type '(example-block export-block src-block comment-block))
(list (progn (goto-char (org-element-property :post-affiliated datum))
(list (progn (goto-char (org-element-post-affiliated datum))
(line-beginning-position 2))
(progn (goto-char (org-element-property :end datum))
(progn (goto-char (org-element-end datum))
(skip-chars-backward " \r\t\n")
(line-beginning-position 1))
(org-element-property :value datum)))
((memq type '(fixed-width latex-environment table))
(let ((beg (org-element-property :post-affiliated datum))
(end (progn (goto-char (org-element-property :end datum))
(let ((beg (org-element-post-affiliated datum))
(end (progn (goto-char (org-element-end datum))
(skip-chars-backward " \r\t\n")
(line-beginning-position 2))))
(list beg
@@ -439,58 +453,89 @@ END."
"Non-nil when point is on DATUM.
DATUM is an element or an object. Consider blank lines or white
spaces after it as being outside."
(and (>= (point) (org-element-property :begin datum))
(and (>= (point) (org-element-begin datum))
(<= (point)
(org-with-wide-buffer
(goto-char (org-element-property :end datum))
(skip-chars-backward " \r\t\n")
(if (eq (org-element-class datum) 'element)
(line-end-position)
(point))))))
(org-with-wide-buffer
(goto-char (org-element-end datum))
(skip-chars-backward " \r\t\n")
(if (eq (org-element-class datum) 'element)
(line-end-position)
(point))))))
(defun org-src--contents-for-write-back (write-back-buf)
"Populate WRITE-BACK-BUF with contents in the appropriate format.
Assume point is in the corresponding edit buffer."
(let ((indentation-offset
(if org-src--preserve-indentation 0
(+ (or org-src--block-indentation 0)
(if (memq org-src--source-type '(example-block src-block))
org-src--content-indentation
0))))
(use-tabs? (and (> org-src--tab-width 0) t))
(preserve-fl (eq org-src--source-type 'latex-fragment))
(source-tab-width org-src--tab-width)
(contents (org-with-wide-buffer
(let ((eol (line-end-position)))
(list (buffer-substring (point-min) eol)
(buffer-substring eol (point-max))))))
(write-back org-src--allow-write-back)
(preserve-blank-line org-src--preserve-blank-line)
marker)
(defun org-src-preserve-indentation-p (&optional node)
"Non-nil when indentation should be preserved within NODE.
When NODE is not passed, assume element at point."
(let ((node (or node (org-element-at-point))))
(and (org-element-type-p node '(example-block src-block))
(or (org-element-property :preserve-indent node)
org-src-preserve-indentation))))
(defun org-src--contents-for-write-back-1
( write-back-buf contents
&optional indentation-offset preserve-fl source-tab-width write-back)
"Populate WRITE-BACK-BUF with CONTENTS in the appropriate format.
INDENTATION-OFFSET, when non-nil is additional indentation to be applied
to all the lines. PRESERVE-FL means that first line should not be
indented (useful for inline blocks contents that belong to paragraph).
The original indentation, if any, is not altered.
TAB-WIDTH is `tab-width' to be used when indenting. The value of 0
means that tabs should not be used.
WRITE-BACK, when non-nil, is a function to be called with point at
WRITE-BACK-BUF after inserting the original contents, but before
applying extra indentation."
(let ((use-tabs? (and (> source-tab-width 0) t))
indent-str)
(with-current-buffer write-back-buf
;; Reproduce indentation parameters from source buffer.
(setq indent-tabs-mode use-tabs?)
(when (> source-tab-width 0) (setq tab-width source-tab-width))
;; Apply WRITE-BACK function on edit buffer contents.
(insert (org-no-properties (car contents)))
(setq marker (point-marker))
(insert (org-no-properties (car (cdr contents))))
(insert (org-no-properties contents))
(goto-char (point-min))
(when (functionp write-back) (save-excursion (funcall write-back)))
;; Add INDENTATION-OFFSET to every line in buffer,
;; unless indentation is meant to be preserved.
(when (> indentation-offset 0)
(when preserve-fl (forward-line))
(when (and indentation-offset (> indentation-offset 0))
;; The exact sequence of tabs and spaces used to indent
;; up to `indentation-offset' in the Org buffer.
(setq indent-str
(with-temp-buffer
;; Reproduce indentation parameters.
(setq indent-tabs-mode use-tabs?)
(when (> source-tab-width 0)
(setq tab-width source-tab-width))
(indent-to indentation-offset)
(buffer-string)))
;; LaTeX-fragments are inline. Do not add indentation to their
;; first line.
(when preserve-fl (forward-line))
(while (not (eobp))
(skip-chars-forward " \t")
(when (or (not (eolp)) ; not a blank line
(and (eq (point) (marker-position marker)) ; current line
preserve-blank-line))
(let ((i (current-column)))
(delete-region (line-beginning-position) (point))
(indent-to (+ i indentation-offset))))
(forward-line)))
(set-marker marker nil))))
;; Keep empty src lines empty, even when src block is
;; indented on Org side.
;; See https://list.orgmode.org/725763.1632663635@apollo2.minshall.org/T/
(when (not (eolp)) ; not an empty line
(insert indent-str))
(forward-line))))))
(defun org-src--contents-for-write-back (write-back-buf)
"Populate WRITE-BACK-BUF with contents in the appropriate format.
Assume point is in the corresponding edit buffer."
(org-src--contents-for-write-back-1
write-back-buf
;; CONTENTS
(org-with-wide-buffer (buffer-string))
;; INDENTATION
(if org-src--preserve-indentation 0
(+ (or org-src--block-indentation 0)
(if (memq org-src--source-type '(example-block src-block))
org-src--content-indentation
0)))
;; PRESERVE-FL
(eq org-src--source-type 'latex-fragment)
;; TAB-WIDTH
org-src--tab-width
;; WRITE-BACK
org-src--allow-write-back))
(defun org-src--edit-element
(datum name &optional initialize write-back contents remote)
@@ -532,24 +577,16 @@ Leave point in edit buffer."
(source-file-name (buffer-file-name (buffer-base-buffer)))
(source-tab-width (if indent-tabs-mode tab-width 0))
(type (org-element-type datum))
(block-ind (org-with-point-at (org-element-property :begin datum)
(block-ind (org-with-point-at (org-element-begin datum)
(cond
((save-excursion (skip-chars-backward " \t") (bolp))
(org-current-text-indentation))
((org-element-property :parent datum)
((org-element-parent datum)
(org--get-expected-indentation
(org-element-property :parent datum) nil))
(org-element-parent datum) nil))
(t (org-current-text-indentation)))))
(content-ind org-edit-src-content-indentation)
(blank-line (save-excursion (beginning-of-line)
(looking-at-p "^[[:space:]]*$")))
(empty-line (and blank-line (looking-at-p "^$")))
(preserve-blank-line (or (and blank-line (not empty-line))
(and empty-line (= (+ block-ind content-ind) 0))))
(preserve-ind
(and (memq type '(example-block src-block))
(or (org-element-property :preserve-indent datum)
org-src-preserve-indentation)))
(preserve-ind (org-src-preserve-indentation-p datum))
;; Store relative positions of mark (if any) and point
;; within the edited area.
(point-coordinates (and (not remote)
@@ -576,7 +613,7 @@ Leave point in edit buffer."
;; Initialize buffer.
(when (functionp initialize)
(let ((org-inhibit-startup t))
(condition-case e
(condition-case-unless-debug e
(funcall initialize)
(error (message "Initialization fails with: %S"
(error-message-string e))))))
@@ -595,7 +632,6 @@ Leave point in edit buffer."
(setq org-src--overlay overlay)
(setq org-src--allow-write-back write-back)
(setq org-src-source-file-name source-file-name)
(setq org-src--preserve-blank-line preserve-blank-line)
;; Start minor mode.
(org-src-mode)
;; Clear undo information so we cannot undo back to the
@@ -627,9 +663,9 @@ Leave point in edit buffer."
(defvar org-src-fontify-natively) ; Defined in org.el
(defun org-src-font-lock-fontify-block (lang start end)
"Fontify code block between START and END using LANG's syntax.
This function is called by Emacs' automatic fontification, as long
This function is called by Emacs's automatic fontification, as long
as `org-src-fontify-natively' is non-nil."
(let ((modified (buffer-modified-p)))
(let ((modified (buffer-modified-p)) native-tab-width)
(remove-text-properties start end '(face nil))
(let ((lang-mode (org-src-get-lang-mode lang)))
(when (fboundp lang-mode)
@@ -643,8 +679,11 @@ as `org-src-fontify-natively' is non-nil."
;; Add string and a final space to ensure property change.
(insert string " "))
(unless (eq major-mode lang-mode) (funcall lang-mode))
(setq native-tab-width tab-width)
(font-lock-ensure)
(let ((pos (point-min)) next)
(let ((pos (point-min)) next
;; Difference between positions here and in org-buffer.
(offset (- start (point-min))))
(while (setq next (next-property-change pos))
;; Handle additional properties from font-lock, so as to
;; preserve, e.g., composition.
@@ -658,7 +697,7 @@ as `org-src-fontify-natively' is non-nil."
(when new-prop
(if (not (eq prop 'invisible))
(put-text-property
(+ start (1- pos)) (1- (+ start next)) prop new-prop
(+ offset pos) (+ offset next) prop new-prop
org-buffer)
;; Special case. `invisible' text property may
;; clash with Org folding. Do not assign
@@ -690,7 +729,7 @@ as `org-src-fontify-natively' is non-nil."
(when invisibility-spec
(add-to-invisibility-spec invisibility-spec))
(put-text-property
(+ start (1- pos)) (1- (+ start next))
(+ offset pos) (+ offset next)
'org-src-invisible new-prop
org-buffer)))))))
(setq pos next)))
@@ -700,8 +739,22 @@ as `org-src-fontify-natively' is non-nil."
(when (or (facep src-face) (listp src-face))
(font-lock-append-text-property start end 'face src-face))
(font-lock-append-text-property start end 'face 'org-block))
;; Clear abbreviated link folding.
(org-fold-region start end nil 'org-link)
;; Display native tab indentation characters as spaces
(when native-tab-width
(save-excursion
(goto-char start)
(let ((indent-offset
(if (org-src-preserve-indentation-p) 0
(+ (progn (backward-char)
(org-current-text-indentation))
org-edit-src-content-indentation))))
(while (re-search-forward "^[ ]*\t" end t)
(let* ((b (and (eq indent-offset (move-to-column indent-offset))
(point)))
(e (progn (skip-chars-forward "\t") (point)))
(s (and b (make-string (* (- e b) native-tab-width) ? ))))
(when (and b (< b e)) (add-text-properties b e `(display ,s)))
(forward-char))))))
(add-text-properties
start end
'(font-lock-fontified t fontified t font-lock-multiline t))
@@ -709,7 +762,7 @@ as `org-src-fontify-natively' is non-nil."
(defun org-fontify-inline-src-blocks (limit)
"Try to apply `org-fontify-inline-src-blocks-1'."
(condition-case nil
(condition-case-unless-debug nil
(org-fontify-inline-src-blocks-1 limit)
(error (message "Org mode fontification error in %S at %d"
(current-buffer)
@@ -724,12 +777,9 @@ as `org-src-fontify-natively' is non-nil."
(lang-beg (match-beginning 1))
(lang-end (match-end 1))
pt)
(font-lock-append-text-property
lang-beg lang-end 'face 'org-meta-line)
(font-lock-append-text-property
beg lang-beg 'face 'shadow)
(font-lock-append-text-property
beg lang-end 'face 'org-inline-src-block)
(add-face-text-property beg lang-end 'org-inline-src-block)
(add-face-text-property beg lang-beg 'shadow)
(add-face-text-property lang-beg lang-end 'org-meta-line)
(setq pt (goto-char lang-end))
;; `org-element--parse-paired-brackets' doesn't take a limit, so to
;; prevent it searching the entire rest of the buffer we temporarily
@@ -741,13 +791,11 @@ as `org-src-fontify-natively' is non-nil."
(point)))
(point-max))))
(when (ignore-errors (org-element--parse-paired-brackets ?\[))
(font-lock-append-text-property
pt (point) 'face 'org-inline-src-block)
(add-face-text-property pt (point) 'org-inline-src-block)
(setq pt (point)))
(when (ignore-errors (org-element--parse-paired-brackets ?\{))
(remove-text-properties pt (point) '(face nil))
(font-lock-append-text-property
pt (1+ pt) 'face '(org-inline-src-block shadow))
(add-face-text-property pt (1+ pt) '(org-inline-src-block shadow))
(unless (= (1+ pt) (1- (point)))
(if org-src-fontify-natively
(org-src-font-lock-fontify-block
@@ -755,8 +803,7 @@ as `org-src-fontify-natively' is non-nil."
(1+ pt) (1- (point)))
(font-lock-append-text-property
(1+ pt) (1- (point)) 'face 'org-inline-src-block)))
(font-lock-append-text-property
(1- (point)) (point) 'face '(org-inline-src-block shadow))
(add-face-text-property (1- (point)) (point) '(org-inline-src-block shadow))
(setq pt (point)))))
t)))
@@ -874,7 +921,6 @@ INFO should be a list similar in format to the return value of
(interactive)
(let ((session (cdr (assq :session (nth 2 info)))))
(and session (not (string= session "none"))
(org-babel-comint-buffer-livep session)
(let ((f (intern (format "org-babel-%s-associate-session"
(nth 0 info)))))
(and (fboundp f) (funcall f session))))))
@@ -905,16 +951,16 @@ remotely with point temporarily at the start of the code block in
the Org buffer.
This command is not bound to a key by default, to avoid conflicts
with language major mode bindings. To bind it to C-c @ in all
with language major mode bindings. To bind it to \\`C-c @' in all
language major modes, you could use
(add-hook \\='org-src-mode-hook
(lambda () (define-key org-src-mode-map \"\\C-c@\"
\\='org-src-do-key-sequence-at-code-block)))
In that case, for example, C-c @ t issued in code edit buffers
would tangle the current Org code block, C-c @ e would execute
the block and C-c @ h would display the other available
In that case, for example, \\`C-c @ t' issued in code edit buffers
would tangle the current Org code block, \\`C-c @ e' would execute
the block and \\`C-c @ h' would display the other available
Org-babel commands."
(interactive "kOrg-babel key: ")
(if (equal key (kbd "C-g")) (keyboard-quit)
@@ -961,7 +1007,7 @@ Raise an error when current buffer is not a source editing buffer."
(`current-window (pop-to-buffer-same-window buffer))
(`other-window
(let ((cur-win (selected-window)))
(org-switch-to-buffer-other-window buffer)
(switch-to-buffer-other-window buffer)
(when (eq context 'exit) (quit-restore-window cur-win))))
(`split-window-below
(if (eq context 'exit)
@@ -984,9 +1030,10 @@ Raise an error when current buffer is not a source editing buffer."
(pop-to-buffer-same-window buffer))
(_ (switch-to-buffer-other-frame buffer))))
(`reorganize-frame
(when (eq context 'edit) (delete-other-windows))
(org-switch-to-buffer-other-window buffer)
(when (eq context 'exit) (delete-other-windows)))
(pcase context
(`edit (pop-to-buffer buffer '(org-display-buffer-split)))
(`exit (pop-to-buffer buffer '(org-display-buffer-full-frame)))
(_ (switch-to-buffer-other-window buffer))))
(`switch-invisibly (set-buffer buffer))
(_
(message "Invalid value %s for `org-src-window-setup'"
@@ -1031,7 +1078,7 @@ A coderef format regexp can only match at the end of a line."
(interactive)
(let* ((context (org-element-context))
(label (org-element-property :label context)))
(unless (and (eq (org-element-type context) 'footnote-reference)
(unless (and (org-element-type-p context 'footnote-reference)
(org-src--on-datum-p context))
(user-error "Not on a footnote reference"))
(unless label (user-error "Cannot edit remotely anonymous footnotes"))
@@ -1039,16 +1086,16 @@ A coderef format regexp can only match at the end of a line."
(org-footnote-goto-definition label)
(backward-char)
(org-element-context)))
(inline? (eq 'footnote-reference (org-element-type definition)))
(inline? (org-element-type-p definition 'footnote-reference))
(contents
(org-with-wide-buffer
(buffer-substring-no-properties
(or (org-element-property :post-affiliated definition)
(org-element-property :begin definition))
(or (org-element-post-affiliated definition)
(org-element-begin definition))
(cond
(inline? (1+ (org-element-property :contents-end definition)))
((org-element-property :contents-end definition))
(t (goto-char (org-element-property :post-affiliated definition))
(inline? (1+ (org-element-contents-end definition)))
((org-element-contents-end definition))
(t (goto-char (org-element-post-affiliated definition))
(line-end-position)))))))
(add-text-properties
0
@@ -1079,7 +1126,7 @@ A coderef format regexp can only match at the end of a line."
;; If footnote reference belongs to a table, make sure to
;; remove any newline characters in order to preserve
;; table's structure.
(when (org-element-lineage definition '(table-cell))
(when (org-element-lineage definition 'table-cell)
(while (search-forward "\n" nil t) (replace-match " ")))))
contents
'remote))
@@ -1098,7 +1145,7 @@ the area in the Org mode buffer.
Throw an error when not at such a table."
(interactive)
(let ((element (org-element-at-point)))
(unless (and (eq (org-element-type element) 'table)
(unless (and (org-element-type-p element 'table)
(eq (org-element-property :type element) 'table.el)
(org-src--on-datum-p element))
(user-error "Not in a table.el table"))
@@ -1114,14 +1161,14 @@ Throw an error when not at such a table."
"Edit LaTeX fragment at point."
(interactive)
(let ((context (org-element-context)))
(unless (and (eq 'latex-fragment (org-element-type context))
(unless (and (org-element-type-p context 'latex-fragment)
(org-src--on-datum-p context))
(user-error "Not on a LaTeX fragment"))
(let* ((contents
(buffer-substring-no-properties
(org-element-property :begin context)
(- (org-element-property :end context)
(org-element-property :post-blank context))))
(org-element-begin context)
(- (org-element-end context)
(org-element-post-blank context))))
(delim-length (if (string-match "\\`\\$[^$]" contents) 1 2)))
;; Make the LaTeX deliminators read-only.
(add-text-properties 0 delim-length
@@ -1145,7 +1192,7 @@ Throw an error when not at such a table."
;; If within a table a newline would disrupt the structure,
;; so remove newlines.
(goto-char (point-min))
(when (org-element-lineage context '(table-cell))
(when (org-element-lineage context 'table-cell)
(while (search-forward "\n" nil t) (replace-match " "))))
contents))
t))
@@ -1162,7 +1209,7 @@ 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)
(unless (and (org-element-type-p element 'latex-environment)
(org-src--on-datum-p element))
(user-error "Not in a LaTeX environment"))
(org-src--edit-element
@@ -1186,7 +1233,7 @@ the area in the Org mode buffer.
Throw an error when not at an export block."
(interactive)
(let ((element (org-element-at-point)))
(unless (and (eq (org-element-type element) 'export-block)
(unless (and (org-element-type-p element 'export-block)
(org-src--on-datum-p element))
(user-error "Not in an export block"))
(let* ((type (downcase (or (org-element-property :type element)
@@ -1214,7 +1261,7 @@ then replace the area in the Org mode buffer.
Throw an error when not at a comment block."
(interactive)
(let ((element (org-element-at-point)))
(unless (and (eq (org-element-type element) 'comment-block)
(unless (and (org-element-type-p element 'comment-block)
(org-src--on-datum-p element))
(user-error "Not in a comment block"))
(org-src--edit-element
@@ -1259,16 +1306,18 @@ name of the sub-editing buffer."
element
(or edit-buffer-name
(org-src--construct-edit-buffer-name (buffer-name) lang))
lang-f
(lambda ()
(when lang-f (funcall lang-f))
(setq-local org-coderef-label-format
(or (org-element-property :label-fmt element)
org-coderef-label-format))
(when (eq type 'src-block)
(setq org-src--babel-info babel-info)))
(and (null code)
(lambda () (org-escape-code-in-region (point-min) (point-max))))
(and code (org-unescape-code-in-string code)))
;; Finalize buffer.
(setq-local org-coderef-label-format
(or (org-element-property :label-fmt element)
org-coderef-label-format))
(when (eq type 'src-block)
(setq org-src--babel-info babel-info)
(let ((edit-prep-func (intern (concat "org-babel-edit-prep:" lang))))
(when (fboundp edit-prep-func)
(funcall edit-prep-func babel-info))))
@@ -1278,7 +1327,7 @@ name of the sub-editing buffer."
"Edit inline source code at point."
(interactive)
(let ((context (org-element-context)))
(unless (and (eq (org-element-type context) 'inline-src-block)
(unless (and (org-element-type-p context 'inline-src-block)
(org-src--on-datum-p context))
(user-error "Not on inline source code"))
(let* ((lang (org-element-property :language context))
@@ -1323,7 +1372,7 @@ will then replace
the area in the Org mode buffer."
(interactive)
(let ((element (org-element-at-point)))
(unless (and (eq (org-element-type element) 'fixed-width)
(unless (and (org-element-type-p element 'fixed-width)
(org-src--on-datum-p element))
(user-error "Not in a fixed-width area"))
(org-src--edit-element
@@ -1408,8 +1457,8 @@ EVENT is passed to `mouse-set-point'."
(org-with-wide-buffer
(when (and write-back
(not (equal (buffer-substring beg end)
(with-current-buffer write-back-buf
(buffer-string)))))
(with-current-buffer write-back-buf
(buffer-string)))))
(undo-boundary)
(goto-char beg)
(let ((expecting-bol (bolp)))
@@ -1430,11 +1479,7 @@ EVENT is passed to `mouse-set-point'."
(goto-char beg)
(cond
;; Block is hidden; move at start of block.
((if (eq org-fold-core-style 'text-properties)
(org-fold-folded-p nil 'block)
(cl-some (lambda (o) (eq (overlay-get o 'invisible) 'org-hide-block))
(overlays-at (point))))
(beginning-of-line 0))
((org-fold-folded-p nil 'block) (forward-line -1))
(write-back (org-src--goto-coordinates coordinates beg end))))
;; Clean up left-over markers and restore window configuration.
(set-marker beg nil)