agzam / spacehammer

Hammerspoon config inspired by Spacemacs
MIT License
556 stars 70 forks source link

window history push can try to index win when it is nil #146

Closed Grazfather closed 2 years ago

Grazfather commented 2 years ago
(fn history.push
  [self]
  "
  Append current window frame geometry to history.
  self refers to history table instance
  "
  (let [win (hs.window.focusedWindow)    ; Can be nil
        id (: win :id)                   ; Error here
        tbl (. self id)]
    (when win                            ; Yet we protect here
      (when (= (type tbl) :nil)
        (tset self id []))
      (when tbl
        (let [last-el (. tbl (length tbl))]
          (when (~= last-el (: win :frame))
            (table.insert tbl (: win :frame))))))))
2021-10-27 08:07:56: 08:07:56 ERROR:   LuaSkin: hs.timer callback error: ./windows.fnl:20: attempt to index a nil value (local 'win')
stack traceback:
    ./windows.fnl:20: in method 'push'
    ./windows.fnl:71: in function 'windows.maximize-window-frame'
    (...tail calls...)

Not sure how I got a nil window, but I did. On my work computer, should be an easy fix for after work.

Grazfather commented 2 years ago

Easy to repro: Just minimize a window and then run it, e.g. with (hs.hotkey.bind [:alt] :x (fn [] (print (hs.window.focusedWindow))))