[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Occur stack
From: |
Tom |
Subject: |
Re: Occur stack |
Date: |
Fri, 17 Jan 2014 17:19:50 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Andreas Röhler <andreas.roehler <at> 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)
Re: Occur stack, Andreas Röhler, 2014/01/15
- Re: Occur stack, Tom, 2014/01/15
- Re: Occur stack, Tom, 2014/01/16
- Re: Occur stack, Andreas Röhler, 2014/01/17
- Re: Occur stack, Tom, 2014/01/17
- Re: Occur stack, Andreas Röhler, 2014/01/19
- Re: Occur stack, Tom, 2014/01/19
Re: Occur stack,
Tom <=
Re: Occur stack, Tom, 2014/01/18
Re: Occur stack, Stefan Monnier, 2014/01/18
Re: Occur stack, Tom, 2014/01/19
Re: Occur stack, Daniel Colascione, 2014/01/19
Re: Occur stack, Stefan Monnier, 2014/01/19
Re: Occur stack, Tom, 2014/01/19
Re: Occur stack, Lars Ingebrigtsen, 2014/01/18
Re: Occur stack, Stefan Monnier, 2014/01/18
Re: Occur stack, Juri Linkov, 2014/01/21
Re: Occur stack, joakim, 2014/01/21