emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [patch] Check org-structure-template-alist
@ 2018-05-27 12:57 Rasmus
  2018-05-27 15:57 ` Aaron Ecay
  0 siblings, 1 reply; 3+ messages in thread
From: Rasmus @ 2018-05-27 12:57 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 644 bytes --]

Hi,

Here’s a patch that would check org-structure-template-alist for the "old"
format.

It just pops a user-error if the old format is detected (it checks if the
cdr of org-structure-template-alist entries is a list).

On my system, binding max-mini-window-height seems to have no effect.  My
test window-total-height is 35.

    (let ((max-mini-window-height 15))
      (message (mapconcat 'number-to-string (number-sequence 1 15) "\n")))

If there’s any better way to display the error or check if
org-structure-template-alist is in the "old" format let me know.

Rasmus 

-- 
Slowly unravels in a ball of yarn and the devil collects it

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Check-format-of-org-structure-template-alist.patch --]
[-- Type: text/x-patch, Size: 3082 bytes --]

From 7ae2fd392aaa5f76f65f4c88a0b1286167d6732a Mon Sep 17 00:00:00 2001
From: Rasmus <rasmus@gmx.us>
Date: Sun, 27 May 2018 14:44:49 +0200
Subject: [PATCH] Check format of org-structure-template-alist

* org.el (org--check-org-structure-template-alist): New function
  yielding user-error if using old org-structure-template-alist
  format.
  (org--insert-structure-template-mks):
* org-tempo.el (org-tempo-add-templates): Use new function
---
 lisp/org-tempo.el |  2 ++
 lisp/org.el       | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 38 insertions(+)

diff --git a/lisp/org-tempo.el b/lisp/org-tempo.el
index b9a554ff7..a651c7b37 100644
--- a/lisp/org-tempo.el
+++ b/lisp/org-tempo.el
@@ -102,6 +102,8 @@ Tempo templates will be added."
 
 Go through `org-structure-template-alist' and
 `org-tempo-keywords-alist' and update tempo templates."
+  (mapc 'org--check-org-structure-template-alist '(org-structure-template-alist
+						   org-tempo-keywords-alist))
   (let ((keys (org-tempo--keys)))
     ;; Check for duplicated snippet keys and warn if any are found.
     (when (> (length keys) (length (delete-dups keys)))
diff --git a/lisp/org.el b/lisp/org.el
index b05acd78a..c67e91489 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -11727,6 +11727,41 @@ block can be inserted by pressing TAB after the string \"<KEY\"."
 		(string :tag "Template")))
   :package-version '(Org . "9.2"))
 
+(defun org--check-org-structure-template-alist (&optional checklist)
+  "Check whether `org-structure-template-alist' is set up correctly.
+In particular, check if the Org 9.2 format is used as opposed to
+previous format.
+"
+  (let* ((elm (cl-remove-if-not (lambda (x) (listp (cdr x)))
+				(or (eval checklist)
+				    org-structure-template-alist)))
+	 (len (length elm))
+	 (maxlen 3)
+	 (resize-mini-windows t)
+	 (message-truncate-lines nil)
+	 (max-mini-window-height 15))
+    (when elm
+      (user-error
+       (mapconcat 'identity
+		  '("Please update the entries of `%s'."
+		    ""
+		    "In Org 9.2 the format was changed from something akin to"
+		    "   (\"s\" \"#+BEGIN_SRC ?\\n#+END_SRC\" "
+		    "to something akin to"
+		    "    (\"s\" . \"src\")"
+		    "See (info \"(org)org-structure-template-alist\")"
+		    ""
+		    "The following entries must be updated:"
+		    ""
+		    "%s"
+		    "%s")
+		  "\n")
+       (or checklist org-structure-template-alist)
+       (pp-to-string (cl-subseq elm 0 (min maxlen len)))
+       (if (> len maxlen)
+	   (format "... And %s other entries" (- len maxlen))
+	 "")))))
+
 (defun org--insert-structure-template-mks ()
   "Present `org-structure-template-alist' with `org-mks'.
 
@@ -11734,6 +11769,7 @@ Menus are added if keys require more than one keystroke.  Tabs
 are added to single key entries when more than one stroke is
 needed.  Keys longer than two characters are reduced to two
 characters."
+  (org--check-org-structure-template-alist)
   (let* (case-fold-search
 	 (templates (append org-structure-template-alist
 			    '(("\t" . "Press TAB, RET or SPC to write block name"))))
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [patch] Check org-structure-template-alist
  2018-05-27 12:57 [patch] Check org-structure-template-alist Rasmus
@ 2018-05-27 15:57 ` Aaron Ecay
  2018-05-28 21:49   ` Rasmus
  0 siblings, 1 reply; 3+ messages in thread
From: Aaron Ecay @ 2018-05-27 15:57 UTC (permalink / raw)
  To: Rasmus, emacs-orgmode

Hi Rasmus,

2018ko maiatzak 27an, Rasmus-ek idatzi zuen:

[...]

> If there’s any better way to display the error 

org-display-warning?

[...]

> +       (mapconcat 'identity
> +		  '("Please update the entries of `%s'."
> +		    ""
> +		    "In Org 9.2 the format was changed from something akin to"
> +		    "   (\"s\" \"#+BEGIN_SRC ?\\n#+END_SRC\" "
> +		    "to something akin to"
> +		    "    (\"s\" . \"src\")"
> +		    "See (info \"(org)org-structure-template-alist\")"
> +		    ""
> +		    "The following entries must be updated:"
> +		    ""
> +		    "%s"
> +		    "%s")
> +		  "\n")

You could use a multiline string literal.  IMO itʼs less ugly (but
still ugly...)
-- 
Aaron Ecay

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch] Check org-structure-template-alist
  2018-05-27 15:57 ` Aaron Ecay
@ 2018-05-28 21:49   ` Rasmus
  0 siblings, 0 replies; 3+ messages in thread
From: Rasmus @ 2018-05-28 21:49 UTC (permalink / raw)
  To: emacs-orgmode

Aaron Ecay <aaronecay@gmail.com> writes:

> Hi Rasmus,
>
> 2018ko maiatzak 27an, Rasmus-ek idatzi zuen:
>
> [...]
>
>> If there’s any better way to display the error 
>
> org-display-warning?

That’s great.  Thanks!

> [...]
>
>> +       (mapconcat 'identity
>> +		  '("Please update the entries of `%s'."
>> +		    ""
>> +		    "In Org 9.2 the format was changed from something akin to"
>> +		    "   (\"s\" \"#+BEGIN_SRC ?\\n#+END_SRC\" "
>> +		    "to something akin to"
>> +		    "    (\"s\" . \"src\")"
>> +		    "See (info \"(org)org-structure-template-alist\")"
>> +		    ""
>> +		    "The following entries must be updated:"
>> +		    ""
>> +		    "%s"
>> +		    "%s")
>> +		  "\n")
>
> You could use a multiline string literal.  IMO itʼs less ugly (but
> still ugly...)

Same difference to me.

Rasmus

-- 
C is for Cookie

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-05-28 21:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-27 12:57 [patch] Check org-structure-template-alist Rasmus
2018-05-27 15:57 ` Aaron Ecay
2018-05-28 21:49   ` Rasmus

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).