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 EOQdKlfdzF5NZgAA0tVLHw (envelope-from ) for ; Tue, 26 May 2020 09:11:51 +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 WNbiJVfdzF6NYgAAbx9fmQ (envelope-from ) for ; Tue, 26 May 2020 09:11:51 +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 0CD8C940253 for ; Tue, 26 May 2020 09:11:51 +0000 (UTC) Received: from localhost ([::1]:60320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jdVci-0001e2-Tz for larch@yhetil.org; Tue, 26 May 2020 05:11:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53206) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdVcP-0001du-Rq for emacs-orgmode@gnu.org; Tue, 26 May 2020 05:11:29 -0400 Received: from relay6-d.mail.gandi.net ([217.70.183.198]:59019) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdVcO-0007kr-94; Tue, 26 May 2020 05:11:29 -0400 X-Originating-IP: 185.131.40.67 Received: from localhost (40-67.ipv4.commingeshautdebit.fr [185.131.40.67]) (Authenticated sender: admin@nicolasgoaziou.fr) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id C3479C000C; Tue, 26 May 2020 09:11:23 +0000 (UTC) From: Nicolas Goaziou To: Timothy Subject: Re: (Feature Request) have org-edit-special work inside non-environment LaTeX blocks, i.e. \( \) and \[ \] References: <87wo4z6sec.fsf@nicolasgoaziou.fr> Mail-Followup-To: Timothy , Bastien , "emacs-orgmode\@gnu.org" Date: Tue, 26 May 2020 11:11:17 +0200 In-Reply-To: (Timothy's message of "Tue, 26 May 2020 16:39:41 +0800") Message-ID: <87mu5v6oy2.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.183.198; envelope-from=mail@nicolasgoaziou.fr; helo=relay6-d.mail.gandi.net X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/26 04:33:21 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, RCVD_IN_MSPIKE_H2=-0.001, 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: 6uWff/ciMOv4 Timothy writes: > 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? Without hesitation, the first form is nicer. The second one is just abusing let-binding. I die a little just by looking at it. > I've changed to (string-match-p "\\`\\$[^$]" contents), as this seems > like the idiomatic form, let me know if you're happy with this. the "-p" part is not warranted here. In Emacs, every function is expected to modify match data, unless specified in the docstring. Since there is a cost in preserving match-data, we shouldn't do it without a good reason. Here, there isn't. Note that you'll find a zillion of places in Org code base that contradict the above. But, hey, nobody's perfect. > 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 :) See `rx' macro. S-exp regexps are usually easier to read (after an initial struggle), and less likely to introduce subtle bugs. For long regexps, this is important. For this one, either way is fine. >> You could factor out (length contents) so it is only called once. > > I'm not sure if this a big deal, This is not a big deal, but poor practice, IMO. > but I shoved it in the let* for now, let me know if that suffices. Well. Ideally, let-binding should enclose the minimum part of the code that needs the binding. Sometimes, an exception is tolerated, because the code would contain too many nested let-forms. But, conversely, you shouldn't stuff every local variable at the beginning of the function and be done with it. In this particular case, there's no reason to stuff the `length' call at the top of the function when you need it later on, on a well-defined S-exp. IOW, it is more idiomatic to just add a let-binding around the appropriate (add-text-properties ...). >>> + (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. It was just about the missing full stop. You looked at the moon, but I really was the fool showing the tip of his finger ;) >>> + (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" But it should be ", so remove newlines." > I recall being asked to list modified/added functions, what else do > I need? Nothing else. >> 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. You could look at `test-org-src/footnote-references' for inspiration. However, I assume tests will be less complicated for LaTeX fragments. >> Could you remind me if you signed the FSF papers already? > > They're done and dusted :) Perfect. We're almost there, then.