From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id Pm13IOXLzF46bAAA0tVLHw (envelope-from ) for ; Tue, 26 May 2020 07:57:25 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id eOHBG+XLzF4FcAAAB5/wlQ (envelope-from ) for ; Tue, 26 May 2020 07:57:25 +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 EC3A3940363 for ; Tue, 26 May 2020 07:57:24 +0000 (UTC) Received: from localhost ([::1]:58120 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jdUSg-00032C-NA for larch@yhetil.org; Tue, 26 May 2020 03:57:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:45090) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdUSC-0002yB-J6 for emacs-orgmode@gnu.org; Tue, 26 May 2020 03:56:52 -0400 Received: from relay12.mail.gandi.net ([217.70.178.232]:41341) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdUSA-0002rT-Oa; Tue, 26 May 2020 03:56:52 -0400 Received: from localhost (40-67.ipv4.commingeshautdebit.fr [185.131.40.67]) (Authenticated sender: admin@nicolasgoaziou.fr) by relay12.mail.gandi.net (Postfix) with ESMTPSA id E189D20000B; Tue, 26 May 2020 07:56:44 +0000 (UTC) From: Nicolas Goaziou To: TEC Subject: Re: (Feature Request) have org-edit-special work inside non-environment LaTeX blocks, i.e. \( \) and \[ \] References: <87d06s9rva.fsf@nicolasgoaziou.fr> <87blmcp0m2.fsf@gmail.com> Mail-Followup-To: TEC , Bastien , "emacs-orgmode\@gnu.org" Date: Tue, 26 May 2020 09:56:43 +0200 In-Reply-To: <87blmcp0m2.fsf@gmail.com> (TEC's message of "Mon, 25 May 2020 22:08:19 +0800") Message-ID: <87wo4z6sec.fsf@nicolasgoaziou.fr> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=217.70.178.232; envelope-from=mail@nicolasgoaziou.fr; helo=relay12.mail.gandi.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/26 03:17:30 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-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=none; dmarc=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: -1.01 X-TUID: V5aB5ax7YxJy Hello, TEC writes: > --- > lisp/org-src.el | 45 +++++++++++++++++++++++++++++++++++++++++++++ > lisp/org.el | 1 + > 2 files changed, 46 insertions(+) Thank you. It looks fine, I will only be nitpicking. > +(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"))) This is a fancy way to use a let-binding. I suggest to mimic what is done elsewhere, i.e., first bind `context', then check if we're at a LaTeX fragment, then bind the rest. > + ;; Grab the LaTeX fragment for propertization Missing full stop at the end of the comment. > + (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 "\\$[^$]" (substring contents 0 2)) Use (string-match "\\`\\$[^$]" contents) instead. or, arguably better, (string-match (rx (seq string-start "$" (not (any "$")))) contents) > + 1 2))) > + ;; make the LaTeX deliminators read-only Missing initial capital and final full stop. > + (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) You could factor out (length contents) so it is only called once. > + (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 See above. > + (while (re-search-forward "\n[ \t]*\n" nil t) (replace-match "\n")) > + ;; If within a table a newline would disrupt the structure, This comment is truncated. > + (goto-char (point-min)) > + (when (org-element-lineage context '(table-cell)) > + (while (search-forward "\n" nil t) (replace-match " "))) > + ) Don't leave parenthesis alone. Also, make sure your indentation is right, e.g., using M-q on the definition. You also need to add a proper commit message and use `git format-patch', and an entry in ORG-NEWS (probably in Miscellaneous part). Bonus points if you can add some tests in "testing/lisp/test-org-src.el". Could you remind me if you signed the FSF papers already? Regards, -- Nicolas Goaziou