开发者

Elisp programming - what's the best setup?

开发者 https://www.devze.com 2023-02-15 10:13 出处:网络
There are all kind of cool programming language modes in Emacs, written in elisp, but apparently no special support for elisp itself.

There are all kind of cool programming language modes in Emacs, written in elisp, but apparently no special support for elisp itself.

Since slime is not working for elisp, I ask myself if all that elisp code is just hacked in the scratch buffer? Is there no need for something li开发者_开发技巧ke slime when writing elisp, or is it simply not there? Is anybody using ECB and semantic for bigger elisp projects?


ielm is the Emacs Lisp REPL: Interactive Emacs Lisp Mode.

M-x ielm gets you there.


Emacs itself comes with Emacs Lisp support. Basic-to-intermediate things like completion (M-TAB), library search (M-x apropos), documentation (C-h f, C-h v, C-h S), running code on-the-fly (C-M-x, M-:) operate directly in the running Emacs.

Slime's primary purpose is interaction with an external process. You don't need that for Emacs Lisp (unless you're developing for a different version of Emacs, but that's a rare concern).

The features of ECB and semantic are mostly useful for large projects (consisting of more than a handful of source files). People don't tend to write large projects in Emacs Lisp.


There's always emacs-lisp-mode, which (at least in Emacs 23) is automatically loaded whenever you edit a .el file. This appears to be what many emacs lisp hackers use to write their programs. It has a few nice features (like compiling or evaluating a buffer, some debugging tools, profiling). The *scratch* buffer is by default edited from lisp-interaction-mode, which is a bit different.

It's not quite as full featured as, say, slime (elisp has a much smaller community than common lisp), but it definitely works. You'd have to poke around the documentation and experiment with the mode to see what kind of features you can use.


As indicated, Emacs is already the definitive elisp development environment, and internally provides you with most of the functionality you are likely to want.

You might potentially also use ctags/etags to generate an external index for your elisp code base, if you were wanting to jump to function definitions which were not already loaded (and lacked autoload declarations). M-x find-function RET handles this otherwise. (I bind that to C-hC-f)

The "apropos" functions are key to finding things in general. I use the following bindings for easy access:

(define-prefix-command 'Apropos-Prefix nil "Apropos (a,c,d,i,l,v,C-v)")
(global-set-key (kbd "C-h C-a") 'Apropos-Prefix)
(define-key Apropos-Prefix (kbd "a")   'apropos)
(define-key Apropos-Prefix (kbd "C-a") 'apropos)
(define-key Apropos-Prefix (kbd "c")   'apropos-command)
(define-key Apropos-Prefix (kbd "d")   'apropos-documentation)
(define-key Apropos-Prefix (kbd "i")   'info-apropos)
(define-key Apropos-Prefix (kbd "l")   'apropos-library)
(define-key Apropos-Prefix (kbd "v")   'apropos-variable)
(define-key Apropos-Prefix (kbd "C-v") 'apropos-value)

;; Use prefix arg (C-u) to see more results for a call,
;; or uncomment the next line to do this by default:
;; (setq apropos-do-all t)
;; See C-h v apropos-do-all RET for details.

I also enable eldoc-mode and I have imenu-ido-goto-symbol bound (but very rarely utilised).

There are other libraries that may prove useful. I know that some people swear by ParEdit, for example. Admittedly, it's a bit difficult to target a search for elisp libraries which are useful for writing elisp. I'm not sure if the Emacs Wiki has a category for this?


  • I generally use emacs-lisp-mode in preference to the default mode for *scratch*. 99% of the time I want to save even throw-away, interactive tests (at least temporarily), so I more often use a *.el file than *scratch*.

  • Icicles can help a lot when interacting with Emacs Lisp. The ways are too numerous to list here. Here are two overviews that can give an idea:

http://www.emacswiki.org/emacs/EmacsNewbieWithIcicles

http://www.emacswiki.org/emacs/Icicles_-_Nutshell_View


I think add this to you .emacs

(define-key emacs-lisp-mode-map (kbd "M-.") 'find-function-at-point)

will be very helpful.


M-x edebug-defun 

to debug the function I think these is the best debug tools for elisp.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号