Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gui: split smart jump from hotlist #1187

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

shiona
Copy link

@shiona shiona commented Apr 26, 2018

New option config.look.hotlist.get_sort to select
the way in which jump_smart selects the buffer to jump to.

Name suggestions are welcome, current name choices are bad.

@shiona
Copy link
Author

shiona commented Apr 26, 2018

I am also not sure if this is the correct way of implementing the split. To be frank I don't think the smart jump should have anything to do with a gui element showing active buffers. But I'll let more experienced weechat developers choose.

Copy link
Member

@sim642 sim642 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall the name get and get_sort sound pretty meaningless and unrelated to smart jumping. Maybe it should be named weechat.look.smart_jump_sort or similar.

@@ -90,6 +90,17 @@ enum t_config_look_hotlist_sort
CONFIG_LOOK_HOTLIST_SORT_NUMBER_DESC,
};

enum t_config_look_hotlist_get_sort
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really necessary to have two separate enums for what's essentially the same thing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know I could reuse a configuration enum.
I'll look into how to do this.
Is it possible to make this option optional and when not set default to "same as look.hotlist.sort"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't seem to find an example of an optional option.
I dislike the idea of defaulting to any arbitrary value for smart_jump, because I believe many people assume it to follow the config of hotlist_sort by now.

Any idea how I would create an option for smart_jump that would contain the same options as hotlist_sort with an addition of default (that does the same as the selected hotlist_sort).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible to set a "parent" for an option: https://weechat.org/files/doc/devel/weechat_plugin_api.en.html#_config_new_option. That allows defaulting to another option's value when not set and seems like what you're thinking of. It's not totally automatic though: you have to check your option first and if it's unset use the other one yourself.

Internally the two options could be based on the same enum. To the user you need to manually write the possible choices strings in each option separately anyway, these can differ. If you set up the parent option, the "default" wouldn't be necessary and "null" would mean the same thing (use parent).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, this sounds perfect.
Thank you!

Copy link
Author

@shiona shiona Apr 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure about the documentation.

name of option; with WeeChat ≥ 1.4, the name can include a parent option name (the value of parent option will be displayed in /set command output if this option is "null"), the syntax is then: "name << file.section.option"

Should the name of the option then be "smart_jump_order << weechat.look.hotlist_sort"?

Also as I said I could not find an example of an optional (nullable) option.
The macros I can find (CONFIG_{INTEGER,STRING,BOOLEAN,COLOR}) expect the value to be non-null. There seems to be a function config_file_option_is_null. Is there a reason some of these are functions and others are macros?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the option name should contain the parent, it's kind of a hack in WeeChat.

Each server's options have parents but that's kind of hard to understand as they're dynamic. Here's an example from a PR of mine: https://github.com/weechat/weechat/pull/684/files. The function you mentioned should be right. The macros are there for convenience, with parent/nullable options some functions need to be used directly.

selected = ptr_hotlist;
}
return selected;
break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These breaks are superfluous when already returning.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I saw some return + breaks somewhere and that it was a styling convention to have break in every case. I'll take them out.

@@ -474,6 +474,86 @@ gui_hotlist_resort ()
gui_hotlist_changed_signal ();
}

struct t_gui_hotlist *
gui_hotlist_get ()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a verbose copy of gui_hotlist_find_pos. Maybe one function could be performing the same logic without the need for duplicate code, especially considering that there could be just one enum.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, it is a copy of gui_hotlist_find_pos.
I'll try to pick the common part out and reorganize the code.

@flashcode flashcode added the feature New feature request label May 3, 2018
@shiona
Copy link
Author

shiona commented May 15, 2018

After the latest commit I'm happy with the functionality of this PR.
I'm not 100% sure if the function pointers for comparisons is the right choice or that smart_jump_prefer_forward should be its own option or somehow baked in into smart_jump_order. I'll let someone more knowledgeable of this codebase make those decisions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants