From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: [PATCH] Adjustment of point in Org-src buffer Date: Thu, 30 Sep 2010 11:01:43 +0100 Message-ID: <878w2jr1mg.fsf@stats.ox.ac.uk> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from [140.186.70.92] (port=39275 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P1FxZ-0003FA-He for emacs-orgmode@gnu.org; Thu, 30 Sep 2010 06:01:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1P1FxY-00041O-7f for emacs-orgmode@gnu.org; Thu, 30 Sep 2010 06:01:53 -0400 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:59520) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1P1FxX-000415-Uc for emacs-orgmode@gnu.org; Thu, 30 Sep 2010 06:01:52 -0400 Received: from blackcap.stats.ox.ac.uk (blackcap.stats [163.1.210.5]) by markov.stats.ox.ac.uk (8.13.6/8.13.6) with ESMTP id o8UA1ofV020664 for ; Thu, 30 Sep 2010 11:01:50 +0100 (BST) 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: emacs org-mode mailing list Currently, if point is in the #+end_src line, then in the org-src edit buffer it goes to the beginning of the last line. There are two patches below. Patch 1 changes this so that point goes to the end of the last line of code. This gives nicer behaviour when creating an active region in the edit buffer. Patch 2 places a save-excursion round this, and gets rid of an org-goto-line, so that point in the Org buffer is not affected by generating the edit buffer. Patch 1: Adjustment of location of point when generating org-src edit buffer ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --8<---------------cut here---------------start------------->8--- diff --git a/lisp/org-src.el b/lisp/org-src.el index 6c4c464..05580d9 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -211,9 +211,7 @@ buffer." (interactive) (unless (eq context 'save) (setq org-edit-src-saved-temp-window-config (current-window-configuration))) - (let ((line (org-current-line)) - (col (current-column)) - (mark (and (use-region-p) (mark))) + (let ((mark (and (use-region-p) (mark))) (case-fold-search t) (info (org-edit-src-find-region-and-lang)) (babel-info (org-babel-get-src-block-info)) @@ -223,7 +221,7 @@ buffer." (preserve-indentation org-src-preserve-indentation) (allow-write-back-p (null code)) block-nindent total-nindent ovl lang lang-f single lfmt buffer msg - begline markline markcol) + begline markline markcol line col) (if (not info) nil (setq beg (move-marker beg (nth 0 info)) @@ -254,6 +252,9 @@ buffer." (org-set-local 'org-edit-src-content-indentation 0)))) (unless (functionp lang-f) (error "No such language mode: %s" lang-f)) + (if (> (point) end) (goto-char end)) + (setq line (org-current-line) + col (current-column)) (org-goto-line line) (if (and (setq buffer (org-edit-src-find-buffer beg end)) (if org-src-ask-before-returning-to-edit-buffer --8<---------------cut here---------------end--------------->8--- Patch 2: Don't move point when generating org-src edit buffer ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --8<---------------cut here---------------start------------->8--- diff --git a/lisp/org-src.el b/lisp/org-src.el index 05580d9..c1d579c 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -252,10 +252,10 @@ buffer." (org-set-local 'org-edit-src-content-indentation 0)))) (unless (functionp lang-f) (error "No such language mode: %s" lang-f)) - (if (> (point) end) (goto-char end)) - (setq line (org-current-line) - col (current-column)) - (org-goto-line line) + (save-excursion + (if (> (point) end) (goto-char end)) + (setq line (org-current-line) + col (current-column))) (if (and (setq buffer (org-edit-src-find-buffer beg end)) (if org-src-ask-before-returning-to-edit-buffer (y-or-n-p "Return to existing edit buffer? [n] will revert changes: ") t)) --8<---------------cut here---------------end--------------->8--- Dan