Emacs Lisp Function Guide?

前端 未结 12 2271
清歌不尽
清歌不尽 2021-01-30 12:13

I have been using Emacs for more than three years now but it still takes me days to write even small functions in Lisp. I\'ve looked through GNU Emacs Lisp Reference Manual but

相关标签:
12条回答
  • 2021-01-30 12:18

    Have you tried the build-in manual in emacs? Open any lisp buffer (or any buffer in lisp mode), move your point to any function or variable, and hit C-h f (for function) or C-h v (for variable). Emacs will give you a fairly concise description of the function/variable.

    For example, the manual content for (save-excursion) is

    save-excursion is a special form in `C source code'.
    (save-excursion &rest BODY)
    
    Save point, mark, and current buffer; execute BODY; restore those things.
    Executes BODY just like `progn'.
    The values of point, mark and the current buffer are restored
    even in case of abnormal exit (throw or error).
    The state of activation of the mark is also restored.
    
    This construct does not save `deactivate-mark', and therefore
    functions that change the buffer will still cause deactivation
    of the mark at the end of the command.  To prevent that, bind
    `deactivate-mark' with `let'.
    

    The good thing also is the build-in manual give you "link" to to the source code of the function and to other functions that might be related, which make it nice to browse around.

    Of course you can't learn lisp this way, but for looking up documentation of function this is a nice starter. When you find the build-in manual not understandable (which sometimes does happen), then it's time for you to google the function ;)

    0 讨论(0)
  • 2021-01-30 12:19

    The GNU Introduction to emacs lisp is certainly more approachable than the reference manual.

    0 讨论(0)
  • 2021-01-30 12:19

    If you're willing to fork over money for a dead tree, I'd recommend


    (source: oreilly.com)

    0 讨论(0)
  • 2021-01-30 12:19

    In XEmacs, and I believe in Emacs as well, pressing C-h f, then the tab key for tab completion, which at that point is all functions, will give you a list of functions the editor knows about.

    You just use cursor keys and scroll to one you want to know about and press enter to see details.

    If a list of functions, with further info available, is what you want, that will give it to you.

    This list is all currently available functions, so if you have packages of lisp installed, it shows the functions those packages supply as well as native functions. In my copy of XEmacs, today, I have 6,586 functions in the list. Emacs will be similar.

    The problem is that not all functions have names that make them context-meaningful (ie not all menu variables/functions have the word menu in them, so you will miss some things if you go by names only.

    You can use the INFO pages (on the menu) to view them more topically arranged, and get to the same usage information.

    0 讨论(0)
  • 2021-01-30 12:23

    I think you are taking the wrong approach. When learning a programming language and set of libraries (collectively, "Emacs Lisp"), you need to approach it on both the micro and macro scale. Before you can start writing software, you need to know what tools you have available. That is what the Emacs Lisp manual aims to educate you on. You really need to sit down and read the whole thing. That way you know what features Emacs provides.

    After you do that, you need "micro-level" information. There are a number of sources that provide this. If you have a general idea of what you need to do ("working with buffers"), then the Lisp reference is a good place to figure out what you need to know. If you know that there's a function that does what you want, but don't quite remember the name, then M-x apropos (C-u C-h a) will help you search the documentation. If you know what function you want to use, but don't remember quite how it works, then M-x describe-function (C-h f) will sort that out for you.

    So anyway, the key is to learn Emacs Lisp, and then let Emacs help you with the details. A list of functions isn't going to teach you much.

    (Oh, one more thing -- you should familiarize yourself with Common Lisp. Most Emacs libraries use cl, which are the useful CL functions implemented in Emacs Lisp. loop, destructuring-bind, defun*, and so on are all there, and they are very helpful.)

    0 讨论(0)
  • 2021-01-30 12:24

    I would add a couple of things:

    • M-x apropos - searches functions and variables for whatever string you specify (e.g. directory). Note that this is slightly different than C-h a, which only finds interactive functions

    • find a similar piece of code and copy it - you can learn an awful lot about how to do things by looking at what's already done. If you have a particular function you want to see examples of, one good way is to visit the main lisp source directory in dired (e.g. d:/product/emacs/lisp or /usr/share/lib/emacs/lisp) and do % g which will grep through all files looking for whatever string you type. Open up that file and see what other people have done with it.

    • C-h f and C-h v - as someone else mentioned, you can open up source, position point over a function or variable and then get documentation on it.

    • Check out the Emacs wiki, which has a crap-load of Emacs lisp modules for you to peruse.

    0 讨论(0)
提交回复
热议问题