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

Update oldschoolkeys, tabmenu, yanksel plugins #14

Closed
wants to merge 10 commits into from

Conversation

schvabodka-man
Copy link
Contributor

@schvabodka-man schvabodka-man commented Aug 20, 2017

Hello there! Due to changes in API plugin tabmenu was broken and unusable on newer versions of luakit. I fixed it to work with new api and it works nice. I've also removed standart hotkey for it(because anyway you can set it in you luakit config and not everyone wants to have this hotkey). I also fixed yankselect and old school keybindings plugins. Would be sweat if you'll merge this

Copy link
Member

@aidanholm aidanholm left a comment

Choose a reason for hiding this comment

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

Mostly good, just a bunch of formatting changes really.
Make sure all tests pass when using these modules as well.

}
local add_binds = modes.add_binds

module("plugins.oldschoolkeys")
Copy link
Member

Choose a reason for hiding this comment

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

The use of module() in plugins is now forbidden. This is because it unavoidably sets a global variable. Instead, declare a local table named _M and return it at the end of the file. All subsequent top-level variables should either be local or should be fields of _M.

@@ -4,24 +4,16 @@

local pairs = pairs
Copy link
Member

Choose a reason for hiding this comment

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

Remove this


module("plugins.oldschoolkeys")

add_binds("normal",
Copy link
Member

Choose a reason for hiding this comment

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

Opening brace should go on the same line as add_binds, and closing brace+paren should go on a new line:

add_binds("normal", {
   ...
})

tabmenu/init.lua Outdated
@@ -7,80 +7,71 @@ local ipairs = ipairs
local table = table

local lousy = require "lousy"

Copy link
Member

Choose a reason for hiding this comment

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

Remove space here

tabmenu/init.lua Outdated
@@ -7,80 +7,71 @@ local ipairs = ipairs
local table = table

local lousy = require "lousy"

local modes = require "modes"

Copy link
Member

Choose a reason for hiding this comment

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

ditto

yanksel/init.lua Outdated
local add_binds, add_cmds = add_binds, add_cmds

local modes = require "modes"

Copy link
Member

Choose a reason for hiding this comment

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

ditto

yanksel/init.lua Outdated
local modes = require "modes"

local add_binds = modes.add_binds
local add_cmds = modes.add_cmds

module("plugins.yanksel")
Copy link
Member

Choose a reason for hiding this comment

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

ditto re module

yanksel/init.lua Outdated
luakit.selection.primary = ""
end),
})
function yank_select(w)
Copy link
Member

Choose a reason for hiding this comment

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

I'd say make this an action table, which is just a table with func (function) and desc (description) keys. See lib/binds.lua for examples (scrolling actions).

tabmenu/init.lua Outdated
local add_binds = modes.add_binds
local add_cmds = modes.add_cmds
local new_mode = modes.new_mode

local add_binds, add_cmds = add_binds, add_cmds
local new_mode, menu_binds = new_mode, menu_binds

module("plugins.tabmenu")
Copy link
Member

Choose a reason for hiding this comment

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

ditto re module

tabmenu/init.lua Outdated
local add_binds = modes.add_binds
local add_cmds = modes.add_cmds
local new_mode = modes.new_mode

local add_binds, add_cmds = add_binds, add_cmds
local new_mode, menu_binds = new_mode, menu_binds

module("plugins.tabmenu")

hide_box = false
Copy link
Member

Choose a reason for hiding this comment

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

make this _M.hide_box

@schvabodka-man
Copy link
Contributor Author

Okay, here it goes. Check this one. Maybe in few time i'll fix user agent changer

Copy link
Member

@aidanholm aidanholm left a comment

Choose a reason for hiding this comment

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

Mostly fixed now

Separately, I'd prefer it if you split this fixes commit and squashed the changes for each file into the earlier file-specific commits, as this keeps the git history clean.

Finally, make sure the tests pass; to do this:

  1. copy the modules into the luakit repo under config/
  2. require these modules (require "oldschoolkeys", etc.) in config/rc.lua
  3. run make run-tests

@@ -1,19 +1,17 @@
------------------------------------------------------------------------
-- Add some convenient keybindings back. --
------------------------------------------------------------------------

local pairs = pairs
local lousy = require("lousy")

Copy link
Member

Choose a reason for hiding this comment

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

No blank lines between require lines

add_binds("normal",{
{ "b", "Back", function (w, m) w:back(m.count) end, {count=1}},
{ "<Mod1-Page_Up>", "Reorder tabs", function (w, m) w.tabs:reorder(w.view, w.tabs:current() - m.count) end, {count=1}},
{ "<Mod1-Page_Down>", "Reorder tabs", function (w, m) w.tabs:reorder(w.view, (w.tabs:current() + m.count) % w.tabs:count()) end, {count=1}}})
Copy link
Member

Choose a reason for hiding this comment

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

