elisp

Emacs - regular expressions in Lisp need to be double-escaped - why?

浪子不回头ぞ 提交于 2019-11-28 08:59:55
I've been playing around with emacs lisp, and I wanted to write a little function to do a regular expression search and replace. I had a heck of a time getting the regular expression to work correctly because I didn't realize that all the special characters need to be double escaped when writing lisp code (but not when using query-replace-regexp interactively!). So for example, using query-replace-regexp interactively you can use ^\(.*\)[\t]-.*$ but when writing elisp code you need to double escape everything like so: ^\\(.*\\)[\t]-.*$ I finally found a reference to this in a Steve Yegge

Can I limit the length of the compilation buffer in Emacs?

给你一囗甜甜゛ 提交于 2019-11-28 07:59:30
问题 Is it possible to limit the number of lines that the Emacs compilation buffer stores? Our build system can produce some 10,000 lines of output on whole product builds, if no errors are encountered. Since my compilation buffer also parses ANSI colors, this can get very, very slow. I would like to have only e.g. 2,000 lines of output buffered. 回答1: It appears that comint-truncate-buffer works just as well for compilation buffers as it does for shell buffers: (add-hook 'compilation-filter-hook

Emacs: highlighting TODO *only* in comments

泪湿孤枕 提交于 2019-11-28 06:28:10
This question is related to another one, Emacs :TODO indicator at left side . I recently came across a minor mode I like a lot called FixmeMode . It supports auto highlighting of TODO marks, and navigating between them. However, I think it makes more sense to recognize the "TODO" strings only in comments, rather than polluting the whole file. Is it possible? Trey Jackson Check out the library fic-mode.el , it has been verified in C++ and Emacs-Lisp. It was written specifically to answer this question. The installation is like any standard package: (require 'fic-mode) (add-hook 'c++-mode-hook

Emacs: if latexmk finishes okay, then show pdf, else display errors

穿精又带淫゛_ 提交于 2019-11-28 06:13:16
问题 Could anyone please give me hand with the step between the first start-process and the second start-process . The second start-process that displays the pdf-file should run only if the first start-process finishes without errors . There is probably some type of successful exit code that can be spotted, but I would need some help please in that regard. I'm open to suggestions regarding how best to determine whether the first start-process finished without errors. One method would be to look at

How do you ensure an association list maintains unique keys in Emacs

自作多情 提交于 2019-11-28 04:48:36
问题 Given the frequency that keys are added to association lists like auto-mode-alist , I presume there is some idiomatic method for maintaining association lists with unique keys, but have yet to encounter it. Let's say I execute the following: (setq alist '()) (add-to-list 'alist '(a . 1)) (add-to-list 'alist '(a . 2)) (add-to-list 'alist '(b . 3)) After running that, alist contains ((b . 3) (a . 2) (a . 1)) . I see that add-to-list can take an optional compare-fn , so I presume there is some

emacs lisp, how to get buffer major mode?

久未见 提交于 2019-11-28 04:04:39
I have tried to search Google and look in the manual, but still cannot find how to get major mode of a buffer object. Can you help me with an example or a reference. Thanks only solution I could find was to query major-mode after changing the buffer and then changing back to original buffer. Is there a better way to do it? Aidan Cully Is there a problem with that? (defun buffer-mode (buffer-or-string) "Returns the major mode associated with a buffer." (with-current-buffer buffer-or-string major-mode)) with-current-buffer will restore your buffer when it returns. For current buffer: (message "

Emacs lisp: why does this sexp cause an invalid-function error?

走远了吗. 提交于 2019-11-28 03:54:45
问题 The sexp in question is (((lambda (b) (lambda (a) (+ b a))) 3) 5) which, to me, looks like it should evaluate to 8 , and in other lisps (e.g. Racket) it does, but in elisp it instead throws this error: Debugger entered--Lisp error: (invalid-function ((lambda (b) (lambda (a) (+ b a))) 3)) It appears to be telling me that ((lambda (b) (lambda (a) (+ b a))) 3) Is not a valid function. This seems wrong, because when I evaluate that expression I get (lambda (a) (+ b a)) which looks like a valid

emacs/elisp: What is the hash (pound, number sign, octothorp) symbol used for?

孤街浪徒 提交于 2019-11-28 03:52:52
What does this do? (add-hook 'compilation-mode-hook #'my-setup-compile-mode) ...and is it different than (add-hook 'compilation-mode-hook 'my-setup-compile-mode) Trey Jackson There is no difference: (eq 'my-add #'my-add) yields t The # can be used in front of a lambda expression indicating to the byte-compiler that the following expression can be byte compiled, see the docs for Anonymous Functions . But there's nothing to compile in the case of a symbol. In general, it is used in the printed representation along with the left angle bracket (<) to indicate that the object printed is a

Emacs — How to push a Git repository to multiple remotes

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 03:52:02
问题 I'm looking for some assistance, please, using Emacs / Magit to push the local repository changes to the remote website and to Github in one fell-swoop. I found a non-Emacs / non-Magit related thread ( https://stackoverflow.com/a/3195446/2112489) , with comments stating that it is the definitive answer on pushing to a remote and to Github, and it has a few hundred thumbs-up. I assume (perhaps incorrectly) that is a good starting point for the local .gitconfig file in the $HOME directory on my

Is there a (repeat-last-command) in Emacs?

醉酒当歌 提交于 2019-11-28 02:42:05
Frequently, I've dug into apropos and docs looking for something like the following only to give up to get back to the task at hand: (repeat-last-command) do the last C- or M- command I just executed (to be rebound to a fn key) or sometimes the related: (describe-last-function) what keystroke did I just mistakenly issue, the effect of which I'd like to add to my bag of tricks. describe-key is close, but requires knowing what I typed. Am I simply asking too much from my trusty sidekick? cms with regards to ' describe-last-function ': There's a variable last-command which is set to a symbol