英文:
I expect this elisp function to visualize entire function, but it visualizes beginning to cursor
问题
It looks like the function that I use is not correctly visualizing the entire function. Currently, the function only visually highlights the region from the beginning of the function to the current buffer cursor position.
I want to modify this function to select the function, from top to bottom.
(defun evil-visual-current-function ()
"Highlight the entire current function in Evil's visual mode."
(interactive)
(let ((function-name (which-function)))
(if function-name
(save-excursion
(beginning-of-defun)
(evil-visual-make-selection (point)
(end-of-defun) (point))) ; move cursor to end of function
(message "Not inside a function"))))
英文:
It looks like the function that I use is not correctly visualizing the entire function. Currently, the function only visually highlights the region from the beginning of the function to the current buffer cursor position.
I want to modify this function to select the function, from top to bottom.
(defun evil-visual-current-function ()
"Highlight the entire current function in Evil's visual mode."
(interactive)
(let ((function-name (which-function)))
(if function-name
(save-excursion
(beginning-of-defun)
(evil-visual-make-selection (point)
(end-of-defun) (point))) ; move cursor to end of function
(message "Not inside a function"))))
答案1
得分: 1
When you leave the save-excursion
block, the cursor moves back to the original position, which changes the selected region. Change the function to:
(defun evil-visual-current-function ()
"在 Evil 的可视模式中突出显示整个当前函数。"
(interactive)
(let ((function-name (which-function)))
(if function-name
(progn
(beginning-of-defun)
(evil-visual-make-selection (point) (end-of-defun) (point)))
(message "不在函数内部")))))
英文:
When you leave the save-excursion
block, the cursor moves back to the original position, which changes the selected region. Change the function to:
(defun evil-visual-current-function ()
"Highlight the entire current function in Evil's visual mode."
(interactive)
(let ((function-name (which-function))
(if function-name
(progn
(beginning-of-defun)
(evil-visual-make-selection (point) (end-of-defun) (point)))
(message "Not inside a function"))))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论