From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id iOpQBREhzV7oZAAA0tVLHw (envelope-from ) for ; Tue, 26 May 2020 14:00:49 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id QEgIAREhzV5oJgAAbx9fmQ (envelope-from ) for ; Tue, 26 May 2020 14:00:49 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 88956940DEA for ; Tue, 26 May 2020 14:00:48 +0000 (UTC) Received: from localhost ([::1]:60182 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jda8N-0006yo-8c for larch@yhetil.org; Tue, 26 May 2020 10:00:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36238) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jda7r-0006yQ-HZ for emacs-orgmode@gnu.org; Tue, 26 May 2020 10:00:15 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]:51242) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jda7p-0003qp-Lt; Tue, 26 May 2020 10:00:15 -0400 Received: by mail-pj1-x1029.google.com with SMTP id cx22so1465201pjb.1; Tue, 26 May 2020 07:00:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:references:user-agent:in-reply-to :message-id:mime-version; bh=/1wmVI8G9VPYzD/Xt7fe8MNf58N/uDmOCfHmPuKU9FI=; b=pGYQP0Z61Z2vKqXT4zaf77m//BkTXg6BM5p4JrUdaLkldFPMYflVu6z/qf3n+Wp6MP wmd1D/bEnUZrXHsdGr+61EUsFMp1cUqDGW6XkGMV02/3V+VwNtyP7fVH/K9hBdD/46J2 gm7RBIfr6CQmatM4Gu5kcFHo24idHfMVmYZXXA3qsCY2sL9AZGdXcqE6pjw6B6YIBmm1 vNySunfDY3KHFZcr25YADDkNY/6M+kJARCzqYYG8kDYX/B/rUHW4bHpRCMEGsze07wU1 PK5vhbAK1TclTM3SwOGl+xOQib8KtAE2DHZyNzLC0zbuuomrvLIcuZfpAK8winJ/5pDz RFKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:references:user-agent :in-reply-to:message-id:mime-version; bh=/1wmVI8G9VPYzD/Xt7fe8MNf58N/uDmOCfHmPuKU9FI=; b=Ms9yVcKgnaJ0C5x4eWXYdjw7Ozlg2KgsBQyh1c+5P2YGDBFDcLEtpAqevlFArrawX3 BAi2TGsLGMcgKA5wZRHaMiP9kuRHW10gAAc+W/JcEobVN93H/4zrC+toQC0TgHnnZeTg gk2+W+TveW2LUWMqXj9GL9FAeVMu9wcVeJCy4IQg94vi/IMwPfnlpyx9k786LfATJLAH vqT9+YVdDucfEi4NgLazKJujVtvf7VwPnP5W0DUWyxJShgS+VkIGELEoSPggjo2Sw2at OMcCYDBr4lzW2dGE+WdfZsfa8ooXuM7J8ro+OA5Wrj2WVJXYdHs0QnKRDuuExLEANQEH V91Q== X-Gm-Message-State: AOAM530GAe1hX5cTSSSeDWfPKdwfxb+tu+WbjG80uIeviWOPkW/vazQE VGCOSNKxMfmLC8ktH73NVu334CWJLzw= X-Google-Smtp-Source: ABdhPJyF+x/7fUT0OGPpiWMUoK+zouPjSxVYZ6jvKt5YqGBh4mJv5P+oLxLGETh/OjlpW2kS/WQsng== X-Received: by 2002:a17:90a:bf08:: with SMTP id c8mr26995666pjs.13.1590501611049; Tue, 26 May 2020 07:00:11 -0700 (PDT) Received: from localhost (180-150-91-8.b4965b.per.nbn.aussiebb.net. [180.150.91.8]) by smtp.gmail.com with ESMTPSA id d2sm15602922pfc.7.2020.05.26.07.00.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 May 2020 07:00:09 -0700 (PDT) From: TEC To: Nicolas Goaziou 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 References: <87wo4z6sec.fsf@nicolasgoaziou.fr> <87mu5v6oy2.fsf@nicolasgoaziou.fr> <87lflf82qp.fsf@gmail.com> User-agent: mu4e 1.4.6; emacs 26.3 In-reply-to: <87lflf82qp.fsf@gmail.com> Message-ID: <87k10y94pl.fsf@gmail.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=tecosaur@gmail.com; helo=mail-pj1-x1029.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bastien , "emacs-orgmode@gnu.org" Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=fail (rsa verify failed) header.d=gmail.com header.s=20161025 header.b=pGYQP0Z6; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: 0.09 X-TUID: bAkXFfDfUnzU --=-=-= Content-Type: text/plain; format=flowed 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. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Extend-org-edit-special-to-editing-LaTeX-fragments.patch >From 31aa97c7f0cc9bf7272f4e781192b1458ee98525 Mon Sep 17 00:00:00 2001 From: TEC 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. \\ 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 --=-=-=--