Ok_Mouse_8756 · 2022-02-03 11:05
I'm trying to write a simple function to search for a word and then center the page on that word. As a lambda the function works but when I try to define it so I can bind it to "n" I get the error"Invalid function: (evil-search-next)"
I'm not sure what I'm doing wrong. I know a little lisp but not much and I can't seem to figure out what isn't working.
​
​
(define-key evil-normal-state-map (kbd "n") 'search-center-evil)
(defun search-center-evil ()
(interactive)
(progn
((evil-search-next)
(evil-scroll-line-to-center
(line-number-at-pos (point))))))
​
Ok_Mouse_8756 · 2022-02-03 11:14
I just took out the progn and it worked. Kindof confused as to what the progn error was but at least it's working
Least_Isopod_4061 · 2022-02-03 11:41
The body of progn doesn't need to be a list, you enclosed your evil functions in an extra set of parentheses. This works
(progn (message "hello")
(message "world"))
This doesn't
(progn ((message "hello")
(message "world")))
But as you've noticed, you don't need a progn for this function anyways.
iwaka · 2022-02-04 02:51
I wanted similar behaviour, and the way I did it was using an advice.
If you want to center the screen after 10 different functions, advices are simpler to implement than writing 10 different custom functions duplicating library behaviour.
Just a thought. You don't have to do this now, but if you find yourself wanting to add this functionality to other functions, consider using advices.