Minimal working example for displaying/killing preview buffer with persistent action

24 views
Skip to first unread message

Tianxiang Xiong

unread,
Jan 12, 2017, 3:06:12 AM1/12/17
to emacs-helm
Can I get a minimal working example of a Helms source with a persistent action that, when applied to a candidate, alternates between bringing up a buffer and killing/burying it? The buffer brought up by persistent action (which I'll call the "preview" buffer) could be the *Help* buffer, but preferably not, since there's a lot of complexity with Emacs built-in buffers like *Help* that we can avoid for a minimal working example.

In my current approach, I can bring up a preview buffer like so:

(defun helm-cider-repl--history-preview (entry)
 
"Preview the CIDER REPL history entry in a temp buffer.


Useful when the entry longer than `helm-cider-repl-history-max-lines' lines."

 
(let ((buf (get-buffer-create "*Helm CIDER REPL History Preview*")))
   
(switch-to-buffer buf)
   
(setq buffer-read-only nil)
   
(erase-buffer)
   
(insert entry)
   
(clojure-mode)
   
(font-lock-ensure)
   
(setq buffer-read-only t)))


But I'm not sure how best to manage state so that another application of persistent action will kill/bury the buffer. One difficulty that when we switch candidates and apply persistent action again (e.g. through follow-mode), we don't want this alternating behavior.

Thierry Volpiatto

unread,
Jan 12, 2017, 4:03:31 AM1/12/17
to emacs...@googlegroups.com
I am not sure to understand what you want to do exactly, here what I guess you would
like:

- The buffer "*Helm CIDER REPL History Preview*" is visible and belong
to current candidate:
Kill it unless using follow-mode.

- The buffer "*Helm CIDER REPL History Preview*" is visible and don't
belong to current candidate:
Run `helm-cider-repl--history-preview` to replace buffer contents with
infos belonging to current candidate.

- The buffer "*Helm CIDER REPL History Preview*" is not visible:
Run `helm-cider-repl--history-preview` on current candidate and
display buffer.

See `helm-elisp--persistent-help` and
`helm-buffers-list-persistent-action` among others examples.

--
Thierry
Reply all
Reply to author
Forward
0 new messages