From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tom Newsgroups: gmane.emacs.devel Subject: Re: Occur stack Date: Wed, 15 Jan 2014 20:16:22 +0000 (UTC) Message-ID: References: <52D6D907.4030702@online.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1389817015 24655 80.91.229.3 (15 Jan 2014 20:16:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 15 Jan 2014 20:16:55 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Jan 15 21:17:03 2014 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1W3Wta-0003HX-H1 for ged-emacs-devel@m.gmane.org; Wed, 15 Jan 2014 21:17:02 +0100 Original-Received: from localhost ([::1]:57024 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W3WtZ-0002lc-Ve for ged-emacs-devel@m.gmane.org; Wed, 15 Jan 2014 15:17:01 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48435) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W3WtR-0002kZ-KL for emacs-devel@gnu.org; Wed, 15 Jan 2014 15:16:59 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W3WtL-00008z-EN for emacs-devel@gnu.org; Wed, 15 Jan 2014 15:16:53 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:54458) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W3WtL-00008m-84 for emacs-devel@gnu.org; Wed, 15 Jan 2014 15:16:47 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1W3WtJ-0002kk-Bg for emacs-devel@gnu.org; Wed, 15 Jan 2014 21:16:45 +0100 Original-Received: from 94-21-170-99.pool.digikabel.hu ([94.21.170.99]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 15 Jan 2014 21:16:45 +0100 Original-Received: from adatgyujto by 94-21-170-99.pool.digikabel.hu with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 15 Jan 2014 21:16:45 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 96 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: sea.gmane.org User-Agent: Loom/3.14 (http://gmane.org/) X-Loom-IP: 94.21.170.99 (Opera/9.80 (Windows NT 6.1) Presto/2.12.388 Version/12.16) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:168493 Archived-At: Andreas Röhler online.de> writes: > > Being able to jump back or read occur-history like > M-x browse-kill-ring would be great. > I created a simple proof of concept implementation, so it can be tested in practice. It can be activated by adding this to the occur hook and then it saves the last 10 occur results: (add-hook 'occur-hook 'buffer-history-save) If you do some occuring and then run M-x buffer-history-list in the occur buffer then it lists the stored occur sessions and you can press RET on any of them to restore it in the occur buffer. The code is generic, so in theory it can work for other commands too, but I only tested it with occur. Note that it's a very simple implementation, it only restores the stored contents in the occur buffer, so it requires a live occur buffer. For this reason it begins with an occur advice which prevents occur from killing the occur buffer if there are no matches. Here's the code: ;; this is needed to prevent occur from killing the buffer ;; when there are no matches (defadvice occur (around my-occur-advice activate) (flet ((kill-buffer (buf) (bury-buffer buf))) ad-do-it)) (setq buffer-history nil) (defun buffer-history-save () (let ((entry (assoc major-mode buffer-history))) (unless entry (setq entry (cons major-mode '())) (push entry buffer-history)) (push (buffer-substring (point-min) (point-max)) (cdr entry)) (if (> (length (cdr entry)) 10) (setcdr entry (butlast (cdr entry)))))) (setq buffer-history-target-buffer nil) (defun buffer-history-list () (interactive) (let ((entry (assoc major-mode buffer-history))) (unless entry (error "No buffer history here.")) (setq buffer-history-target-buffer (current-buffer)) (pop-to-buffer "*buffer history*") (let ((inhibit-read-only t)) (erase-buffer)) (dolist (item (cdr entry)) ;; assuming the first line describes the contents (assert (string-match ".*?\n" item)) (let ((start (point))) (let ((line (match-string 0 item))) (set-text-properties 0 (length line) nil line) (insert line)) (put-text-property start (1+ start) 'buffer-history-contents item))) (goto-char (point-min)) (local-set-key (kbd "RET") 'buffer-history-restore))) (defun buffer-history-restore () (interactive) (let ((contents (get-text-property (line-beginning-position) 'buffer-history-contents))) (pop-to-buffer buffer-history-target-buffer) (let ((inhibit-read-only t)) (erase-buffer) (insert contents)) (goto-char (point-min))))