From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id IBB5M60dN2LqnwAAgWs5BA (envelope-from ) for ; Sun, 20 Mar 2022 13:27:25 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id 0D3LMK0dN2LV5AAA9RJhRA (envelope-from ) for ; Sun, 20 Mar 2022 13:27:25 +0100 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 58D4329F1C for ; Sun, 20 Mar 2022 13:27:25 +0100 (CET) Received: from localhost ([::1]:57352 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nVuea-0005PY-Ix for larch@yhetil.org; Sun, 20 Mar 2022 08:27:24 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51056) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nVucM-0005Ow-T5 for emacs-orgmode@gnu.org; Sun, 20 Mar 2022 08:25:09 -0400 Received: from [2607:f8b0:4864:20::52b] (port=38777 helo=mail-pg1-x52b.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nVucK-0000zz-I0 for emacs-orgmode@gnu.org; Sun, 20 Mar 2022 08:25:06 -0400 Received: by mail-pg1-x52b.google.com with SMTP id s72so5730102pgc.5 for ; Sun, 20 Mar 2022 05:25:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:in-reply-to:references:date:message-id :mime-version; bh=Xbj8d+ICoquIDW1smSf0qKKKaToUyhpgcldRARm+VXg=; b=RIxhJEtfRy/DTbBEG2WsdgejBHYfYTRMGjoIdghad6o5zQmQp+ox3HCm2hCQ4FaD0Z +4whEDlvUXKIfL91X1oBx1P9tKAW3LN52u3Ta51ld7JCTR4bdES7jwxD+znNVsVF2GVh i+mQ9HwphDxCBYWqG23Oafhb4clZ4IewmuOoeb+LSpcHwAggQcnWlRtapUYus0l3wsVR 0ngLRNq109YQDDFskVNWotUL/m9qaoEb5VjNYoaPlKhLEu/rO3LQAU34P7O2I+K0urmb 7AdXDxLvsQAeTj6vdC3GpdOu+tH0N509XjOsJho0+VBXgGk2DXKAO8VVhpexg2DGWivC AeTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version; bh=Xbj8d+ICoquIDW1smSf0qKKKaToUyhpgcldRARm+VXg=; b=xAVybwM3Dh0kcqCm339b0Lay21n8PRBBQ4XmypA+yhAfdaS/1fc4wCfa9GkPh1Q2Uq 4X9wvcZYwG/EkdnxmxtIXdrpDqkST+rzTfIj4d98qHEx9ywZVjPQI2GmhMagHI5U4RRl 7oUKKweK8h/OvKlsi4CBAMVYWsCe7LAxMGNMOrH7uMOPMpJxM+6hA98ivnPNEoXv8U8E 2oggchPVXl9BjZFJMYYOCUQZLpBY6C05TB6vjJmsIsziC01oOYBnPA2T4h8LYYtpI3fu 7lSnX+81v6Jk4W/9lVsXOc/cxto7ZO+XtNPILAZeawkkD+KDDbzi7I55gfTdeD71sYKf cIuA== X-Gm-Message-State: AOAM533N9B6xwO9S/6XhM5SmVumuqncudA3zYFKGqtJ7d1IbJV7/8JFK wVgFdt25yisitx2Dop01S0k= X-Google-Smtp-Source: ABdhPJxoVa51yknPkUaG8FpPL5R6CCp5J3TlwXSvHD4JwhGk5h2ycV/AKLgdtePAyknLb5j45oAOZA== X-Received: by 2002:a05:6a00:1350:b0:4f7:8c4f:cfca with SMTP id k16-20020a056a00135000b004f78c4fcfcamr18784841pfu.45.1647779102148; Sun, 20 Mar 2022 05:25:02 -0700 (PDT) Received: from localhost ([45.128.72.3]) by smtp.gmail.com with ESMTPSA id w3-20020a63af03000000b00381309eb407sm11682745pge.68.2022.03.20.05.25.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Mar 2022 05:25:01 -0700 (PDT) From: Ihor Radchenko To: Rudolf =?utf-8?Q?Adamkovi=C4=8D?= Subject: [PATCH] Re: [BUG] Hard-coded begin/end in org-insert-structure-template [9.5.2 (release_9.5.2-24-g668205 @ /Users/salutis/src/emacs/nextstep/Emacs.app/Contents/Resources/lisp/org/)] In-Reply-To: References: Date: Sun, 20 Mar 2022 20:25:29 +0800 Message-ID: <871qywerpi.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::52b (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::52b; envelope-from=yantar92@gmail.com; helo=mail-pg1-x52b.google.com X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 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_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, PDS_HP_HELO_NORDNS=0.659, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: emacs-orgmode@gnu.org Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1647779245; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=Xbj8d+ICoquIDW1smSf0qKKKaToUyhpgcldRARm+VXg=; b=AjdeyyYx8Dh9W+XWuj8jiGtMWExwTIpJYo0xgDOSTUqhkQVqRCWm2wgabkUN0gLf0Cz9s+ nPJ5xb8vjiQ3NQ5qFpVKgbRFOSqLqicYBafK3VGiwIW3d1SbopsP1GLeMYUMkiqnEklvKh ebdspyoBkageMhtPWtWVfO4GwgNBJ6CqkYK+VyZd3hPAbut1IpBUpi7jXgavVom+NkI83N C8ASk2/yZemriviWRWjNaIfWh2quvWytI1fjUt4p+5a562+V5p+NoKnmliZHDLEfmWiNTA HkSPXPwvf0YyBkgKUPgCiZWytoqwEqaWhZAVFKSTFte31CKhd5sB5RrS/3uDKA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1647779245; a=rsa-sha256; cv=none; b=lRQg7murrYhMlcu/Ez7lE5Oz5vkVKmF/rEOuCwEYQ3IzHMBI1zxHtdpWoNfdJXnuVf0le9 gLOhv+X6/1aWp2x6dC3LaYWDdcTWZgj38YtI7spVcIROhwA0YM57BoJRO8SeFQm+4fHJEp wBUWk2KmUHuppNrYeR2RDMnqTj7ve2WWoWl9m6VA6BlYfpxpGAzJimn/ISSK5rl1opZn3O z+kAAzwajPaidSiTK38yqjllHhwVhQeWMcPzf1ZI9rqfCNnUUKwoPyxoQ0DPUX6293Nq/l E1BK3mqh+aTGRYG1dKQkWRPtUWHnBNFLc1JzXcSV+brz93E4gjp7nX6bYQUtyg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=RIxhJEtf; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -3.63 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=RIxhJEtf; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (aspmx1.migadu.com: domain of "emacs-orgmode-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="emacs-orgmode-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 58D4329F1C X-Spam-Score: -3.63 X-Migadu-Scanner: scn1.migadu.com X-TUID: JVzX8vKQuzq2 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Rudolf Adamkovi=C4=8D writes: > Inspired by Protesilaos Stavrou, I started using uppercase Org keywords. > I like the results so far, but I also noticed some inflexibility in the > Org mode. Specifically, the `org-insert-structure-template' procedure > hard-codes lowercase "begin_" and "end_". Thus, even if one customizes > the `org-structure-template-alist' with uppercase keywords, Org still > inserts them as "begin_SRC". Given that Org lets the user pick their > preferred style, I consider this a bug. I would not call it a bug, but the situation can certainly be improved. We can auto-magically determine whether to use BEGIN_ or begin_ depending on the case in template type. Tentative patch attached. Best, Ihor --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Auto-Upcase-downcase-begin-end-in-structure-template.patch >From bdf8340ab8b41f0c9f26f5b0bdadbf079b8f6d66 Mon Sep 17 00:00:00 2001 Message-Id: From: Ihor Radchenko Date: Sun, 20 Mar 2022 20:15:21 +0800 Subject: [PATCH] Auto-Upcase/downcase #+begin/#+end in structure templates * lisp/org-tempo.el (org-tempo-add-block): * lisp/org.el (org-insert-structure-template): When inserting #+begin_type/#+end_type, follow type's case. TYPE will become #+BEGIN_TYPE and type will become #+bein_type. (org-insert-structure-template): Make sure that we use case-insensitive match even when user changes case-fold-search value. (org-structure-template-alist): Clarify selection of #+BEGIN/END vs. #+begin/end in the docstring. --- lisp/org-tempo.el | 13 ++++++++++--- lisp/org.el | 19 +++++++++++++------ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/lisp/org-tempo.el b/lisp/org-tempo.el index b34007bf7..cd5ef9e8e 100644 --- a/lisp/org-tempo.el +++ b/lisp/org-tempo.el @@ -119,11 +119,18 @@ (defun org-tempo-add-block (entry) "Add block entry from `org-structure-template-alist'." (let* ((key (format "<%s" (car entry))) (name (cdr entry)) - (special (member name '("src" "export")))) + (special (member name '("src" "export"))) + (upcase? (string= (car (split-string name)) + (upcase (car (split-string name)))))) (tempo-define-template (format "org-%s" (replace-regexp-in-string " " "-" name)) - `(,(format "#+begin_%s%s" name (if special " " "")) + `(,(format "#+%s_%s%s" + (if upcase? "BEGIN" "begin") + name + (if special " " "")) ,(when special 'p) '> n ,(unless special 'p) n - ,(format "#+end_%s" (car (split-string name " "))) + ,(format "#+%s_%s" + (if upcase? "END" "end") + (car (split-string name " "))) >) key (format "Insert a %s block" name) diff --git a/lisp/org.el b/lisp/org.el index 9455c15c8..26617d7c8 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -9492,7 +9492,9 @@ (defcustom org-structure-template-alist "An alist of keys and block types. `org-insert-structure-template' will display a menu with this list of templates to choose from. The block type is inserted, -with \"#+BEGIN_\" and \"#+END_\" added automatically. +with \"#+begin_\" and \"#+end_\" added automatically. If the block +type is written using upper case letter, \"#+BEGIN_\" and \"#+END_\" +are added instead. The menu keys are defined by the car of each entry in this alist. If two entries have the keys \"a\" and \"aa\" respectively, the @@ -9624,18 +9626,23 @@ (defun org-insert-structure-template (type) Select a block from `org-structure-template-alist' then type either RET, TAB or SPC to write the block type. With an active region, wrap the region in the block. Otherwise, insert an empty -block." +block. + +When foo is written as FOO, upcase the #+BEGIN/END as well." (interactive (list (pcase (org--insert-structure-template-mks) (`("\t" . ,_) (read-string "Structure type: ")) (`(,_ ,choice . ,_) choice)))) - (let* ((region? (use-region-p)) + (let* ((case-fold-search t) ; Make sure that matches are case-insnsitive. + (region? (use-region-p)) (region-start (and region? (region-beginning))) (region-end (and region? (copy-marker (region-end)))) (extended? (string-match-p "\\`\\(src\\|export\\)\\'" type)) (verbatim? (string-match-p (concat "\\`" (regexp-opt '("example" "export" "src"))) - type))) + type)) + (upcase? (string= (car (split-string type)) + (upcase (car (split-string type)))))) (when region? (goto-char region-start)) (let ((column (current-indentation))) (if (save-excursion (skip-chars-backward " \t") (bolp)) @@ -9643,7 +9650,7 @@ (defun org-insert-structure-template (type) (insert "\n")) (save-excursion (indent-to column) - (insert (format "#+begin_%s%s\n" type (if extended? " " ""))) + (insert (format "#+%s_%s%s\n" (if upcase? "BEGIN" "begin") type (if extended? " " ""))) (when region? (when verbatim? (org-escape-code-in-region (point) region-end)) (goto-char region-end) @@ -9652,7 +9659,7 @@ (defun org-insert-structure-template (type) (end-of-line)) (unless (bolp) (insert "\n")) (indent-to column) - (insert (format "#+end_%s" (car (split-string type)))) + (insert (format "#+%s_%s" (if upcase? "END" "end") (car (split-string type)))) (if (looking-at "[ \t]*$") (replace-match "") (insert "\n")) (when (and (eobp) (not (bolp))) (insert "\n"))) -- 2.34.1 --=-=-=--