[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org 9632401dc6 3/3: Auto-Upcase/downcase #+begin/#+end
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org 9632401dc6 3/3: Auto-Upcase/downcase #+begin/#+end in structure templates |
Date: |
Sat, 18 Jun 2022 02:58:03 -0400 (EDT) |
branch: externals/org
commit 9632401dc6affc09e573e4af7c8898990cd8f04c
Author: Ihor Radchenko <yantar92@gmail.com>
Commit: Ihor Radchenko <yantar92@gmail.com>
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.
* etc/ORG-NEWS (Structure templates now respect case used in
~org-structure-template-alist~): Document the change.
---
etc/ORG-NEWS | 5 +++++
lisp/org-tempo.el | 13 ++++++++++---
lisp/org.el | 23 +++++++++++++++--------
3 files changed, 30 insertions(+), 11 deletions(-)
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 198684b8fa..4702da9b5f 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -222,6 +222,11 @@ produce results superior to Minted or Listings.
*** Support for =#+include=-ing URLs
=#+include: FILE= will now accept URLs as the file.
+*** Structure templates now respect case used in
~org-structure-template-alist~
+
+The block type in ~org-structure-template-alist~ is not case-sensitive.
+When the block type starts from the upper case, structure template
+will now insert =#+BEGIN_TYPE=. Previously, lower-case =#+begin_type= was
inserted unconditionally.
** New functions and changes in function arguments
diff --git a/lisp/org-tempo.el b/lisp/org-tempo.el
index ed71431751..f9a913ec2d 100644
--- a/lisp/org-tempo.el
+++ b/lisp/org-tempo.el
@@ -118,11 +118,18 @@ Go through `org-structure-template-alist' and
"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 3e9e146b4f..2005005675 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -8601,9 +8601,11 @@ keywords relative to each registered export back-end."
("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
@@ -8735,18 +8737,23 @@ If an element cannot be made unique, an error is
raised."
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))
@@ -8754,7 +8761,7 @@ block."
(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)
@@ -8763,7 +8770,7 @@ block."
(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")))