How can I change a word in a buffer using elisp?

江枫思渺然 提交于 2019-12-11 01:54:49

问题


How can I change the word at point using elisp? Something quite like (upcase-word) but using my own function?

Background: I've written a function that detects the base of the number at point and can convert it to any other base. What I would like to do is to change the number directly in the buffer.

TIA Markus


回答1:


Try this code. I've included a sample interactive function using upcase:

(defun change-word-at-point (fun)
  (cl-destructuring-bind (beg . end)
      (bounds-of-thing-at-point 'word)
    (let ((str (buffer-substring-no-properties beg end)))
      (delete-region beg end)
      (insert (funcall fun str)))))

(defun upcase-word ()
  (interactive)
  (change-word-at-point 'upcase))


来源:https://stackoverflow.com/questions/22299920/how-can-i-change-a-word-in-a-buffer-using-elisp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!