From mboxrd@z Thu Jan 1 00:00:00 1970 From: Carsten Dominik Subject: Re: Saving the *Org Edit Src Example* buffer Date: Tue, 2 Jun 2009 19:04:56 +0200 Message-ID: <8216B89D-C718-4604-AAC4-82BFCA967161@gmail.com> References: <873aain0f7.fsf@stats.ox.ac.uk> Mime-Version: 1.0 (Apple Message framework v935.3) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Return-path: Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MBXRA-0006jA-7h for emacs-orgmode@gnu.org; Tue, 02 Jun 2009 13:06:08 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MBXR5-0006ZB-6I for emacs-orgmode@gnu.org; Tue, 02 Jun 2009 13:06:07 -0400 Received: from [199.232.76.173] (port=48564 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MBXR5-0006Ys-0p for emacs-orgmode@gnu.org; Tue, 02 Jun 2009 13:06:03 -0400 Received: from mx20.gnu.org ([199.232.41.8]:51579) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MBXR4-0002c3-C3 for emacs-orgmode@gnu.org; Tue, 02 Jun 2009 13:06:02 -0400 Received: from mail-ew0-f162.google.com ([209.85.219.162]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MBXR3-0007bK-D5 for emacs-orgmode@gnu.org; Tue, 02 Jun 2009 13:06:01 -0400 Received: by ewy6 with SMTP id 6so11493534ewy.42 for ; Tue, 02 Jun 2009 10:06:00 -0700 (PDT) In-Reply-To: <873aain0f7.fsf@stats.ox.ac.uk> 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: Dan Davison Cc: emacs org-mode mailing list Hi Dan, On Jun 2, 2009, at 5:02 PM, Dan Davison wrote: > Following on from the recent improvements to the *Org Edit Src > Example* > buffer, I have one more proposal: I have remapped C-x C-s so that it > saves the code in the org buffer, rather than offering to save the > Edit > buffer itself (as it used to be with the indirect edit buffer). I find > this essential, although I recognise that remapping C-x C-s is a > rather > radical thing to do to an emacs buffer. But allowed: From the Emacs lisp docs, under Major Mode Conventions: It is legitimate for a major mode to rebind a standard key sequence if it provides a command that does "the same job" in a way better suited to the text this mode is used for. I'd say, your's is a perfect example for this rule. > I am using the simple-minded approach below; it seems to work fine (I > don't even notice a flicker -- should I be surprised at that?), but if > someone can suggest an improved implementation I'd be happy to learn > how > it should be done (perhaps there are buffer variables other than point > and mark that I should restore? Is there a general mechanism I should > use for this?). > > Dan > > (defun org-edit-src-save () > "Update the parent org buffer with the edited source code, save > the parent org-buffer, and return to the source code edit > buffer." > (interactive) > (let ((p (point)) > (m (mark))) > (org-edit-src-exit) > (save-buffer) > (org-edit-src-code) > (set-mark m) > (goto-char p))) This is already excellent. I have changed it only slightly, in order to get a better message when this command finishes, and because `push-mark' should be used here instead of `set-mark'. (defun org-edit-src-save () "Save parent buffer with current state source-code buffer." (interactive) (let ((p (point)) (m (mark)) msg) (org-edit-src-exit) (save-buffer) (setq msg (current-message)) (org-edit-src-code) (push-mark m 'nomessage) (goto-char p) (message (or msg "")))) I have added your code, thanks. - Carsten