elisp

How to keep dir-local variables when switching major modes?

心不动则不痛 提交于 2019-11-27 14:11:39
I'm committing to a project where standard indentations and tabs are 3-chars wide, and it's using a mix of HTML, PHP, and JavaScript. Since I use Emacs for everything, and only want the 3-char indentation for this project, I set up a ".dir-locals.el" file at the root of the project to apply to all files/all modes under it: ; Match projets's default indent of 3 spaces per level- and don't add tabs ( (nil . ( (tab-width . 3) (c-basic-offset . 3) (indent-tabs-mode . nil) )) ) Which works fine when I first open a file. The problem happens when switching major modes- for example to work on a chunk

Get rid of “reference to free variable” byte-compilation warnings

与世无争的帅哥 提交于 2019-11-27 13:39:00
问题 I'm writing an emacs major mode, which uses buffer-local variables to store some state: (defun foo-mode () "My nice major mode" (interactive) (kill-all-local-variables) (setq mode-name "foo") (setq major-mode 'foo-mode) (set (make-local-variable 'foo-state) "bar")) (defun foo-change-state () (setq foo-state "baz")) This works very well and has the property that in any buffer not using my major mode, the foo-state variable is not bound (which is a good thing in my opinion, since it avoids

Unicode characters in emacs term-mode

落爺英雄遲暮 提交于 2019-11-27 13:29:07
问题 I use ansi-term for my normal terminal sessions. I tend to use unicode characters in my prompt to do things like set the trailing character based on the type of source control I'm using. I use the character "±" as my prompt for git repositories. In Emacs' ansi-term, my prompt isn't rendered as unicode, and shows as "\302\261". Displaying the current coding system shows that it defaults to utf-8-unix for input to the process, but I get raw binary as the decoding output. I can hit C-c RET p to

Emacs custom command line argument

只谈情不闲聊 提交于 2019-11-27 13:14:58
问题 From the documentation I can see I can access command line arguments (command-line-args). I'd like to add my own arguments but Emacs complains at start up that it doesn't recognize them. E.g. emacs -my_argument I get: command-line-1: Unknown option `-my_argument' What's a proper way to define my custom arguments and provide information to my Emacs session? Is there a way to pop an argument from a command line? 回答1: Add something like this to your ~/.emacs , ~/.emacs.el , or ~/.emacs.d/init.el

Emacs Lisp: How to add a folder and all its first level sub-folders to the load-path

放肆的年华 提交于 2019-11-27 13:03:46
问题 If I have a folder structure set up like this: ~/Projects emacs package1 package1-helpers package2 package2-helpers package2-more-helpers package3 package3-helpers How do I add these folders: ~/Projects/emacs ~/Projects/emacs/package1 ~/Projects/emacs/package2 ~/Projects/emacs/package3 ...to the load-path from my .emacs file? I basically need a short automated version of this code: (add-to-list 'load-path "~/Projects/emacs") (add-to-list 'load-path "~/Projects/emacs/package1") (add-to-list

Emacs :TODO indicator at left side

我怕爱的太早我们不能终老 提交于 2019-11-27 12:57:58
问题 I want to have sort of indiacator at left side of the line wherever I have in the source code #TODO : some comment //TODO: some comments The indicator could be a just mark and I already enabled line numbers displayed at emacs. 回答1: This command will do something like you want. (defun annotate-todo () "put fringe marker on TODO: lines in the curent buffer" (interactive) (save-excursion (goto-char (point-min)) (while (re-search-forward "TODO:" nil t) (let ((overlay (make-overlay (- (point) 5)

Idiomatic batch processing of text in Emacs?

一曲冷凌霜 提交于 2019-11-27 12:54:52
In Python, you might do something like fout = open('out','w') fin = open('in') for line in fin: fout.write(process(line)+"\n") fin.close() fout.close() (I think it would be similar in many other languages as well). In Emacs Lisp, would you do something like (find-file 'out') (setq fout (current-buffer) (find-file 'in') (setq fin (current-buffer) (while moreLines (setq begin (point)) (move-end-of-line 1) (setq line (buffer-substring-no-properties begin (point)) ;; maybe (print (process line) fout) ;; or (save-excursion (set-buffer fout) (insert (process line))) (setq moreLines (= 0 (forward

“Wrong type argument: commandp” error when binding a lambda to a key

早过忘川 提交于 2019-11-27 11:24:33
I am getting a "Wrong type argument: commandp, (lambda nil (forward-line 5))" here. (global-set-key [?\M-n] (lambda () (forward-line 5))) What is the error? I'm fairly sure it's simple & I'm missing something obvious. brendan global-set-key expects an interactive command. (lambda () (interactive) (forward-line 5)) ought to work. By the way, C-h f commandp is a pretty good starting point for errors like that. Baishampayan Ghose The correct form should be this - (global-set-key (kbd "M-n") (lambda () (interactive) (forward-line 5))) The problem was that you forgot to put (interactive) (as

How to go about learning Common Lisp and Emacs Lisp?

北战南征 提交于 2019-11-27 11:09:29
问题 The last few months I've been using Emacs extensively as my main development environment and I've now come to a point at which I'd like to learn it's own Emacs Lisp to write my own little stuff for Emacs and extend it to my personal needs. Having said that I've also wanted to learn Common Lisp for a while now, to play around with and explore a new language. My question is, where should I start from? Will Emacs Lisp give me the necessary knowledge to pick up Common Lisp later more easily or

How to maximize Emacs on Windows at startup?

浪子不回头ぞ 提交于 2019-11-27 10:15:37
问题 This is driving me crazy: I simply want Emacs to maximize to whatever screen resolution I have at startup. Ideally I like a cross-platform (Windows & Linux) solution that works on any screen resolution, but I can't even get it to work on just Window XP with even hard-coded sizes. Here are what I tried: Setting the initial-frame-alist with appropriate height/width Setting the default-frame-alist (Windows specific stuff) Sending message to the emacs windows telling it to maximize via (w32-send