From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id GBuuMsQTO2LrJAEAgWs5BA (envelope-from ) for ; Wed, 23 Mar 2022 13:34:12 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id WE4QMMQTO2L9AgEA9RJhRA (envelope-from ) for ; Wed, 23 Mar 2022 13:34:12 +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 12067F5D7 for ; Wed, 23 Mar 2022 13:34:12 +0100 (CET) Received: from localhost ([::1]:41088 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nX0Bm-0003FS-3b for larch@yhetil.org; Wed, 23 Mar 2022 08:34:10 -0400 Received: from eggs.gnu.org ([209.51.188.92]:45324) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nWzeE-0005rf-JP for emacs-orgmode@gnu.org; Wed, 23 Mar 2022 07:59:31 -0400 Received: from [2607:f8b0:4864:20::1032] (port=52117 helo=mail-pj1-x1032.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nWzeC-0005Lx-CH for emacs-orgmode@gnu.org; Wed, 23 Mar 2022 07:59:30 -0400 Received: by mail-pj1-x1032.google.com with SMTP id gb19so1440597pjb.1 for ; Wed, 23 Mar 2022 04:59:28 -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=5jVOTwBVSyLaqk/vSjrX3+9WR5A791J55mhe+TYfLMU=; b=oJo7Jrco28OJPAyR9KnNXogFAcMFR8U3nX1GkdjbWX3Bert/yTSamCsmWybAbdlnXR Go812x9+hJHfI2ZgehVmCXDFifq45PzF3jOvcEWYklvOPFkdDDrCqxJzP2kiXnUmNXOM XOS9i6qPmWtq2z2Qw5OANnSt49MQir8NRU1gFB4uy71n5uw8QQnRzM9GENI0/W3VlDoU k9g+crc8BI95S+QA3ETYJADIg+RuxkuvNZ4/Jy766DuDGRitfvfxtZ+2jvkg6fTFaOqK 9tW6YNLFi5Tm5b/k5H179OkjUaLqa9ImyqSjI3Tt5LYrgBKohPDigrLa3WV1DgSnJsDL 7K9Q== 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=5jVOTwBVSyLaqk/vSjrX3+9WR5A791J55mhe+TYfLMU=; b=DYZRwF1dDhoAaw4mjqfJqmBleFWSGlMS2GPid2CFOjHYXs4g5sE/Or0/9lE7wY+FY5 KMlXMwD7EpIfvKcykr2HGPqfseQHRnjfrEkFm2nPPcnNzTgAZTVVKF6C5SzhwzGlDyLW Zr64irNTaNQWHKAQcrrRZjhe1zaOn/05GjFeHUmPK/fQWC0JVnIzRGb0whunm6vz/+oW ux7NHb/h3OOFxWKzeLdwNFTAqV7ByWENYU8Hmth1JooJ48gl3M65rPeu9SKXd2Fm5hiQ rtHlpglyE/VB9VTYT/r1Z67kRQAYMQBTWaoh6aDcglJiC5Zzba9dS8ynZWkpLWPGCfic eKhw== X-Gm-Message-State: AOAM53239iw/w1KLSSWaTEcYympWOUEAfJayfTDLtYHwfdurogoxZ9JF RkiuaqEm2+JfQod8RPwrrjI= X-Google-Smtp-Source: ABdhPJzXMo/pe/xwPBBPBgSrH69cXz4TvjlR2NFoPzZk9g0WmmL1ivCuyYyyrG7buosX/O7Unu64Yw== X-Received: by 2002:a17:902:9345:b0:153:4d7a:53d9 with SMTP id g5-20020a170902934500b001534d7a53d9mr23914348plp.116.1648036767095; Wed, 23 Mar 2022 04:59:27 -0700 (PDT) Received: from localhost ([209.95.60.92]) by smtp.gmail.com with ESMTPSA id p34-20020a056a000a2200b004cd49fc15e5sm28118663pfh.59.2022.03.23.04.59.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Mar 2022 04:59:26 -0700 (PDT) From: Ihor Radchenko To: Rudolf =?utf-8?Q?Adamkovi=C4=8D?= Subject: Re: [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: <871qywerpi.fsf@localhost> Date: Wed, 23 Mar 2022 19:59:50 +0800 Message-ID: <87czicubex.fsf@localhost> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::1032 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=yantar92@gmail.com; helo=mail-pj1-x1032.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=1648038852; 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=5jVOTwBVSyLaqk/vSjrX3+9WR5A791J55mhe+TYfLMU=; b=TLdw2mS4b6nSPPUfSoUsBhEgOHPum0OrwE34fuRGmasDSvf5T6db/u/IPLt+oU3iREP1zO 0GVKjelW8HJeEUgiMyJSIV5KtGfNolHAs4OpCjAC7zQ/oF2TaBWeQA5ReGX+PTfHn3cbw8 KfY+Ndttp/eJF3p7u4Ppi7ygKSdM0hwZFIPIpdV+v510vSRFFSwaVwlzoOUM4tEP4dhdzy SlNPLxTANnMIWpUjoH2/IMeyVgN5QDLTWMH0D9KvTAPbz1Q6i2P0G0KjJ3d0ldKByhHI0S Le1Y66HD5uH3kvDbgcvU6tBPpdaPX5mvTjfMWR00sgLFuoHU6PqQBpXE6ykWTQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1648038852; a=rsa-sha256; cv=none; b=NyZwfkzRSVQGLR5yinf447yHKt3xXIsgHacAhtWAJSsC4/b7fKVA6C8Slg1hWk9rJCBtFK q3L4+CVE88kadUmoqvvZTzgtQY1BWvMSINhCRrND6BNhQrBcTI969waB8UEhtIGlqfgYzR aNCys1Ed30nmeXhvhdZRCHziDQ4Iij/ivSZGuwYwBxc8G1QRRG2e7RqHq8yAd5BtUKbTOs wIQMydaKqj73vaWjs3BMYsiFJmdIO09p/sY9iBp7fzpEFmdNtIr/iZTQewQWXyLQSUR6pM 6IntNTaJutJOXp8rerLuwy7DHvG4xa9/d9sDV6TQmy1riJug9oRE2AAF3mSRqw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=oJo7Jrco; 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: -8.60 Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=oJo7Jrco; 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: 12067F5D7 X-Spam-Score: -8.60 X-Migadu-Scanner: scn0.migadu.com X-TUID: 2JtmMg+I1v7C --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Rudolf Adamkovi=C4=8D writes: >> +with \"#+begin_\" and \"#+end_\" added automatically. If the block >> +type is written using upper case letter, \"#+BEGIN_\" and \"#+END_\" >> +are added instead. > > FYI: A typo in "letter" (expected "letters") > > (We could also simplify to: "if the block type consists of just > uppercase letter".) > >> + (let* ((case-fold-search t) ; Make sure that matches are case-insnsit= ive. >> + (region? (use-region-p)) > > FYI: A typo in "case-insnsitive" (expected "case-insensitive") Thanks for proofreading! Attaching the fixed version of the patch. Best, Ihor --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Auto-Upcase-downcase-begin-end-in-structure-template.patch >From b39925decd0e5ee5a0ce88b3fcea3a9647d35001 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 | 23 +++++++++++++++-------- 2 files changed, 25 insertions(+), 11 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..529146097 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -9490,9 +9490,11 @@ (defcustom org-structure-template-alist ("s" . "src") ("v" . "verse")) "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. +`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. If the block type +consists of just uppercase letters, \"#+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-insensitive. + (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 --=-=-=--