From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: function for inserting a block Date: Sun, 03 Sep 2017 10:10:39 +0200 Message-ID: <87efromccg.fsf@nicolasgoaziou.fr> References: <877exghblx.fsf@ericabrahamsen.net> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40276) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1doPzT-0006mm-F2 for emacs-orgmode@gnu.org; Sun, 03 Sep 2017 04:10:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1doPzO-0003mY-J7 for emacs-orgmode@gnu.org; Sun, 03 Sep 2017 04:10:47 -0400 Received: from relay2-d.mail.gandi.net ([2001:4b98:c:538::194]:42925) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1doPzN-0003lJ-Vu for emacs-orgmode@gnu.org; Sun, 03 Sep 2017 04:10:42 -0400 In-Reply-To: <877exghblx.fsf@ericabrahamsen.net> (Eric Abrahamsen's message of "Sat, 02 Sep 2017 17:25:30 -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: > The easy template entry thing is useful as far as it goes, but for some > reason I find myself "marking up" existing text in Org as least as often > as I'm writing new text from scratch. I've always wanted a "wrap region > in block" command, and finally wrote one. Don't know why it took me so > long. Would something like this be attractive for inclusion in Org? Thanks. I agree Org needs something like this. > (defun org-insert-structure-template (type start end) > "Insert a block structure as in #+BEGIN_TYPE/#+END_TYPE. > > Prompts for a block TYPE, and inserts the block. With an active > region, wrap the region in the block." > (interactive "sBlock type: \nr") > (let ((s (set-marker (make-marker) start)) > (e (set-marker (make-marker) end))) (set-marker (make-marker) start) -> (copy-marker start) You need to clean these markers at the end of the function. Markers set to a position are never garbage-collected. Usually, it happens at the end of an `unwind-protect'. > (goto-char s) > (goto-char (line-beginning-position)) > (insert (format "#+BEGIN_%s\n" (upcase type))) (upcase type) is wrong, because special blocks are case sensitive. > (goto-char e) > (goto-char (line-end-position)) (end-of-line) ? > (insert (format "\n#+END_%s" (upcase type))))) The function also needs to take care about global indentation. Inserting at column 0 may not be desirable. What happens if no region is active? Can it mark the element at point (see `org-mark-element')? What happens if the chosen type is verbatim (e.g. "example"), can it protect "#+", "*" and so on with commas (see `org-escape-code-in-region')? > If this is acceptable, I'd like to bind it to "C-c i", and would provide > docs. We cannot bind it to "C-c i", this is a reserved key-binding. But we can suggest users to do so in the manual. Or find another binding. Regards, -- Nicolas Goaziou