From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Leo Newsgroups: gmane.emacs.bugs Subject: bug#8463: 24.0.50; [PATCH] Direct Edit in *Occur* Buffer Date: Sun, 10 Apr 2011 16:14:53 +0800 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1302424658 23700 80.91.229.12 (10 Apr 2011 08:37:38 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 10 Apr 2011 08:37:38 +0000 (UTC) Cc: Daniel Colascione To: 8463@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Apr 10 10:37:34 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q8q9D-0006QV-IN for geb-bug-gnu-emacs@m.gmane.org; Sun, 10 Apr 2011 10:37:31 +0200 Original-Received: from localhost ([127.0.0.1]:40211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q8q9C-0004DW-PT for geb-bug-gnu-emacs@m.gmane.org; Sun, 10 Apr 2011 04:37:30 -0400 Original-Received: from [140.186.70.92] (port=42053 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q8q92-00048u-MO for bug-gnu-emacs@gnu.org; Sun, 10 Apr 2011 04:37:21 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q8q91-0002w6-LV for bug-gnu-emacs@gnu.org; Sun, 10 Apr 2011 04:37:20 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:44637) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q8q91-0002w2-Jk for bug-gnu-emacs@gnu.org; Sun, 10 Apr 2011 04:37:19 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1Q8poQ-0004lu-Fe; Sun, 10 Apr 2011 04:16:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Leo Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: dan.colascione@gmail.com, bug-gnu-emacs@gnu.org Resent-Date: Sun, 10 Apr 2011 08:16:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 8463 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org X-Debbugs-Original-Xcc: Daniel Colascione Original-Received: via spool by submit@debbugs.gnu.org id=B.130242333418303 (code B ref -1); Sun, 10 Apr 2011 08:16:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 10 Apr 2011 08:15:34 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q8pny-0004l9-0n for submit@debbugs.gnu.org; Sun, 10 Apr 2011 04:15:34 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q8pnv-0004kx-N4 for submit@debbugs.gnu.org; Sun, 10 Apr 2011 04:15:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q8pnp-0006Dx-Ck for submit@debbugs.gnu.org; Sun, 10 Apr 2011 04:15:26 -0400 Original-Received: from lists.gnu.org ([199.232.76.165]:47572) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q8pnp-0006De-1p for submit@debbugs.gnu.org; Sun, 10 Apr 2011 04:15:25 -0400 Original-Received: from [140.186.70.92] (port=34918 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q8pnn-0005hv-As for bug-gnu-emacs@gnu.org; Sun, 10 Apr 2011 04:15:24 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q8pnk-0006BL-Br for bug-gnu-emacs@gnu.org; Sun, 10 Apr 2011 04:15:21 -0400 Original-Received: from mail-iw0-f169.google.com ([209.85.214.169]:46122) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q8pnk-0006AM-1E for bug-gnu-emacs@gnu.org; Sun, 10 Apr 2011 04:15:20 -0400 Original-Received: by iwg8 with SMTP id 8so6321578iwg.0 for ; Sun, 10 Apr 2011 01:15:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:subject:x-debbugs-cc:date:message-id :mime-version:content-type; bh=4ptzm3BhUkiey8EMmVXDA4ID1v88weiW/vp1SKUEZXI=; b=OZGeK5CHrBczBg59QGlsxHJ3fjBziTrxe1n1GqPR5hxkkykUriEk4tD0kb/gKmGugA cLZ6RdLOzo+Q44pP9T/TJfaxIEqtxt2k96WYFeCM8+qvgGVgDj9FaLXOSSdfE6RFfRqG i9dlkgB/w0TXoGfwpl891c8MrNUZnIOtyMJ+k= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:x-debbugs-cc:date:message-id:mime-version :content-type; b=trD8PQklaMBVNm8rs1RtptJC28YywQZYB9jRzhu48Dyzqph3oJL1J8WXYDiTU0+o/4 kBQYdQQ3l4TTPbaSNc5MOXfKWyyUzpTDNlITnorzw/Dg0jailV/BBpU2eHjoWe3qz5di WHmYGlaTSQhIx83Br+jux5RBiimAdLVX3FDjk= Original-Received: by 10.231.181.137 with SMTP id by9mr4107955ibb.60.1302423318396; Sun, 10 Apr 2011 01:15:18 -0700 (PDT) Original-Received: from th041153.ip.tsinghua.edu.cn ([114.249.204.95]) by mx.google.com with ESMTPS id o3sm3277569ibd.10.2011.04.10.01.15.06 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 10 Apr 2011 01:15:17 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Sun, 10 Apr 2011 04:16:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:45728 Archived-At: --=-=-= I have extended the occur feature in Emacs to allow direct editing in the *Occur* buffer by propagating the changes to the original buffers. With the attached preliminary patch, one can press `C-x C-q' or `C-c C-c' to enter occur-edit-mode and start editing. Pressing `C-x C-q' or `C-c C-c' again finishes the edit. Comments are highly welcomed. Thanks in advance. Leo --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=occur.diff === modified file 'lisp/replace.el' --- lisp/replace.el 2011-04-08 03:05:58 +0000 +++ lisp/replace.el 2011-04-10 08:02:15 +0000 @@ -761,7 +761,8 @@ (let ((map (make-sparse-keymap))) ;; We use this alternative name, so we can use \\[occur-mode-mouse-goto]. (define-key map [mouse-2] 'occur-mode-mouse-goto) - (define-key map "\C-c\C-c" 'occur-mode-goto-occurrence) + (define-key map "\C-c\C-c" 'occur-edit-mode) + (define-key map "\C-x\C-q" 'occur-edit-mode) (define-key map "\C-m" 'occur-mode-goto-occurrence) (define-key map "o" 'occur-mode-goto-occurrence-other-window) (define-key map "\C-o" 'occur-mode-display-occurrence) @@ -815,6 +816,18 @@ map) "Keymap for `occur-mode'.") +(defvar occur-edit-mode-map + (let ((map (make-sparse-keymap))) + (define-key map [mouse-2] 'occur-mode-mouse-goto) + (define-key map "\C-c\C-c" 'occur-edit-mode-finish) + (define-key map "\C-x\C-q" 'occur-edit-mode-finish) + (define-key map "\C-m" 'occur-mode-goto-occurrence) + (define-key map "\C-o" 'occur-mode-display-occurrence) + (define-key map "\M-n" 'occur-next) + (define-key map "\M-p" 'occur-prev) + (define-key map "\C-c\C-f" 'next-error-follow-minor-mode) + map)) + (defvar occur-revert-arguments nil "Arguments to pass to `occur-1' to revert an Occur mode buffer. See `occur-revert-function'.") @@ -849,6 +862,59 @@ (add-hook 'change-major-mode-hook 'font-lock-defontify nil t) (setq next-error-function 'occur-next-error)) +(defun occur-edit-mode () + (interactive) + (setq buffer-read-only nil) + (use-local-map occur-edit-mode-map) + (setq major-mode 'occur-edit-mode + mode-name "Occur-Edit") + (add-hook 'after-change-functions 'occur-after-change-function nil t) + (force-mode-line-update)) + +(defvar occur-edit-modified-buffers nil) +(make-variable-buffer-local 'occur-edit-modified-buffers) + +(defun occur-edit-mode-finish () + (interactive) + (mapc (lambda (buf) + (and (buffer-file-name buf) + (with-current-buffer buf + (save-buffer)))) + occur-edit-modified-buffers) + (setq buffer-read-only t) + (kill-local-variable 'occur-edit-modified-buffers) + (remove-hook 'after-change-functions 'occur-after-change-function t) + (set-buffer-modified-p nil) + (use-local-map occur-mode-map) + (setq major-mode 'occur-mode + mode-name "Occur")) + +(defun occur-after-change-function (beg end length) + (let* ((m (get-text-property (point) 'occur-target)) + (buf (marker-buffer m)) + (col (current-column))) + (when (and (markerp m) (buffer-live-p buf)) + (let ((line (- (line-number-at-pos) + (line-number-at-pos (window-start)))) + (readonly (with-current-buffer buf buffer-read-only)) + (win (or (get-buffer-window buf) + (display-buffer buf t))) + (text (save-excursion + (forward-line 0) + (search-forward ":" nil t) + (setq col (- col (current-column))) + (buffer-substring-no-properties (point) (line-end-position))))) + (and (not readonly) + (add-to-list 'occur-edit-modified-buffers buf)) + (with-selected-window win + (goto-char m) + (recenter line) + (if readonly + (message "Buffer `%s' is read only." buf) + (delete-region (line-beginning-position) (line-end-position)) + (insert text)) + (move-to-column col)))))) + (defun occur-revert-function (ignore1 ignore2) "Handle `revert-buffer' for Occur mode buffers." (apply 'occur-1 (append occur-revert-arguments (list (buffer-name))))) @@ -1273,6 +1339,7 @@ `(font-lock-face prefix-face)) `(occur-prefix t mouse-face (highlight) occur-target ,marker follow-link t + read-only t help-echo "mouse-2: go to this occurrence")))) (match-str ;; We don't put `mouse-face' on the newline, @@ -1333,13 +1400,15 @@ (goto-char headerpt) (let ((beg (point)) end) - (insert (format "%d match%s%s in buffer: %s\n" - matches (if (= matches 1) "" "es") - ;; Don't display regexp for multi-buffer. - (if (> (length buffers) 1) - "" (format " for \"%s\"" - (query-replace-descr regexp))) - (buffer-name buf))) + (insert (propertize + (format "%d match%s%s in buffer: %s\n" + matches (if (= matches 1) "" "es") + ;; Don't display regexp for multi-buffer. + (if (> (length buffers) 1) + "" (format " for \"%s\"" + (query-replace-descr regexp))) + (buffer-name buf)) + 'read-only t)) (setq end (point)) (add-text-properties beg end (append --=-=-=--