From: TEC <tecosaur@gmail.com>
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Cc: Bastien <bzg@gnu.org>, "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: Re: (Feature Request) have org-edit-special work inside non-environment LaTeX blocks, i.e. \( \) and \[ \]
Date: Tue, 26 May 2020 21:56:19 +0800 [thread overview]
Message-ID: <87k10y94pl.fsf@gmail.com> (raw)
In-Reply-To: <87lflf82qp.fsf@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 338 bytes --]
Ok, I think this is everything except for except putting (length
contents) in a let binding. I don't mind if you edit a let binding
into the patch, I'm just struggling to overcome a feeling that
it's a bit silly adding a binding for a short, simple function
called twice.
Let me know if this is good, or if you'd like any changes.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Extend-org-edit-special-to-editing-LaTeX-fragments.patch --]
[-- Type: text/x-patch, Size: 4368 bytes --]
From 31aa97c7f0cc9bf7272f4e781192b1458ee98525 Mon Sep 17 00:00:00 2001
From: TEC <tec@tecosaur.com>
Date: Sun, 24 May 2020 23:35:33 +0800
Subject: [PATCH] Extend org-edit-special to editing LaTeX-fragments Defines a
new function, `org-edit-latex-fragment' which is hooked into
`org-edit-special', modifying `org-src--contents-area-modified' to recognise
the element type.
---
etc/ORG-NEWS | 7 +++++++
lisp/org-src.el | 45 +++++++++++++++++++++++++++++++++++++++++++++
lisp/org.el | 1 +
3 files changed, 53 insertions(+)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 5183b58de..ea7ccb7c5 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -459,6 +459,13 @@ By default, Haskell blocks are interpreted. By adding =:compile yes=
to a Haskell source block, it will be compiled, executed and the
results will be displayed.
+*** Support for ~org-edit-special~ with LaTeX fragments.
+
+Calling ~org-edit-special~ on an inline LaTeX fragment calls a new
+function, ~org-edit-latex-fragment~. This functions in a comparable
+manner to editing inline source blocks, bringing up a minibuffer set
+to LaTeX mode. The math-mode deliminators are read only.
+
* Version 9.3
** Incompatible changes
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 1643607e4..43fb10fa5 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -363,6 +363,12 @@ where BEG and END are buffer positions and CONTENTS is a string."
(end (progn (goto-char (org-element-property :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)
+ (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)))
@@ -959,6 +965,45 @@ Throw an error when not at such a table."
(table-recognize)
t))
+(defun org-edit-latex-fragment ()
+ "Edit LaTeX fragment at point."
+ (interactive)
+ (let ((context (org-element-context)))
+ (unless (and (eq (org-element-type context) 'latex-fragment)
+ (org-src--on-datum-p context))
+ (user-error "Not on a LaTeX fragment"))
+ (let*
+ ;; Grab the LaTeX fragment for propertization.
+ ((contents (buffer-substring-no-properties
+ (org-element-property :begin context)
+ (- (org-element-property :end context)
+ (org-element-property :post-blank context))))
+ (delim-length (if (string-match "\\`\\$[^$]" contents))
+ 1 2))
+ ;; Make the LaTeX deliminators read-only.
+ (add-text-properties
+ 0 delim-length
+ '(read-only "Cannot edit LaTeX deliminator" front-sticky t rear-nonsticky t)
+ contents)
+ (add-text-properties
+ (- (length contents) delim-length)
+ (length contents)
+ '(read-only "Cannot edit LaTeX deliminator" front-sticky nil rear-nonsticky nil)
+ contents)
+ (org-src--edit-element
+ context
+ (org-src--construct-edit-buffer-name (buffer-name) "LaTeX fragment")
+ (org-src-get-lang-mode "latex")
+ (lambda ()
+ ;; Blank lines break things, replace with a single newline.
+ (while (re-search-forward "\n[ \t]*\n" nil t) (replace-match "\n"))
+ ;; If within a table a newline would disrupt the structure, so remove newlines.
+ (goto-char (point-min))
+ (when (org-element-lineage context '(table-cell))
+ (while (search-forward "\n" nil t) (replace-match " "))))
+ contents))
+ t))
+
(defun org-edit-latex-environment ()
"Edit LaTeX environment at point.
\\<org-src-mode-map>
diff --git a/lisp/org.el b/lisp/org.el
index 40c3c46b9..0808fc210 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -17347,6 +17347,7 @@ Otherwise, return a user error."
(pcase (org-element-type context)
(`footnote-reference (org-edit-footnote-reference))
(`inline-src-block (org-edit-inline-src-code))
+ (`latex-fragment (org-edit-latex-fragment))
(`timestamp (if (eq 'inactive (org-element-property :type context))
(call-interactively #'org-time-stamp-inactive)
(call-interactively #'org-time-stamp)))
--
2.26.2
next prev parent reply other threads:[~2020-05-26 14:00 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-19 1:31 (Feature Request) have org-edit-special work inside non-environment LaTeX blocks, i.e. \( \) and \[ \] Timothy
2020-05-19 7:47 ` Nicolas Goaziou
2020-05-19 9:27 ` Timothy
2020-05-19 9:39 ` Nicolas Goaziou
2020-05-19 9:45 ` Timothy
2020-05-19 13:27 ` Nicolas Goaziou
2020-05-19 13:32 ` Timothy
2020-05-19 14:09 ` Nicolas Goaziou
2020-05-19 14:12 ` Timothy
2020-05-19 14:28 ` Nicolas Goaziou
2020-05-19 14:33 ` Timothy
2020-05-23 9:10 ` Bastien
2020-05-23 9:20 ` tecosaur
2020-05-23 9:34 ` Bastien
2020-05-24 15:07 ` TEC
2020-05-24 15:38 ` TEC
2020-05-24 15:43 ` Timothy
2020-05-24 19:33 ` Nicolas Goaziou
2020-05-25 1:33 ` TEC
2020-05-25 7:11 ` Nicolas Goaziou
2020-05-25 9:28 ` TEC
2020-05-25 9:41 ` Nicolas Goaziou
2020-05-25 9:42 ` TEC
2020-05-25 9:55 ` TEC
2020-05-25 10:09 ` Nicolas Goaziou
2020-05-25 10:09 ` TEC
2020-05-25 10:23 ` Nicolas Goaziou
2020-05-25 10:24 ` TEC
2020-05-25 10:32 ` Nicolas Goaziou
2020-05-25 10:33 ` TEC
2020-05-25 10:05 ` TEC
2020-05-25 10:20 ` Nicolas Goaziou
2020-05-25 10:21 ` TEC
2020-05-25 11:27 ` Nicolas Goaziou
2020-05-25 13:22 ` Timothy
2020-05-25 14:08 ` TEC
2020-05-26 7:56 ` Nicolas Goaziou
2020-05-26 8:39 ` Timothy
2020-05-26 9:11 ` Nicolas Goaziou
2020-05-26 9:23 ` TEC
2020-05-26 13:56 ` TEC [this message]
2020-05-26 21:13 ` Nicolas Goaziou
2020-05-26 17:01 ` John Kitchin
2020-05-25 18:58 ` Nicolas Goaziou
2020-05-26 4:48 ` TEC
2020-05-25 10:11 ` Nicolas Goaziou
2020-05-25 10:17 ` TEC
-- strict thread matches above, loose matches on Subject: below --
2020-05-18 6:44 Timothy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87k10y94pl.fsf@gmail.com \
--to=tecosaur@gmail.com \
--cc=bzg@gnu.org \
--cc=emacs-orgmode@gnu.org \
--cc=mail@nicolasgoaziou.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).