all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Tom <adatgyujto@gmail.com>
To: emacs-devel@gnu.org
Subject: Re: Occur stack
Date: Fri, 17 Jan 2014 17:19:50 +0000 (UTC)	[thread overview]
Message-ID: <loom.20140117T180743-808@post.gmane.org> (raw)
In-Reply-To: 52D8E8CB.5080600@online.de

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)







  parent reply	other threads:[~2014-01-17 17:19 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-14 16:24 Occur stack Tom
2014-01-14 16:35 ` Nicolas Richard
2014-01-14 16:57   ` Tom
2014-01-14 17:00     ` Tom
2014-01-14 17:07     ` Juanma Barranquero
2014-01-14 17:12       ` Tom
2014-01-14 17:21         ` Lars Magne Ingebrigtsen
2014-01-14 20:30           ` Tom
2014-01-14 20:40             ` Tom
2014-01-14 21:08           ` Daniel Colascione
2014-01-14 21:24             ` John Yates
2014-01-14 21:32             ` Drew Adams
2014-01-14 21:26           ` Stefan Monnier
2014-01-14 17:41         ` Allen S. Rout
2014-01-15  8:27       ` Juri Linkov
2014-01-15  9:06         ` David Kastrup
2014-01-16  7:57           ` Juri Linkov
2014-01-16  8:53             ` David Kastrup
2014-01-16  9:46               ` Lars Ingebrigtsen
2014-01-16 10:36                 ` David Kastrup
2014-01-16 13:47                   ` Stefan Monnier
2014-01-16 13:54                     ` David Kastrup
2014-01-17 15:52                       ` Lars Ingebrigtsen
2014-01-15 18:52 ` Andreas Röhler
2014-01-15 20:16   ` Tom
2014-01-16 17:19     ` Tom
2014-01-17  8:24       ` Andreas Röhler
2014-01-17 13:24         ` Tom
2014-01-19 14:50           ` Andreas Röhler
2014-01-19 16:03             ` Tom
2014-01-17 17:19         ` Tom [this message]
2014-01-18 17:01           ` Tom
2014-01-19  2:39             ` Stefan Monnier
2014-01-19  6:40               ` Tom
2014-01-19  7:12                 ` Daniel Colascione
2014-01-19 14:38                 ` Stefan Monnier
2014-01-19 15:56                   ` Tom
2014-01-18 17:04           ` Lars Ingebrigtsen
2014-01-19  2:45             ` Stefan Monnier
2014-01-21  7:51               ` Juri Linkov
2014-01-21  9:05                 ` joakim
2014-01-22  8:03                   ` Juri Linkov
2014-01-21 19:42               ` Lars Ingebrigtsen
2014-01-22  1:27                 ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=loom.20140117T180743-808@post.gmane.org \
    --to=adatgyujto@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.