elisp

How to find a bug in “.emacs” or “init.el”?

跟風遠走 提交于 2019-11-27 09:54:36
问题 Sometimes when I open Emacs, Emacs initialization fail. That is because .emacs or init.el files have a bug. (My bugs often come from just mistyping.) I want to find the bug in .emacs or init.el . Is there any way to do this? 回答1: To find out what part of your init file ( ~/.emacs ) is causing the behavior you see, bisect your init file recursively : First comment-out half, to see which half is responsible, then 3/4, to see which quarter is responsible,... To comment out a region of text (e.g.

Emacs comment/uncomment current line [duplicate]

元气小坏坏 提交于 2019-11-27 09:36:23
问题 This question already has an answer here: Eclipse-like Line Commenting in Emacs 7 answers I know there's already an Emacs question on this, and that it was closed, but I find it quite relevant and important. Basically, I want to comment/uncomment the current line. I was expecting this to be fairly easy with a macro, but I found that it really isn't. If the current line is commented, uncomment. If it is uncommented, comment it. And I would also to comment out the whole line, not just from

Filtering text through a shell command in Emacs

荒凉一梦 提交于 2019-11-27 09:23:11
问题 In vi[m] there is the ! command which lets me pipe text through a shell command -- like sort or indent -- and get the filtered text back into the buffer. Is there an equivalent in emacs? 回答1: You can select a region and type `C-u M-| command RET', and it replaces the region with the command output in the same buffer due to the interactive prefix argument of shell-command-on-region. 回答2: I wrote this a few years back, it might help you: (defun generalized-shell-command (command arg) "Unifies

How to use <escape> (conditionally) as a modifier key

独自空忆成欢 提交于 2019-11-27 08:01:55
问题 Is it possible to have <escape> activate functions when certain conditions exist, yet behave like a modifier key when those conditions are not met? (define-key lawlist-mode-map (kbd "<escape>") (lambda () (interactive) (cond ((ABC . . .) (message "You have satisfied condition ABC.")) ((DEF . . .) (message "You have satisfied condition DEF.")) (t (The <escape> key shall behave like a modifier key: ESC- )) ))) EDIT: Based upon the awesome solution / answer provide by Stefan, the following is an

Emacs shell scripts - how to put initial options into the script?

僤鯓⒐⒋嵵緔 提交于 2019-11-27 07:00:47
Inspired by Stack Overflow question Idomatic batch processing of text in Emacs? I tried out an Emacs shell script with the following headline: #!/usr/bin/emacs --script I put some Emacs Lisp code in it, and saved it as textfile rcat. Since the --script option does not prevent the loading of the site-start file, I had a lot of Loading /etc/emacs/site-start.d/20apel.el (source)... Loading /etc/emacs23/site-start.d/35elib-startup.el (source)... Loading /etc/emacs23/site-start.d/50auctex.el (source)... messages in the Bash shell (stdout). I can prevent that by calling rcat --no-site-file or rcat

How do I do closures in Emacs Lisp?

廉价感情. 提交于 2019-11-27 06:54:43
I'm trying to create a function on the fly that would return one constant value. In JavaScript and other modern imperative languages I would use closures: function id(a) { return function() {return a;}; } but Emacs lisp doesn't support those. I can create mix of identity function and partial function application but it's not supported either. So how do I do that? Stupid idea: how about: (defun foo (x) `(lambda () ,x)) (funcall (foo 10)) ;; => 10 Found another solution with lexical-let (defun foo (n) (lexical-let ((n n)) #'(lambda() n))) (funcall (foo 10)) ;; => 10 Bernard Hurley Real (Not Fake

Convert Emacs macro into Elisp

半腔热情 提交于 2019-11-27 06:36:59
问题 Is there a way to convert an emacs macro into elisp, not like what M-x insert-kbd-macro does, the actual activity becoming elisp statements. Thanks for your help. 回答1: Nope, sorry. There is no trivial way to convert an emacs macro into elisp. Update: There's been some work on Emacs to start down this path. See this thread as a starting point. It's still not possible (June 2010), but there's activity. The first reason I can think of is dealing with interactive commands and translating

Emacs - Error when calling (server-start)

送分小仙女□ 提交于 2019-11-27 06:04:39
I am currently using GNU Emacs 23.0.93.1 in Windows Vista SP1. In my .emacs file I make a call to (server-start) and that is causing an error with the message The directory ~/.emacs.d/server is unsafe . Has anyone seen this and know a fix or workaround? ... other than leaving server turned off ;) Here is the stack trace: Debugger entered--Lisp error: (error "The directory ~/.emacs.d/server is unsafe") signal(error ("The directory ~/.emacs.d/server is unsafe")) error("The directory %s is unsafe" "~/.emacs.d/server") server-ensure-safe-dir("~\\.emacs.d\\server\\") server-start(nil) call

elegant way to count items

拈花ヽ惹草 提交于 2019-11-27 06:01:33
问题 I have a list shaped like this: '(("Alpha" . 1538) ("Beta" . 8036) ("Gamma" . 8990) ("Beta" . 10052) ("Alpha" . 12837) ("Beta" . 13634) ("Beta" . 14977) ("Beta" . 15719) ("Alpha" . 17075) ("Rho" . 18949) ("Gamma" . 21118) ("Gamma" . 26923) ("Alpha" . 31609)) How can I count the total number of occurrences of the terms in the car of each element in the list? Basically I want: (("Alpha" . 4) ("Beta" . 5) ("Gamma" . 3) ("Rho" . 1)) No, this is not homework. I just don't have the "thinking in

How to achieve code folding effects in Emacs?

大兔子大兔子 提交于 2019-11-27 05:47:22
Whats the best way to achieve something like code folding, or the type of cycling that org-mode uses. What would be the best solution in elisp to create this type of behavior? EDIT: I'm sorry I was not clear. I want to program something in elisp that does things very similar to code folding, or actually most like org-mode with the hierarchy that can be expanded. I am wondering the best way to achieve this affect. I think I have heard emacs overlays are a good solution, but I dont know. As far as folding I just use the builtin set-selective-display EDIT NUMBER 2: Thanks for the answers but I