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: Fri, 17 Jan 2014 17:19:50 +0000 (UTC) Message-ID: References: <52D6D907.4030702@online.de> <52D8E8CB.5080600@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 1389979231 7198 80.91.229.3 (17 Jan 2014 17:20:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 17 Jan 2014 17:20:31 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jan 17 18:20:37 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 1W4D5w-0003ZJ-SC for ged-emacs-devel@m.gmane.org; Fri, 17 Jan 2014 18:20:37 +0100 Original-Received: from localhost ([::1]:39364 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W4D5w-0002Dl-0g for ged-emacs-devel@m.gmane.org; Fri, 17 Jan 2014 12:20:36 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51353) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W4D5h-0002B3-9U for emacs-devel@gnu.org; Fri, 17 Jan 2014 12:20:27 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W4D5a-0000D6-Dw for emacs-devel@gnu.org; Fri, 17 Jan 2014 12:20:21 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]:43496) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W4D5a-0000D1-6Y for emacs-devel@gnu.org; Fri, 17 Jan 2014 12:20:14 -0500 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1W4D5Y-0003B5-9y for emacs-devel@gnu.org; Fri, 17 Jan 2014 18:20:12 +0100 Original-Received: from 78-131-103-206.pool.digikabel.hu ([78.131.103.206]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 17 Jan 2014 18:20:12 +0100 Original-Received: from adatgyujto by 78-131-103-206.pool.digikabel.hu with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 17 Jan 2014 18:20:12 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 103 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: 78.131.103.206 (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:168633 Archived-At: Andreas Röhler online.de> writes: > > In cases where a plenty of occur-calls is done, > maybe the discussion WRT to memory pertains? Here's an other experimental code which does it the other way: it does not store buffer contents, it reruns the command instead. This way memory is not an issue, because it only stores a short description and a restore function, but in this case it requires explicit support from the involved commands, they need to supply the function for restoring the results. (The code again is simple, so it stores the live buffer pointers of the occur target buffers, it does not reopen the target buffer if it has been closed after running occur.) (setq buffer-history nil) (defun buffer-history-save (description restore-function) (let ((entry (assoc major-mode buffer-history))) (unless entry (setq entry (cons major-mode '())) (push entry buffer-history)) (push (list 'description description 'restore-function restore-function) (cdr entry)))) (defun buffer-history-list () (interactive) (let ((entry (assoc major-mode buffer-history))) (unless entry (error "No buffer history here.")) (pop-to-buffer "*buffer history*") (let ((inhibit-read-only t)) (erase-buffer)) (dolist (item (cdr entry)) (let ((start (point))) (insert (plist-get item 'description) "\n") (put-text-property start (1+ start) 'buffer-history-restore-function (plist-get item 'restore-function)))) (goto-char (point-min)) (local-set-key (kbd "RET") 'buffer-history-restore))) (defun buffer-history-restore () (interactive) (funcall (get-text-property (line-beginning-position) 'buffer-history-restore-function))) (defun buffer-history-save-occur () (let* ((regexp (car occur-revert-arguments)) (buffers (car (cddr occur-revert-arguments))) (restore-fun (cond ((eq this-command 'occur) (eval `(let ((buffer (car buffers)) (regexp regexp)) (lambda () (with-current-buffer buffer (occur regexp)))) t)) ((eq this-command 'multi-occur) (eval `(let ((buffers buffers) (regexp regexp)) (lambda () (multi-occur buffers regexp))) t))))) (if (not restore-fun) (unless (eq this-command 'buffer-history-restore) (message "buffer-history: unsupported occur command '%s'" this-command)) (set-text-properties 0 (length regexp) nil regexp) (buffer-history-save (format "'%s' in %s" regexp (mapconcat (lambda (buffer) (buffer-name buffer)) buffers ", ")) restore-fun)))) (add-hook 'occur-hook 'buffer-history-save-occur)