From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dan Davison Subject: Re: Re: [PATCH] Allow code edit buffer to inherit active region Date: Tue, 21 Sep 2010 15:25:27 +0100 Message-ID: <8762xz18dk.fsf@stats.ox.ac.uk> References: <871v992xzy.fsf@stats.ox.ac.uk> <87eicwcuw0.fsf@stats.ox.ac.uk> <2193BA26-48F8-42D2-A376-933E60756893@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from [140.186.70.92] (port=52954 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oy3nV-00028T-B3 for emacs-orgmode@gnu.org; Tue, 21 Sep 2010 10:27:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Oy3mj-0003YU-E1 for emacs-orgmode@gnu.org; Tue, 21 Sep 2010 10:26:17 -0400 Received: from markov.stats.ox.ac.uk ([163.1.210.1]:39816) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oy3mj-0003YI-4h for emacs-orgmode@gnu.org; Tue, 21 Sep 2010 10:25:29 -0400 In-Reply-To: <2193BA26-48F8-42D2-A376-933E60756893@gmail.com> (Carsten Dominik's message of "Tue, 21 Sep 2010 14:34:18 +0200") 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: Carsten Dominik Cc: emacs org-mode mailing list Carsten Dominik writes: > Hi Dan, > > both changes look good to me. OK, that is applied. So now, if the region is contained within a src block, then it will be inherited by the language major mode edit buffer. One consequence is that commands like M-; (comment-region) and C-M-\ (indent-region) can be called with their native effects from a src block in the Org buffer; see example below. Dan > > - Carsten > > On Sep 14, 2010, at 3:33 PM, Dan Davison wrote: > >> Dan Davison writes: >> >>> If we allow the current region to be inherited by the code edit >>> buffer >>> (patch below), then language major mode commands that operate on the >>> region can be called remotely from the org buffer. For example >>> >>> C-c C-v C-x M-; comment region according to language >>> C-c C-v C-x C-M-\ indent region according to language >>> >>> Users can make these more convenient, e.g. >>> >>> (defun my/org-comment-dwim (&optional arg) >>> (interactive "P") >>> (or (org-babel-do-key-sequence-in-edit-buffer "\M-;") >>> (comment-dwim arg))) >>> >>> (define-key org-mode-map "\M-;" 'my/org-comment-dwim) >>> >>> Dan >>> >>> Proposed patch: >>> ~~~~~~~~~~~~~~~ >> >> I would like to make one addition to this patch: adding >> >> (setq deactivate-mark nil) >> >> towards the end means that if the region is contained within the src >> block, then it will be active (and highlighted) in the edit buffer. >> >> Dan >> >>> >>> commit 6e14f016cdfe92357092461058def5d4073541e2 >>> Author: Dan Davison >>> Date: Sat Sep 4 13:43:56 2010 -0400 >>> >>> Transmit active region from Org buffer to code edit buffer >>> >>> * org-src.el (org-edit-src-code): If mark was inside code >>> block then code edit buffer inherits mark with active region. >>> >>> diff --git a/lisp/org-src.el b/lisp/org-src.el >>> index d1948cc..d0a9729 100644 >>> --- a/lisp/org-src.el >>> +++ b/lisp/org-src.el >>> @@ -209,6 +209,7 @@ buffer." >>> (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))) >>> (case-fold-search t) >>> (info (org-edit-src-find-region-and-lang)) >>> (babel-info (org-babel-get-src-block-info)) >>> @@ -217,7 +218,8 @@ buffer." >>> (end (make-marker)) >>> (preserve-indentation org-src-preserve-indentation) >>> (allow-write-back-p (null code)) >>> - block-nindent total-nindent ovl lang lang-f single lfmt >>> begline buffer msg) >>> + block-nindent total-nindent ovl lang lang-f single lfmt buffer msg >>> + begline markline markcol) >>> (if (not info) >>> nil >>> (setq beg (move-marker beg (nth 0 info)) >>> @@ -235,6 +237,10 @@ buffer." >>> block-nindent (nth 5 info) >>> lang-f (intern (concat lang "-mode")) >>> begline (save-excursion (goto-char beg) (org-current-line))) >>> + (if (and mark (>= mark beg) (<= mark end)) >>> + (save-excursion (goto-char mark) >>> + (setq markline (org-current-line) >>> + markcol (current-column)))) >>> (if (equal lang-f 'table.el-mode) >>> (setq lang-f (lambda () >>> (text-mode) >>> @@ -290,6 +296,11 @@ buffer." >>> (while (re-search-forward "^," nil t) >>> (if (eq (org-current-line) line) (setq total-nindent (1+ >>> total- >>> nindent))) >>> (replace-match ""))) >>> + (when markline >>> + (org-goto-line (1+ (- markline begline))) >>> + (org-move-to-column >>> + (if preserve-indentation markcol (max 0 (- markcol total- >>> nindent)))) >>> + (push-mark (point) 'no-message t)) >>> (org-goto-line (1+ (- line begline))) >>> (org-move-to-column >>> (if preserve-indentation col (max 0 (- col total-nindent)))) >>> >>> _______________________________________________ >>> Emacs-orgmode mailing list >>> Please use `Reply All' to send replies to the list. >>> Emacs-orgmode@gnu.org >>> http://lists.gnu.org/mailman/listinfo/emacs-orgmode >> >> _______________________________________________ >> Emacs-orgmode mailing list >> Please use `Reply All' to send replies to the list. >> Emacs-orgmode@gnu.org >> http://lists.gnu.org/mailman/listinfo/emacs-orgmode > > - Carsten