Final }) should go on a new line


add_binds("normal",{
{ "b", "Back", function (w, m) w:back(m.count) end, {count=1}},
{ "<Mod1-Page_Up>", "Reorder tabs", function (w, m) w.tabs:reorder(w.view, w.tabs:current() - m.count) end, {count=1}},
Copy link
Member

Choose a reason for hiding this comment

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

These functions are long enough that they should be multi-line

yanksel/init.lua Outdated
module("plugins.yanksel")
local _M = {}

local funcs = {
Copy link
Member

Choose a reason for hiding this comment

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

This table should be called actions

@schvabodka-man
Copy link
Contributor Author

It's passing tests

@aidanholm
Copy link
Member

I'm getting the following test failures:

FAIL style/test_luacheck / test_luacheck
  tests/style/test_luacheck.lua:102: Luacheck messages:
    config/tabmenu/init.lua:28: (9:16):                setting non-standard global variable 'hide_box'
    config/tabmenu/init.lua:42: (12:19):               accessing undefined variable 'hide_box'
    config/oldschoolkeys/init.lua:4: (7:11):           unused variable 'lousy'
    config/yanksel/init.lua:5: (7:11):                 unused variable 'lousy'
    config/yanksel/init.lua:12: (18:18):               line contains trailing whitespace
FAIL style/test_source_format / test_vim_modeline
  tests/style/test_source_format.lua:41: Some files do not have modelines:
  config/tabmenu/init.lua                                Missing/malformed modeline
  config/oldschoolkeys/init.lua                          Missing/malformed modeline
  config/yanksel/init.lua                                Missing/malformed modeline
FAIL style/test_source_format / test_no_trailing_whitespace
  tests/style/test_source_format.lua:313: Some files have trailing whitespace:
  config/yanksel/init.lua:12                             Trailing whitespace
FAIL style/test_source_format / test_no_tabs_in_indentation
  tests/style/test_source_format.lua:287: Some files have tabs in indentation:
  config/tabmenu/init.lua:20                             Tabs in indentation
  config/oldschoolkeys/init.lua:14                       Tabs in indentation
  config/oldschoolkeys/init.lua:15                       Tabs in indentation
  config/oldschoolkeys/init.lua:16                       Tabs in indentation
  config/oldschoolkeys/init.lua:18                       Tabs in indentation
  config/oldschoolkeys/init.lua:19                       Tabs in indentation
  config/oldschoolkeys/init.lua:20                       Tabs in indentation
  config/yanksel/init.lua:14                             Tabs in indentation
  config/yanksel/init.lua:15                             Tabs in indentation
  config/yanksel/init.lua:16                             Tabs in indentation
  config/yanksel/init.lua:17                             Tabs in indentation
  config/yanksel/init.lua:18                             Tabs in indentation
  config/yanksel/init.lua:19                             Tabs in indentation
  config/yanksel/init.lua:20                             Tabs in indentation
  config/yanksel/init.lua:21                             Tabs in indentation

The trailing whitespace / tabs are easy to fix. Just remove the lines with unused variables.
For the modelines, you need to add the following to the bottom of each file, with a blank line above it:

-- vim: et:sw=4:ts=8:sts=4:tw=80

@aidanholm
Copy link
Member

On tabmenu.lua lines 28 and 42, hide_box should be _M.hide_box; that should be everything!

@schvabodka-man
Copy link
Contributor Author

I'm not using vim, i'm using emacs. I just replaced tabs with spaces(4 tabs = 4 spaces) and run it through lua beautifier. Hide box is already _M.hide_box(really it is). And 28 and 42 is intended with 4 spaces

@schvabodka-man
Copy link
Contributor Author

Ok, wait for a second i fixed those references

@aidanholm
Copy link
Member

Even so, the project's coding standard is to use vim modelines (and I thought emacs could read vim modelines?)
I'm guessing perhaps you forgot to push changes then? I have the same version as on this PR.

@aidanholm
Copy link
Member

Ok, I see your fixes, let me try again

@schvabodka-man
Copy link
Contributor Author

ok, i pushed, some more fixes. should be ok with this variables. And i know shit about these "cool" vim aliases. My emacs display these lines pretty nicely. Maybe in vim the're broken somehow
https://transfer.sh/14MtiM/screenshot.png

@aidanholm
Copy link
Member

Ok, references are fixed, it's just whitespace errors and the extra require "lousy" lines now; once these are fixed it should be ready to merge!

@aidanholm
Copy link
Member

Nice desktop btw; which wm?

@schvabodka-man
Copy link
Contributor Author

I think it would be ok to merge all this fixes commits into three comits or not?

I3wm, polybar with bunch of scripts, rofi, Fedora(but most likely i would migrate to Void), fish shell and Emacs

@Plaque-fcc
Copy link
Collaborator

Plaque-fcc commented Aug 21, 2017 via email

@schvabodka-man
Copy link
Contributor Author

I don't understand about which extra require "lousy" you're talking about. Projectile with grep gives me 4 require lousy(each for 1 plugin)

@aidanholm
Copy link
Member

  • I'd also prefer that there be three commits, "Update tabmenu module" , "Update yanksel module", etc.
  • oldschoolkeys and yanksel never use the lousy variable, so it should be removed.

@schvabodka-man
Copy link
Contributor Author

Fixed that one lousy

@aidanholm
Copy link
Member

Just whitespace issues now; by the way once this is finished it'd be good to modify the README as well to say which plugins are updated and which aren't.

@schvabodka-man
Copy link
Contributor Author

Can you point me on those whitespaces?

@aidanholm
Copy link
Member

Have you ran the tests? That'll show you where the errors are, but they should be basically the same as in the test paste above. I'd just run sed -e 's/\t/ /g' -e 's/ $//' on oldschoolkeys/init.lua and yanksel/init.lua

Separately, the files are still missing modelines

@schvabodka-man
Copy link
Contributor Author

I've run this sed command but it hasn't changed anything(diff is null).

@schvabodka-man
Copy link
Contributor Author

Okay i've added modelines and i still don't know what whitespaces you're talking about

@aidanholm
Copy link
Member

aidanholm commented Aug 23, 2017

Sorry, I wasn't very clear when explaining before. There are two whitespace issues:

  • The lua files have tabs at the beginning of the line, as part of the indentation. This goes against the luakit code style standard, which is that all files must be indented with spaces only.

    To find these files, run grep -rPn '\t' tabmenu oldschoolkeys yanksel from the luakit-plugins root folder. The easiest way to fix these problems is to do a find and replace in emacs, but you can also use the sed command I posted before.

    Here is the output I get, that shows where the problems are. The file name and the line number are on the left, and the code with the whitespace error (tabs in the indentation) are on the right:

tabmenu/init.lua:20:	  { ":tabmenu", [[Open tab menu]], function (w) w:set_mode("tabmenu") end },
oldschoolkeys/init.lua:13:	  function (w, m)
oldschoolkeys/init.lua:14:		 w.tabs:reorder(w.view, w.tabs:current() - m.count)
oldschoolkeys/init.lua:15:	  end, {count=1}},
oldschoolkeys/init.lua:17:	  function (w, m)
oldschoolkeys/init.lua:18:		 w.tabs:reorder(w.view, (w.tabs:current() + m.count) % w.tabs:count())
oldschoolkeys/init.lua:19:	  end, {count=1}}
yanksel/init.lua:13:	  desc = "Yank selection.",
yanksel/init.lua:14:	  func = function (w)
yanksel/init.lua:15:		 local text = luakit.selection.primary
yanksel/init.lua:16:		 if not text then w:error("Empty selection.") return end
yanksel/init.lua:17:		 luakit.selection.clipboard = text
yanksel/init.lua:18:		 w:notify("Yanked selection: " .. text)
yanksel/init.lua:19:		 luakit.selection.primary = ""
yanksel/init.lua:20:	  end,
  • Trailing whitespace; there's a space at the end of a line in the yanksel/init.lua file. This is also not allowed by the current code standards, as it makes diffs larger than necessary, which makes it more difficult to read them and can cause issues with git blame.

    The problem is at line 11 of yanksel/init.lua (local actions = {). There's only one of these, so it's simple to fix manually, with the backspace key :)

Let me know if that's not clear!

@Plaque-fcc
Copy link
Collaborator

Plaque-fcc commented Aug 23, 2017 via email

@aidanholm
Copy link
Member

@Plaque-fcc no worries, there weren't any tests for that kind of thing with the old luakit, and most things had a mix of tabs and spaces :)

@Plaque-fcc
Copy link
Collaborator

Plaque-fcc commented Aug 23, 2017 via email

@aidanholm aidanholm changed the title Fixed broken tabmenu plugin Update oldschoolkeys, tabmenu, yanksel plugins Aug 23, 2017
@aidanholm
Copy link
Member

aidanholm commented Aug 26, 2017

Hey @schvabodka-man, any progress on this one? I'm happy to help if you have any questions

@schvabodka-man
Copy link
Contributor Author

No, progress. I'm busy now

@aidanholm
Copy link
Member

No problem

@schvabodka-man
Copy link
Contributor Author

Maybe in 2-3 days i will actually start to work on these whitespaces

@aidanholm
Copy link
Member

I've merged this one manually; thanks @schvabodka-man for updating these :)

@aidanholm aidanholm closed this Sep 1, 2017
@schvabodka-man
Copy link
Contributor Author

Thx, i really appreciate your cleanup on whitespaces cause i don't have much time now

@aidanholm
Copy link
Member

No problem

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

Successfully merging this pull request may close these issues.

None yet

3 participants