* how to set button action
@ 2016-10-16 2:36 Stefan Huchler
2016-10-16 13:43 ` Alex Kost
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Huchler @ 2016-10-16 2:36 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
I am trying to get buttons working in a tabulated-list mode but when I
press enter on that link it does not execute the print.
also tried it without lambda and the funcions name. Is there a trick I
am missing?
(define-derived-mode test-foo-mode tabulated-list-mode "test-foo"
(setq tabulated-list-format [("Series" 10 t)])
(setq tabulated-list-entries '((nil [("test" . ('action (lambda (btn)
(print "action"))))])))
(tabulated-list-init-header)
(tabulated-list-print)
)
(defun test-foo ()
(interactive)
(let* ((name "*test-foo*")
(buffer (or (get-buffer name)
(generate-new-buffer name))))
(unless (eq buffer (current-buffer))
(with-current-buffer buffer
(unless (eq major-mode 'test-foo-mode)
(condition-case e
(progn
(test-foo-mode)
)
(error
(kill-buffer buffer)
(signal (car e) (cdr e))))))
(switch-to-buffer-other-window buffer))))
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: how to set button action
2016-10-16 2:36 how to set button action Stefan Huchler
@ 2016-10-16 13:43 ` Alex Kost
2016-10-18 5:45 ` Stefan Huchler
0 siblings, 1 reply; 5+ messages in thread
From: Alex Kost @ 2016-10-16 13:43 UTC (permalink / raw)
To: Stefan Huchler; +Cc: help-gnu-emacs
Stefan Huchler (2016-10-16 04:36 +0200) wrote:
> Hi,
>
> I am trying to get buttons working in a tabulated-list mode but when I
> press enter on that link it does not execute the print.
>
> also tried it without lambda and the funcions name. Is there a trick I
> am missing?
>
>
> (define-derived-mode test-foo-mode tabulated-list-mode "test-foo"
> (setq tabulated-list-format [("Series" 10 t)])
> (setq tabulated-list-entries '((nil [("test" . ('action (lambda (btn)
> (print "action"))))])))
The foollowing works for me:
(setq tabulated-list-entries
'((nil [("test" action (lambda (btn) (print "action")))])))
> (tabulated-list-init-header)
> (tabulated-list-print)
> )
>
> (defun test-foo ()
> (interactive)
> (let* ((name "*test-foo*")
> (buffer (or (get-buffer name)
> (generate-new-buffer name))))
> (unless (eq buffer (current-buffer))
> (with-current-buffer buffer
> (unless (eq major-mode 'test-foo-mode)
> (condition-case e
> (progn
> (test-foo-mode)
> )
> (error
> (kill-buffer buffer)
> (signal (car e) (cdr e))))))
> (switch-to-buffer-other-window buffer))))
--
Alex
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: how to set button action
2016-10-16 13:43 ` Alex Kost
@ 2016-10-18 5:45 ` Stefan Huchler
2016-10-19 10:03 ` Michael Heerdegen
0 siblings, 1 reply; 5+ messages in thread
From: Stefan Huchler @ 2016-10-18 5:45 UTC (permalink / raw)
To: help-gnu-emacs
Alex Kost <alezost@gmail.com> writes:
> The foollowing works for me:
>
> (setq tabulated-list-entries
> '((nil [("test" action (lambda (btn) (print "action")))])))
>
>> (tabulated-list-init-header)
>> (tabulated-list-print)
>> )
yes that helped me, a small followup question, if I dont use lamba and
instead a function, can I define a parameter to that function?
It uses a marker object anyway, or can I access the id inside that
function? I have a list and need to know which element got selected.
Or do I have to make a global (line . obj) list?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: how to set button action
2016-10-18 5:45 ` Stefan Huchler
@ 2016-10-19 10:03 ` Michael Heerdegen
2016-10-20 2:57 ` Stefan Huchler
0 siblings, 1 reply; 5+ messages in thread
From: Michael Heerdegen @ 2016-10-19 10:03 UTC (permalink / raw)
To: Stefan Huchler; +Cc: help-gnu-emacs
Stefan Huchler <stefan.huchler@mail.de> writes:
> yes that helped me, a small followup question, if I dont use lamba and
> instead a function, can I define a parameter to that function?
You mean a named function (a lambda is a function). Yes, you can do
that. I suggest to have a look how some Emacs package do that,
e.g. package.el (look at `package-menu--print-info-simple' and the
action function `package-menu-describe-package'. Seems the action
function should accept a button as argument.
> It uses a marker object anyway, or can I access the id inside that
> function? I have a list and need to know which element got selected.
Seems you can either put a property on the button and refer to the
property value in the action function via `button-get', or just use
`tabulated-list-get-id' to get the ID.
HTH,
Michael.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-10-20 2:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-16 2:36 how to set button action Stefan Huchler
2016-10-16 13:43 ` Alex Kost
2016-10-18 5:45 ` Stefan Huchler
2016-10-19 10:03 ` Michael Heerdegen
2016-10-20 2:57 ` Stefan Huchler
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).