How to change default action?

71 views
Skip to first unread message

Titus von der Malsburg

unread,
Jun 19, 2015, 5:56:41 PM6/19/15
to emacs...@googlegroups.com
A users wants to change the default action of a source.  Is there an easy way to do that without redefining the source?  Does helm have a mechanism for selecting a default action?

  Titus

Michael Heerdegen

unread,
Jun 19, 2015, 6:29:09 PM6/19/15
to emacs...@googlegroups.com
Hi Titus,

> A users wants to change the default action of a source. Is there an
> easy way to do that without redefining the source? Does helm have a
> mechanism for selecting a default action?

AFAICT helm-add-action-to-source with INDEX 0 should do that. Look at
its source code to see how similar things can be done.

That applies when the source already exists. If you want to change a
class definition, you can do something similar, for example:

(cl-defmethod
helm--setup-source :after ((source helm-type-file))
(setf (slot-value source 'action)
(let ((actions (oref source action)))
(cons my-new-action actions))))

will effectively change the actions list of any source which is an
instance of any class inheriting from the `helm-type-file' class.


Regards,

Michael.

Titus von der Malsburg

unread,
Jun 20, 2015, 3:10:37 PM6/20/15
to emacs...@googlegroups.com, michael_...@web.de
Hi Michael,

thanks for the response.  I was looking for something simple that I could recommend to users who are not proficient with Elisp.  But perhaps there is no easier way.

  Titus

Michael Heerdegen

unread,
Jun 20, 2015, 3:33:19 PM6/20/15
to emacs...@googlegroups.com
Titus von der Malsburg
Ok - but what's wrong with `helm-add-action-to-source' (and
`helm-delete-action-from-source')? That's the simplest thing I can
imagine for that purpose.


Regards,

Michael.

Thierry Volpiatto

unread,
Jun 20, 2015, 3:44:27 PM6/20/15
to emacs...@googlegroups.com

Michael Heerdegen <michael_...@web.de> writes:

> That applies when the source already exists. If you want to change a
> class definition, you can do something similar, for example:
>
> (cl-defmethod
> helm--setup-source :after ((source helm-type-file))
> (setf (slot-value source 'action)
> (let ((actions (oref source action)))
> (cons my-new-action actions))))

You should not use `helm--setup-source' which is for internal use.
Use instead `helm-setup-user-source' and on the class that is used to
define the source, (better not the parent).

e.g changes actions in helm-find-files:

(defmethod helm-setup-user-source ((source helm-source-ffiles))
(let ((actions (slot-value source 'action)))
(set-slot-value source 'action
(<...Modify actions as needed...>))))

--
Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997

Michael Heerdegen

unread,
Jun 21, 2015, 8:13:31 AM6/21/15
to emacs...@googlegroups.com
Thierry Volpiatto
<thierry....@gmail.com> writes:

> You should not use `helm--setup-source' which is for internal use.

Ok, thanks for clarifying.

> Use instead `helm-setup-user-source' and on the class that is used to
> define the source, (better not the parent).

What's wrong with that?


Regards,

Michael.

Michael Heerdegen

unread,
Jun 21, 2015, 12:39:37 PM6/21/15
to emacs...@googlegroups.com
Michael Heerdegen <michael_...@web.de>
writes:

> > Use instead `helm-setup-user-source' and on the class that is used to
> > define the source, (better not the parent).
>
> What's wrong with that?

That the child classes may change action lists by their own methods when
instantiated?

Anyway, we need to make all that work more transparent somehow. With
other words, see https://github.com/emacs-helm/helm/issues/781.

Michael.

Thierry Volpiatto

unread,
Jun 21, 2015, 2:19:50 PM6/21/15
to emacs...@googlegroups.com

Michael Heerdegen <michael_...@web.de> writes:

> That the child classes may change action lists by their own methods when
> instantiated?

When you run a `helm-setup-user-source' it is you want to modify a
particular source, not the parent.

Say you write a `foo' class inheriting from `bar', and you write a defmethod
against `bar' to modify say the actions on `bar' for `foo'.
Then you write a `baz' class inheriting also from `bar':
Question, do you want have its actions modified as `foo' ?

> Anyway, we need to make all that work more transparent somehow. With
> other words, see https://github.com/emacs-helm/helm/issues/781.

If you define the slots directly in the class, they will overhide the
ones of the child class, isn't that clear ?
Anyway the user shouldn't have to worry about this.
I can provide examples if you want.
I have started a section explaining all this in Home.mdpp, but didn't
had the time to finish it and push it to wiki, have a look, if you want
to write examples go ahead.

Titus von der Malsburg

unread,
Jun 21, 2015, 2:21:51 PM6/21/15
to emacs...@googlegroups.com, michael_...@web.de
Ah, that is actually a good-enough solution.  I didn't know about `helm-delete-action-from-source'.  Thanks!

  Titus
 



Regards,

Michael.

Michael Heerdegen

unread,
Jun 21, 2015, 2:43:48 PM6/21/15
to emacs...@googlegroups.com
Thierry Volpiatto writes:

> Say you write a `foo' class inheriting from `bar', and you write a
> defmethod against `bar' to modify say the actions on `bar' for `foo'.
> Then you write a `baz' class inheriting also from `bar': Question, do
> you want have its actions modified as `foo' ?

In my case: YES. More concretely, I want to modify the list of actions
defined in

(defmethod helm--setup-source :before ((source helm-type-file)) ...)

since I don't want to use the default actions, but different ones, for
every source that derives from that list. This includes child classes.

I have to do it this way because the action list is hardcoded in the
code. If it was defined in a variable, e.g.
`helm-source-type-file-default-actions' (even better an option), life
would be much easier.

Ideally, all longer action lists should be defined as a variable IMHO.
It's overkill to need to cope with classes and their methods for this
basic task. AFAIR that's what I suggested in the quoted thread.

> > Anyway, we need to make all that work more transparent somehow. With
> > other words, see https://github.com/emacs-helm/helm/issues/781.
>
> If you define the slots directly in the class, they will overhide the
> ones of the child class, isn't that clear ?

Of course. I guess you just didn't have my use case in mind, it was
intended.

> I have started a section explaining all this in Home.mdpp, but didn't
> had the time to finish it and push it to wiki, have a look, if you
> want to write examples go ahead.

That's good; will try to have a look tonight.


Regards,

Michael.

Michael Heerdegen

unread,
Jun 21, 2015, 2:50:03 PM6/21/15
to emacs...@googlegroups.com
Titus von der Malsburg
<mals...@posteo.de> writes:

> Ah, that is actually a good-enough solution. I didn't know about
> `helm-delete-action-from-source'. Thanks!

Yes, these functions work for any source. Just keep in mind that it
must already exist, some sources are now defined on the fly. That case
is a bit nontrivial.

Michael.

Thierry Volpiatto

unread,
Jun 21, 2015, 3:00:29 PM6/21/15
to emacs...@googlegroups.com

Michael Heerdegen <michael_...@web.de> writes:

> Thierry Volpiatto writes:
>
>> Say you write a `foo' class inheriting from `bar', and you write a
>> defmethod against `bar' to modify say the actions on `bar' for `foo'.
>> Then you write a `baz' class inheriting also from `bar': Question, do
>> you want have its actions modified as `foo' ?
>
> In my case: YES. More concretely, I want to modify the list of actions
> defined in
>
> (defmethod helm--setup-source :before ((source helm-type-file)) ...)

Ok.

> since I don't want to use the default actions, but different ones, for
> every source that derives from that list. This includes child classes.
>
> I have to do it this way because the action list is hardcoded in the
> code. If it was defined in a variable, e.g.
> `helm-source-type-file-default-actions' (even better an option), life
> would be much easier.

Of course, you have opened an issue for this and this will happen, so
please don't be impatient.

> Ideally, all longer action lists should be defined as a variable IMHO.
> It's overkill to need to cope with classes and their methods for this
> basic task. AFAIR that's what I suggested in the quoted thread.

You have to understand that I can't be hacking helm night and day.

>> If you define the slots directly in the class, they will overhide the
>> ones of the child class, isn't that clear ?
>
> Of course. I guess you just didn't have my use case in mind, it was
> intended.

No you misunderstand the problem this have nothing to do with your use
case.

> That's good; will try to have a look tonight.

Thanks.

Michael Heerdegen

unread,
Jun 21, 2015, 5:45:05 PM6/21/15
to emacs...@googlegroups.com
Thierry Volpiatto
<thierry....@gmail.com> writes:

> Of course, you have opened an issue for this and this will happen, so
> please don't be impatient.

I'm not impatient, just recalling what that was about. Take the time
you need.

> > That's good; will try to have a look tonight.
>
> Thanks.

Dumb question: where can I find your edits? I expected them in the
repo, but there has only one line changed in June 2015 so far in
README.md. I checked all branches.

Michael.

Thierry Volpiatto

unread,
Jun 21, 2015, 11:50:33 PM6/21/15
to emacs...@googlegroups.com
doc/Home.mdpp

I pushed to wiki:

https://github.com/emacs-helm/helm/wiki#developpingusinghelmframework

If you want to add example submit a PR against doc/Home.mdpp.

Use: markdown-pp.py Home.mdpp Home.md

Then use M-x markdown-preview to see your changes in a browser.

to convert your work to valid markdown (it create the index).
See https://github.com/emacs-helm/helm/wiki#wikimaintainerinstructions
on how to install markdown-pp.py.
Reply all
Reply to author
Forward
0 new messages