From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Abrahamsen Subject: Re: function for inserting a block Date: Fri, 10 Nov 2017 09:27:36 -0800 Message-ID: <87mv3um4c7.fsf@ericabrahamsen.net> References: <877exghblx.fsf@ericabrahamsen.net> <87infdctzq.fsf@ericabrahamsen.net> <87k1zsbizs.fsf@ericabrahamsen.net> <87k1zp4rxj.fsf@ericabrahamsen.net> <871slx4j6p.fsf@ericabrahamsen.net> <87376btslq.fsf@nicolasgoaziou.fr> <87vaj7oyxb.fsf@ericabrahamsen.net> <871sl9ow44.fsf@gnu.org> <87fu9pgfkj.fsf@nicolasgoaziou.fr> <87375ouanr.fsf@gmx.us> <871sl8e76c.fsf@nicolasgoaziou.fr> <87y3nfse6m.fsf@gmx.us> <87tvy3sa7m.fsf@gmx.us> <87bmkbflbc.fsf@ericabrahamsen.net> <87po8qscmq.fsf@gmx.us> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:48484) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDD5z-0000Ym-SA for emacs-orgmode@gnu.org; Fri, 10 Nov 2017 12:28:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDD5w-0006KA-LG for emacs-orgmode@gnu.org; Fri, 10 Nov 2017 12:27:59 -0500 Received: from [195.159.176.226] (port=45049 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eDD5w-0006IA-DE for emacs-orgmode@gnu.org; Fri, 10 Nov 2017 12:27:56 -0500 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1eDD5j-0002b2-4A for emacs-orgmode@gnu.org; Fri, 10 Nov 2017 18:27:43 +0100 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Rasmus writes: > Hi Eric, > > Eric Abrahamsen writes: > >>> Also, Eric, it seems that org-structure-template-alist only supports a >>> single letter for short-hands (the car of an entry in >>> org-structure-template-alist is a char). I used to have blocks like ">> expanding to an "abstract" special-block, which I guess isn’t possible >>> anymore? >> >> I hadn't thought of that. Really, all I ever wanted was to wrap things >> in blocks... >> >> I don't see any reason why org-structure-template-alist couldn't go back >> to using string keys. Then we could use read-string, and wouldn't have >> to have special behavior -- a string that didn't exist in the >> alist could just be used literally to make a block. > > I’d prefer that. For some special blocks, a few characters might makes it > more intuitive, e.g. "def" → "definition", "hyp" → "hypothesis" etc. Here's the simplest solution. There still remains the fact that `org-structure-template-alist' has changed format, and `org-try-structure-completion' no longer exists. That may still annoy some people who were using the internals of the process, but... --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=stringkeys.diff diff --git a/lisp/org.el b/lisp/org.el index f873f1021..7c451d525 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -11857,42 +11857,40 @@ keywords relative to each registered export back-end." "TITLE:" "TODO:" "TYP_TODO:" "SELECT_TAGS:" "EXCLUDE_TAGS:")) (defcustom org-structure-template-alist - '((?a . "export ascii") - (?c . "center") - (?C . "comment") - (?e . "example") - (?E . "export") - (?h . "export html") - (?l . "export latex") - (?q . "quote") - (?s . "src") - (?v . "verse")) + '(("a" . "export ascii") + ("c" . "center") + ("C" . "comment") + ("e" . "example") + ("E" . "export") + ("h" . "export html") + ("l" . "export latex") + ("q" . "quote") + ("s" . "src") + ("v" . "verse")) "Structure completion elements. This is an alist of characters and values. When -`org-insert-structure-template' is called, an additional key is -read. The key is first looked up in this alist, and the -corresponding structure is inserted, with \"#+BEGIN_\" and -\"#+END_\" added automatically." +`org-insert-structure-template' is called, a string key is read. +The key is first looked up in this alist, and the corresponding +structure is inserted, with \"#+BEGIN_\" and \"#+END_\" added +automatically." :group 'org-completion :type '(repeat - (cons (character :tag "Key") + (cons (string :tag "Key") (string :tag "Template"))) :package-version '(Org . "9.2")) (defun org-insert-structure-template (type) "Insert a block structure of the type #+begin_foo/#+end_foo. -First read a character, which can be one of the keys in -`org-structure-template-alist'. When it is , prompt the -user for a string to use. With an active region, wrap the region -in the block. Otherwise, insert an empty block." +First read a string, which is used as a lookup key in +`org-structure-template-alist' or, failing that, used literally. +With an active region, wrap the region in the block. Otherwise, +insert an empty block." (interactive (list - (let* ((key (read-key "Key: ")) + (let* ((key (read-string "Key: ")) (struct-string - (or (cdr (assq key org-structure-template-alist)) - (and (= key ?\t) - (read-string "Structure type: ")) - (user-error "`%c' has no structure definition" key)))) + (or (cdr (assoc-string key org-structure-template-alist)) + key))) struct-string))) (let* ((region? (use-region-p)) (s (if region? (region-beginning) (point))) --=-=-=--