From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bernt Hansen Subject: Re: shortcut keys for mark ups Date: Wed, 07 Jan 2009 17:16:02 -0500 Message-ID: <87fxjuzrrx.fsf@gollum.intra.norang.ca> References: <49638861.2050606@cornell.edu> <87sknwz5pe.fsf@gollum.intra.norang.ca> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LKghG-00050F-0t for emacs-orgmode@gnu.org; Wed, 07 Jan 2009 17:16:18 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LKghE-000503-Hh for emacs-orgmode@gnu.org; Wed, 07 Jan 2009 17:16:16 -0500 Received: from [199.232.76.173] (port=43267 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LKghE-000500-BO for emacs-orgmode@gnu.org; Wed, 07 Jan 2009 17:16:16 -0500 Received: from mho-02-bos.mailhop.org ([63.208.196.179]:62045) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LKghE-0000RF-2J for emacs-orgmode@gnu.org; Wed, 07 Jan 2009 17:16:16 -0500 In-Reply-To: (Patrick Drechsler's message of "Wed\, 07 Jan 2009 21\:27\:59 +0100") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Patrick Drechsler Cc: emacs-orgmode@gnu.org Patrick Drechsler writes: > Bernt Hansen schrieb: > [snipped nice code] > > How can I extend this function to wrap the current selection into a > > #+BEGIN_SRC > ...code... > #+END_SRC > > string while also interactively asking the user for a language string? > > ----------------------------------------------------------------- > ;; ============================================================ > ;; Puts current selection between #+BEGIN_SRC and #+END_SRC > ;; and ask for language > ;; ============================================================ > ;; TODO: > ;; 1. Retrieve beginning (C-SPACE) and > ;; end of selection (current position) > ;; 2. Ask for language and insert that string > ;; after `#+BEGIN_SRC ' > (defun my-wrap-src () > (interactive) > (save-excursion > (beginning-of-line) > (insert "#+BEGIN_SRC\n") > (end-of-line) > (insert "\n#+END_SRC"))) > (define-key org-mode-map (kbd " s") 'my-wrap-src) > ----------------------------------------------------------------- > > Example org code before function call: > > ----------------------------------------------------------------- > * Sample Code > public class Bla { > public static void main(String[] args) { > System.out.println("Hello"); > } > } > ----------------------------------------------------------------- > > With the code above: > > - Mark the region: C-SPACE on the letter `p' of the string `public' > and moving the cursor behind the last closing curly bracket. > > - String after being asked for a language: `java' > > Example org code after function call: > > ----------------------------------------------------------------- > * Sample Code > #+BEGIN_SRC java > public class Bla { > public static void main(String[] args) { > System.out.println("Hello"); > } > } > #+END_SRC > ----------------------------------------------------------------- Something like this maybe? It's not 100% to spec. I find regions that are entire lines easier to work with so the end point would be the beginning of the first line not in the region (not after the }) For me - triple clicking and dragging selects entire lines which works well for this. ------------------------------------------------------------------------ (defun my-wrap-src () (interactive) (let ((beg (region-beginning)) (end (region-end)) (src (read-from-minibuffer "Source type: " "java"))) (save-excursion (goto-char (region-end)) (insert "#+END_SRC\n") (goto-char (region-beginning)) (insert "#+BEGIN_SRC " src "\n")))) ------------------------------------------------------------------------ If you want your behaviour you probably jsut have to change (insert "#+END_SRC\n") to (insert "\n#+END_SRC") but that's untested. HTH, -Bernt