From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: function for inserting a block Date: Mon, 30 Oct 2017 12:05:44 +0100 Message-ID: <87r2tmwcrv.fsf@nicolasgoaziou.fr> References: <877exghblx.fsf@ericabrahamsen.net> <87po9q2e8k.fsf@nicolasgoaziou.fr> <87tvyyvpst.fsf@ericabrahamsen.net> <87fuaiz069.fsf@nicolasgoaziou.fr> <87lgk9eo4d.fsf@ericabrahamsen.net> <87fuahxxvs.fsf@nicolasgoaziou.fr> <87r2u1cuwj.fsf@ericabrahamsen.net> <87infdctzq.fsf@ericabrahamsen.net> <87k1zsbizs.fsf@ericabrahamsen.net> <87k1zp4rxj.fsf@ericabrahamsen.net> <871slx4j6p.fsf@ericabrahamsen.net> <87r2ttoq5k.fsf@ericabrahamsen.net> <871sltst0t.fsf@nicolasgoaziou.fr> <87y3o14cul.fsf@ericabrahamsen.net> <87po9czqy8.fsf@nicolasgoaziou.fr> <87she2rjqr.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49839) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e97tB-0001UF-2M for emacs-orgmode@gnu.org; Mon, 30 Oct 2017 07:05:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e97t6-0007pf-42 for emacs-orgmode@gnu.org; Mon, 30 Oct 2017 07:05:53 -0400 Received: from relay4-d.mail.gandi.net ([2001:4b98:c:538::196]:42534) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e97t5-0007n9-TZ for emacs-orgmode@gnu.org; Mon, 30 Oct 2017 07:05:48 -0400 In-Reply-To: <87she2rjqr.fsf@ericabrahamsen.net> (Eric Abrahamsen's message of "Sat, 28 Oct 2017 15:27:24 -0700") 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: Eric Abrahamsen Cc: emacs-orgmode@gnu.org Hello, Eric Abrahamsen writes: > This will get there eventually! Because there's likely to be more > tweaking, I haven't touched the manual or the tests yet, just reworked > the option and function: Thank you. Some comments follow. > #+BEGIN_SRC elisp > (defcustom org-structure-template-alist > '((?s . "SRC") > (?e . "EXAMPLE") > (?E . "EXPORT") > (?q . "QUOTE") > (?v . "VERSE") > (?V . "VERBATIM") This block type doesn't exist. You can remove it. > (?c . "CENTER") > (?C . "COMMENT") > (?l . "EXPORT latex") > (?L . "#+LaTeX") #+LATEX or #+latex (see below) > (?h . "EXPORT html") > (?H . "#+HTML") > (?a . "EXPORT ascii") > (?A . "#+ASCII") > (?i . "#+INDEX") > (?I . "#+INCLUDE")) As suggested by Rasmus once, maybe we could get away from FORTRAN touch and insert everything lowercase. > "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. Hitting will prompt > for a structure. I would remove "Hitting prompts for a structure." which belongs to the function's docstring, not to variable's. > Structure strings prefixed with a \"#+\" are inserted with no > further processing. Strings without this prefix are used to > create a block structure, with \"#+BEGIN\" and \"#+END\" added > automatically. I'm not sure about this part. I understand the backward-compatibility concern, but it sounds a bit alien to the purpose of the function, i.e., there is no wrapping around, it is not an "environment" either. WDYT? > WHAT TO DO ABOUT THIS PART? > There are two templates for each key, the first uses the original Org > syntax, You can remove it. > the second uses Emacs Muse-like syntax tags. These Muse-like tags become > the default when the /org-mtags.el/ module has been loaded. See also the > variable `org-mtags-prefer-muse-templates'." > :group 'org-completion > :type '(repeat > (cons > (character :tag "Key") > (string :tag "Template"))) > :version "26.1" > :package-version '(Org . "8.3")) You need to update :version and :package-version. Technically, if :package-version is provided, we should only use it, IIUC. > (defun org-insert-structure-template (&optional type) > "Insert a block structure of the type #+BEGIN_FOO/#+END_FOO. > This function first reads a character, which can be one of the > keys in `org-structure-template-alist'. It can also be , in > which case the user is prompted for a string to use. "When it is , prompt the user for a string to use." > (interactive) > (let* ((key (read-key "Key: ")) > (struct-string > (or (cdr-safe (assq key org-structure-template-alist)) `cdr-safe' -> `cdr' > (when (= key ?\t) > (read-string "Structure type: ")) Nitpick: (and (eq key ?\t) (read-string ...)) > (error "'%c' has no structure definition" key)))) > (if (string-prefix-p "#+" struct-string) > (progn > (insert (format "%s: " struct-string)) > (when (string= "#+INCLUDE" struct-string) > (insert > (format "\"%s\"" > (abbreviate-file-name > (read-file-name "Include file: ")))))) See above. Regards, -- Nicolas Goaziou