luahammerspoonfennel

How to configure hs.hotkey.modal with Fennel in hammerspoon?


I'm trying to convert some Hammserspoon Lua code to Fennel, but the converted code is throwing the following error.

ERROR:   LuaSkin: hs.hotkey callback: init.fnl:32: attempt to call a table value stack traceback:   init.fnl:32: in function <init.fnl:23>```

The Lua code is working without issue, here it is -

local myModal = hs.hotkey.modal.new()

hs.hotkey.bind({}, 'F18', function()
   myModal:enter()
end)

myModal:bind('', 'V', function()
    myModal:exit()
hs.alert.show("Modal test")
end)

And, here's the converted code that is giving the error.

(local myModal (hs.hotkey.modal.new))
(print (.. "myModal = " (hs.inspect.inspect myModal)))
(myModal:entered (fn [] (print "myModal entered")))
(myModal:exited (fn [] (print "myModal exited")))
(hs.hotkey.bind {} "F18" 
    (fn [] (myModal:enter)))

(myModal:bind "" "V"
    (fn [] ((myModal:exit)
        (hs.alert.show "Modal Test")
    )))

Not sure why the error is generate here. Can anyone help with identifying the issue with this?

The error is coming from the following bit.

(hs.hotkey.bind {} "F18" 
    (fn [] (myModal:enter)))

I had used hs.inspect to check myModal and here's the output from it.

myModal = {
  keys = {}
}

Solution

  • After trying with different things and testing with https://fennel-lang.org/see , I've found that the error was being thrown by a different part of my code. And, not here (although the error pointed to this line).

    (hs.hotkey.bind {} "F18" 
        (fn [] (myModal:enter)))
    

    The issue was inside the myModal:bind function call. I think I'd misplaced a parenthesis. this works

    (myModal:bind "" :T
        (fn [] (my-modal:exit)
            (hs.alert.show "testing Fennel Modal")
        ))