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 IATUOfrVzF6pewAA0tVLHw (envelope-from ) for ; Tue, 26 May 2020 08:40:26 +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 o2OHNfrVzF5MTQAAbx9fmQ (envelope-from ) for ; Tue, 26 May 2020 08:40:26 +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 18DC89401AD for ; Tue, 26 May 2020 08:40:24 +0000 (UTC) Received: from localhost ([::1]:38926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jdV8I-00053V-DL for larch@yhetil.org; Tue, 26 May 2020 04:40:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50012) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdV7l-00053C-Eo for emacs-orgmode@gnu.org; Tue, 26 May 2020 04:39:49 -0400 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]:44885) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jdV7k-00025v-Cb; Tue, 26 May 2020 04:39:49 -0400 Received: by mail-pg1-x52d.google.com with SMTP id p30so9650904pgl.11; Tue, 26 May 2020 01:39:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:message-id:in-reply-to:references:subject :mime-version; bh=F32uolPf8SfDxq01jQvBjoo4dwJGrzvF2YCc4jOfuIc=; b=riVaBZ/l0Eo8CXuo6udu+OWyT77obKqpZzX0Y+BhT8FzX/f+MkCPFB1D5e6vWbEWvn Sow/5TOAWTm4LZpyrIBe6rksSii7hSScUZGTpqFCMCM6i24NRjlslUKNlkZbqwEdIapZ Ic56jCnCrCQYsOyGjVEDu6XJQhw14Co3iM3r13vmDn+xg4b1tQ6Aqagj4fvQsfFvqk5V htHvPa0gzA+QL0jrZWKAJp4jqkXjGTYimBeA4ftGn21/9m86vHkem+9nlF9CB/6XKIBH ds8jON49vhjUhqjPVYCfiq9r/za/PZRLI4cKPjVmqOOjXNrF+QSm5P+CuYyiVD5qRK6F Engg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to :references:subject:mime-version; bh=F32uolPf8SfDxq01jQvBjoo4dwJGrzvF2YCc4jOfuIc=; b=DbuiMDtLg+7yLcLho9NFEBp+FnAjuVUxdF4hkHru3qZtyfHyz3xL7TCbhDlYMpQ6D/ 07JyXmepUZPAFFkr8HQkDF2fDajgDxDueIi4mxzGfn52eGb/GdAZe8k23LIys89Avvhz CCid5ZOlz1i1tOMTO09Fazsh2df7lvkNqNcV9Eyw0jFSaxK4nXboUflX0WZdqpN7eX7f xwOFZrC7mnprqTNGY9QtO6obLwajM3tC0FDEt5LhiaotbwChPavXml3MEy2iyuNAQgou X7c7YjooKSpYf4KQS5Fj5MZE1qw3yvwduFIzyxOjTnCjxxySXQLMDsmRW9zwKHVzvTgP GaaQ== X-Gm-Message-State: AOAM532EOa4BzZ0wjIcsGhHdRs0NSS5mHsLsLkYQIWswuBZrnINuNCD3 8icL6KL5v7HoZ2uBlBvSfQuQeRpyW0Q= X-Google-Smtp-Source: ABdhPJynF+TB0KgUFhcix/8D0dIfpOPHGYJuVORs3lkSgisK2s1eVKJpm6OwsJ+IEtEeMOoF4JbsZQ== X-Received: by 2002:a62:76cc:: with SMTP id r195mr20599932pfc.116.1590482386660; Tue, 26 May 2020 01:39:46 -0700 (PDT) Received: from tranquillity (180-150-91-8.b4965b.per.nbn.aussiebb.net. [180.150.91.8]) by smtp.gmail.com with ESMTPSA id a2sm8442295pfg.98.2020.05.26.01.39.44 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 May 2020 01:39:45 -0700 (PDT) Date: Tue, 26 May 2020 16:39:41 +0800 From: Timothy To: Nicolas Goaziou Message-ID: In-Reply-To: <87wo4z6sec.fsf@nicolasgoaziou.fr> References: <87wo4z6sec.fsf@nicolasgoaziou.fr> Subject: Re: (Feature Request) have org-edit-special work inside non-environment LaTeX blocks, i.e. \( \) and \[ \] X-Mailer: Mailspring MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="5eccd5cd_3346d5f2_27df83" Received-SPF: pass client-ip=2607:f8b0:4864:20::52d; envelope-from=tecosaur@gmail.com; helo=mail-pg1-x52d.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 , "=?utf-8?Q?emacs-orgmode=40gnu.org?=" Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=riVaBZ/l; dmarc=pass (policy=none) header.from=gmail.com; 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.50 X-TUID: CaY6f/rhxYIo --5eccd5cd_3346d5f2_27df83 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Nicolas Goaziou writes: > Thank you. It looks fine, I will only be nitpicking. Nitpick away :D >> +(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. I had a look at that, to me this was cleaner than using multiple let bindings, like so (let ((context ...)) (unless ... user error) (let* ((contents ...) (delim-length ...)) ... vs. (let* ((context ...) (_ (unless ... user error)) (contents ...) (delim-length ...)) ... Personally I find the second one nicer. Thoughts? >> + ;; Grab the LaTeX fragment for propertization > > Missing full stop at the end of the comment. Fixed! > >> + (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 I've changed to (string-match-p "\\`\\$[^$]" contents), as this seems like the idiomatic form, let me know if you're happy with this. I'm not actually sure what's going on with your second suggested form, or why that may be better. If you'd mind explaining, that would be appriciated :) > Missing initial capital and final full stop. Fixed! > You could factor out (length contents) so it is only called once. I'm not sure if this a big deal, but I shoved it in the let* for now, let me know if that suffices. >> + (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. I'm not quite sure what I should see? I don't notice anything to factor out here. > >> + (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. Added ", so remove newlines" > Don't leave parenthesis alone. Fixed! > Also, make sure your indentation is right, e.g., using M-q on the > definition. I've applied auto-indent to `org-edit-latex-fragment' > You also need to add a proper commit message and use `git format-patch', > and an entry in ORG-NEWS (probably in Miscellaneous part). I recall being asked to list modified/added functions, what else do I need? > Bonus points if you can add some tests in > "testing/lisp/test-org-src.el". I'll have a look at that, but I'm not quite sure what to do. > Could you remind me if you signed the FSF papers already? They're done and dusted :) Regards, Timothy. --5eccd5cd_3346d5f2_27df83 Content-Type: application/octet-stream Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="0001-Extend-org-edit-special-to-editing-LaTeX-fragments.patch" RnJvbSBiYjQ5NGViZmQ1NDEzNDNkM2Y0MmMzMTJhMmVmY2JhNWUzY2FjNTQzIE1vbiBTZXAgMTcg MDA6MDA6MDAgMjAwMQpGcm9tOiBURUMgPHRlY0B0ZWNvc2F1ci5jb20+CkRhdGU6IFN1biwgMjQg TWF5IDIwMjAgMjM6MzU6MzMgKzA4MDAKU3ViamVjdDogW1BBVENIXSBFeHRlbmQgb3JnLWVkaXQt c3BlY2lhbCB0byBlZGl0aW5nIExhVGVYLWZyYWdtZW50cyBEZWZpbmVzIGEKIG5ldyBmdW5jdGlv biwgYG9yZy1lZGl0LWxhdGV4LWZyYWdtZW50JyB3aGljaCBpcyBob29rZWQgaW50bwogYG9yZy1l ZGl0LXNwZWNpYWwnLCBtb2RpZnlpbmcgYG9yZy1zcmMtLWNvbnRlbnRzLWFyZWEtbW9kaWZpZWQn IHRvIHJlY29nbmlzZQogdGhlIGVsZW1lbnQgdHlwZS4KCi0tLQogbGlzcC9vcmctc3JjLmVsIHwg N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