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: Thu, 09 Jun 2011 17:42:47 +0800 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: dough.gmane.org 1307613188 11517 80.91.229.12 (9 Jun 2011 09:53:08 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 9 Jun 2011 09:53:08 +0000 (UTC) Cc: Chong Yidong , 8463@debbugs.gnu.org To: Glenn Morris Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jun 09 11:53:04 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QUbvC-0004aX-Dq for geb-bug-gnu-emacs@m.gmane.org; Thu, 09 Jun 2011 11:53:03 +0200 Original-Received: from localhost ([::1]:44037 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QUbvB-0005A6-HI for geb-bug-gnu-emacs@m.gmane.org; Thu, 09 Jun 2011 05:53:01 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:54275) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QUbmX-00037i-JJ for bug-gnu-emacs@gnu.org; Thu, 09 Jun 2011 05:44:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QUbmV-00053a-QA for bug-gnu-emacs@gnu.org; Thu, 09 Jun 2011 05:44:05 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:49465) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QUbmV-00053T-JQ for bug-gnu-emacs@gnu.org; Thu, 09 Jun 2011 05:44:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1QUbmU-00017v-Gg; Thu, 09 Jun 2011 05:44: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: bug-gnu-emacs@gnu.org Resent-Date: Thu, 09 Jun 2011 09:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 8463 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 8463-submit@debbugs.gnu.org id=B8463.13076125964273 (code B ref 8463); Thu, 09 Jun 2011 09:44:02 +0000 Original-Received: (at 8463) by debbugs.gnu.org; 9 Jun 2011 09:43:16 +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 1QUblj-00016s-O6 for submit@debbugs.gnu.org; Thu, 09 Jun 2011 05:43:16 -0400 Original-Received: from mail-pw0-f44.google.com ([209.85.160.44]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QUblh-00016d-Oa for 8463@debbugs.gnu.org; Thu, 09 Jun 2011 05:43:14 -0400 Original-Received: by pwi5 with SMTP id 5so656367pwi.3 for <8463@debbugs.gnu.org>; Thu, 09 Jun 2011 02:43:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-type; bh=8j0mUTDWj8l6M7cpVGA6nKSrMb7oavbIFFzU963UzZ4=; b=hRDO8E0OEh7f8vPDSvpBozQDGgc50jdBLx0NoFQ39fwTbdd1SynSSOFLcBfJCeNVdI Gr4QUDvm7Az3j2Y7utRnqMAnCt7Q4aLWxAQp+tq3lE30LGR3OuwL61E4DdnJgVCEDJM7 1JGf2OwU6LzCFXA67CelB9/hS0R8oaBCYLR8s= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; b=Cev3S90yldN1NsvwuVMLLg42awPWTiewzNQKU51SBBjumgs7l0/ATuAxHufMPHixos /Uf8aTf1Hb+0qIIhzDSiodrO35YE0GnOv0ixPZNEDIiZTkVQPDS4CYn3fVt/nJFTv+JX eiXRyD6LwyYAVTpQWw/S3m3nyp5wB75ehkypE= Original-Received: by 10.142.178.3 with SMTP id a3mr76857wff.53.1307612587873; Thu, 09 Jun 2011 02:43:07 -0700 (PDT) Original-Received: from localhost ([123.114.55.183]) by mx.google.com with ESMTPS id o1sm1545759wfd.20.2011.06.09.02.43.00 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 09 Jun 2011 02:43:06 -0700 (PDT) In-Reply-To: (Glenn Morris's message of "Wed, 01 Jun 2011 19:03:36 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3.50 (Mac OS X 10.6.7) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Thu, 09 Jun 2011 05:44: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: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:47059 Archived-At: --=-=-= Content-Type: text/plain I think maybe we should assign C-c C-c to occur-edit-mode instead. 1. After C-x C-q, I can no longer kill entire lines in the occur buffer. Trying to do so reports "Text is read-only". The text properties are now added when entering occur-edit-mode. 2. After C-x C-q, If I delete some text in the occur buffer, then use "undo", when I reach the point at which there is no more to undo, I get: "Wrong type argument: markerp, nil" rather than "No further undo information". Debugger entered--Lisp error: (wrong-type-argument markerp nil) marker-buffer(nil) occur-after-change-function(1 40 39) primitive-undo(1 ((nil font-lock-face underline 1 . 40) (t 0 . 0))) undo-more(1) undo(nil) call-interactively(undo nil nil) Fixed. 3. After C-x C-q, M-x revert-buffer in the occur buffer triggers an error occur-revert-arguments is killed after any major-mode change. In the patch this has been made permanent-local. Comments welcome. Thanks. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=occur-edit.diff Content-Description: occur-edit.diff === modified file 'lisp/replace.el' --- lisp/replace.el 2011-05-28 22:56:14 +0000 +++ lisp/replace.el 2011-06-09 09:28:09 +0000 @@ -826,6 +826,8 @@ (defvar occur-revert-arguments nil "Arguments to pass to `occur-1' to revert an Occur mode buffer. See `occur-revert-function'.") +(make-variable-buffer-local 'occur-revert-arguments) +(put 'occur-revert-arguments 'permanent-local t) (defcustom occur-mode-hook '(turn-on-font-lock) "Hook run when entering Occur mode." @@ -853,8 +855,6 @@ \\{occur-mode-map}" (set (make-local-variable 'revert-buffer-function) 'occur-revert-function) - (make-local-variable 'occur-revert-arguments) - (add-hook 'change-major-mode-hook 'font-lock-defontify nil t) (setq next-error-function 'occur-next-error)) @@ -865,7 +865,7 @@ (set-keymap-parent map text-mode-map) (define-key map [mouse-2] 'occur-mode-mouse-goto) (define-key map "\C-c\C-c" 'occur-mode-goto-occurrence) - (define-key map "\C-x\C-q" 'occur-mode) + (define-key map "\C-x\C-q" 'occur-edit-finish) (define-key map "\C-c\C-f" 'next-error-follow-minor-mode) (define-key map [menu-bar occur] (cons (purecopy "Occur") occur-menu-map)) map) @@ -878,40 +878,59 @@ To return to ordinary Occur mode, use \\[occur-mode]." (setq buffer-read-only nil) + (put 'occur-noneditable 'read-only t) + (put 'occur-noneditable 'face 'shadow) + (save-excursion + (save-restriction + (widen) + (goto-char (point-min)) + (while (re-search-forward "^[ \t0-9]+:\\|\n" nil t) + (with-silent-modifications + (put-text-property (match-beginning 0) (match-end 0) + 'category 'occur-noneditable))))) (add-hook 'after-change-functions 'occur-after-change-function nil t)) +(defun occur-edit-finish () + (interactive) + (put 'occur-noneditable 'read-only nil) + (put 'occur-noneditable 'face nil) + (occur-mode)) + (defun occur-after-change-function (beg end length) - (save-excursion - (goto-char beg) - (let* ((m (get-text-property (line-beginning-position) 'occur-target)) - (buf (marker-buffer m)) - (col (current-column))) - (when (= length 0) - ;; Apply occur-target property to inserted (e.g. yanked) text. - (put-text-property beg end 'occur-target m) - ;; Did we insert a newline? Occur Edit mode can't create new - ;; Occur entries; just discard everything after the newline. + (let ((m (save-excursion + (goto-char beg) + (get-text-property (line-beginning-position) 'occur-target)))) + (when (and (markerp m) (buffer-live-p (marker-buffer m))) + (when (zerop length) (save-excursion + ;; Apply occur-target property to inserted (e.g. yanked) text. + (put-text-property beg end 'occur-target m) + ;; Did we insert a newline? Occur Edit mode can't create new + ;; Occur entries; just discard everything after the newline. + (goto-char beg) (and (search-forward "\n" end t) (delete-region (1- (point)) end)))) - (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))))) - (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)))))) + (save-excursion + (let* ((buf (marker-buffer m)) + (col (current-column)) + (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))))) + (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) @@ -1341,7 +1360,6 @@ `(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, @@ -1401,15 +1419,13 @@ (goto-char headerpt) (let ((beg (point)) end) - (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)) + (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))) (setq end (point)) (add-text-properties beg end (append --=-=-=--