I expect this elisp function to visualize entire function, but it visualizes beginning to cursor

huangapple go评论58阅读模式
英文:

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"))))

huangapple
  • 本文由 发表于 2023年1月6日 10:40:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75026417.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定