emacs的基本功能

sco*_*yaz 1 emacs elisp

我之前从未编写过emacs函数,并且想知道是否有人可以帮助我开始.我希望有一个函数,它将突出显示的区域解析它(通过","),然后用已经内置到emacs中的另一个函数计算每个块.

突出显示的代码可能是这个样子:x <- function(w=NULL,y=1,z=20){}(R代码),我想刮出来w=NULL,y=1z=20然后通过每一个功能已经包含emacs的.有关如何入门的任何建议?

sds*_*sds 9

A lisp function is defined using defun (you really should read the elisp intro, it will save you a lot of time - "a pint of sweat saves a gallon of blood").

To turn a mere function into an interactive command (which can be called using M-x or bound to a key), you use interactive.

To pass the region (selection) to the function, you use the "r" code:

(defun my-command (beg end)
  "Operate on each word in the region."
  (interactive "r")
  (mapc #'the-emacs-function-you-want-to-call-on-each-arg
        ;; split the string on any sequence of spaces and commas
        (split-string (buffer-substring-no-properties beg end) "[ ,]+")))
Run Code Online (Sandbox Code Playgroud)

Now, copy the form above to the *scratch* emacs buffer, place the point (cursor) on a function, say, mapc or split-string, then hit C-h f RET and you will see a *Help* buffer explaining what the function does.

你可以通过点击C-M-x它来评估函数定义(不要忘记the-emacs-function-you-want-to-call-on-each-arg用有意义的东西替换),然后通过选择w=NULL,y=1,z=20和点击来测试M-x my-command RET.

顺便说一下,C-h f my-command RET现在将显示Operate on each word in the region*Help*缓冲区中.