From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: function for inserting a block Date: Thu, 09 Nov 2017 17:11:57 +0100 Message-ID: <87tvy3sa7m.fsf@gmx.us> References: <877exghblx.fsf@ericabrahamsen.net> <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> <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> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55479) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eCpR6-0004mN-LJ for emacs-orgmode@gnu.org; Thu, 09 Nov 2017 11:12:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eCpR3-0006ag-4U for emacs-orgmode@gnu.org; Thu, 09 Nov 2017 11:12:12 -0500 Received: from [195.159.176.226] (port=49198 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eCpR2-0006Zm-Pr for emacs-orgmode@gnu.org; Thu, 09 Nov 2017 11:12:09 -0500 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1eCpQq-00035L-8u for emacs-orgmode@gnu.org; Thu, 09 Nov 2017 17:11:56 +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: > Nicolas Goaziou writes: > >> Takaaki Ishikawa writes: >> >>> I also support the idea of keeping ">> Please give importance to the backward compatibility in this case. >> >> I explained why I thought it could be removed. I also suggested >> solutions to get an equivalent feature without implementing it in Org. > > Which sounds fair. > >> What is wrong with Abbrev mode, skeletons, tempo.el, expand.el, all >> bundled with Emacs, or YASnippet, in the Emacs ecosystem? It sounds like >> NIH. Or, to put it differently: why in the world would Org implement its >> own template system? > > tempo.el, which I was unaware of, will be able to do this. Thanks for the > pointer. > > I have started to write a replacement. It seems to work fairly OK so far. > Not all keywords have been added, and no mechanism for adding additional > keywords is there yet. > > Nicolas, what would be the best way to hook ‘tempo-complete-tag’ into > "space"? Should I add support directly in org-self-insert-command or add > it to post-command-hook? Actually, it should just hook into TAB (doh). The attached version seems to replicate the old behavior more or less. I had to add a new custom variable to store keywords. 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 " ;; Keywords: outlines, hypermedia, calendar, wp ;; Homepage: http://orgmode.org ;; ;; This file is part of GNU Emacs. ;; ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;; ;;; Commentary: ;; ;;; Code: (require 'tempo) (require 'cl-lib) (defvar org-tempo-tags nil "Tempo tags for org-mode") (defcustom org-structure-template-alist-keywords '((?L . "latex") (?H . "html") (?A . "ascii") (?i . "index")) "Keyword templates like `org-structure-template-alist' expanded via ." :group 'org-tempo :type '(repeat (cons (character :tag "Key") (string :tag "Template"))) :package-version '(Org . "9.2")) (defun org-tempo-setup () (tempo-use-tag-list 'org-tempo-tags) (setq-local tempo-match-finder "^ *\\(<[[:word:]]\\)\\=3D")) (add-hook 'org-mode-hook 'org-tempo-setup) (defun org-tempo-add-templates () "Update all org-tempo templates. Goes through `org-structure-template-alist' and `org-structure-template-alist-keywords'." (let ((keys (mapcar (apply-partially 'format "<%c") (mapcar 'car (append org-structure-template-alist org-structure-template-alist-keywords))))) (if (> (length keys) (length (delete-dups keys))) (user-error "Duplicated keys in `org-structure-template-alist' and `org-st= ructure-template-alist-keywords'")) (mapcar (lambda (key) (if (assoc-string key org-tempo-tags) (setq org-tempo-tags (delete (assoc-string key org-tempo-tags) org-tempo-tags)))) keys) (mapcar 'org-tempo-add-block org-structure-template-alist) (mapcar 'org-tempo-add-keyword org-structure-template-alist-keywords)) (setq tempo-dirty-collection t)) (defun org-tempo-add-block (entry) "Add block entry from `org-structure-template-alist'." (let* ((key (format "<%c" (car entry))) (name (cdr entry))) (tempo-define-template (format "org-%s" (replace-regexp-in-string " " "= -" name)) `(,(format "#+begin_%s " name) p '> n n ,(format "#+end_%s" (car (org-split-string name " "))) >) key (format "Insert a %s block" name) 'org-tempo-tags))) (defun org-tempo-add-keyword (entry) "Add keyword entry from `org-structure-template-alist-keywords'." (let* ((key (format "<%c" (car entry))) (name (cdr entry))) (tempo-define-template (format "org-%s" (replace-regexp-in-string " " "= -" name)) `(,(format "#+%s: " name) p '>) key (format "Insert a %s keyword" name) 'org-tempo-tags))) ;;; Additional keywords (tempo-define-template "org-include" '("#+include: " (ignore-errors (format "\"%s\" " (file-relative-name (read-file-name "Include file: = ")))) p >) "