elisp

macro expansion: to quote the body forms or not?

我的未来我决定 提交于 2019-12-05 20:50:07
I'm having a hard time understanding exactly how macro expansion works. What is the difference in how the elisp interpreter handles these two snippets of code? (defmacro foo (arg) (message "arg is: %s" arg)) (foo "bar") and: (defmacro foo (arg) `(message "arg is: %s" ,arg)) (foo "bar") You example may be confusing because message both displays a message and returns it. strings (like "bar") are self-evaluating. Instructive Example (defconst zzz 123) (defmacro zzz1 (arg) `(insert (format "arg is: %s" ,arg))) (defmacro zzz2 (arg) (insert (format "arg is: %s" arg))) Evaluate the code above using C

Emacs: disable Ido completion in Tramp mode

拟墨画扇 提交于 2019-12-05 20:14:33
问题 I often use ido for auto-completion and tramp to access remote server via ssh. My .emacs includes the following lines: (require 'tramp) (setq tramp-default-method "ssh") (ido-mode 1) (setq ido-enable-flex-matching t) (setq ido-everywhere t) I want to disable Ido completion, when i'm browsing contents of remote server. Note that variable ido-enable-tramp-completion has nothing to do with my problem. Consider line /root@site.com#1234:/var/www/file.txt . I need Ido not to deduct the part after

How to create an empty file by elisp?

本秂侑毒 提交于 2019-12-05 18:24:15
问题 I set an explicit file to customization created via the UI. It's named custom.el . Currently, I use the followed snippets to create this file if not exist. (defconst custom-file (expand-file-name "custom.el" user-emacs-directory)) (unless (file-exists-p custom-file) (shell-command (concat "touch " custom-file))) There is an ugly shell-command touch in, any other elisp functions can do this? 回答1: You can use (write-region "" nil custom-file) not sure that is the ideal solution. 来源: https:/

Emacs ESS Mode TAB stops indenting

巧了我就是萌 提交于 2019-12-05 18:13:22
I'm using Emacs 24 on Windows to write some R code. Up until about 30 minutes ago, whenever I would write a new function, ESS would automatically indent the lines following the function declaration and pressing the tab key on a new blank line would jump me to the appropriately indented starting position inside the declaration. EG: foo <- function() { first line started here second line here. .etc } Now, it is hard wrapping everything to the left, and not responding by automatically indenting after the function declaration or when I hit the tab key. foo <- function() { first line second line }

How to process a series of files with elisp?

╄→гoц情女王★ 提交于 2019-12-05 15:47:41
I'm a newbie to programming, so please bear with me here... I have a directory full of files called "foo01.txt", "foo02.txt", etc. and a function called MyFunction . I want to open each file as a buffer, run MyFunction on it, write the buffer to its file, kill the buffer and move on to the next file in the series until all the files are done. I think all the pieces I need to do this are described in the Cookbook ( http://emacswiki.org/emacs/ElispCookbook ) but I'm not really understanding how to put it all together. Thanks! Answer If you're looking for an answer in pure elisp, you could do

Gist (gist.el / Emacs) — Set the `description` at the time of creation

自闭症网瘾萝莉.ら 提交于 2019-12-05 15:39:11
The default behavior of gist-region is to leave the description blank. To set the description, it is necessary to switch to the gist-list buffer and then use the function gist-edit-current-description to set the description . I would like to be able to set the description at the same time that the gist is created, without switching to the gist-list buffer. A mini-buffer prompt that defaults to the buffer-name would be the preferred method of handling this. How can this be accomplished programmatically? Here are the two main functions in gist.el that are responsible for the behavior described

How do I get emacs to write to read-only files automatically?

微笑、不失礼 提交于 2019-12-05 14:39:55
I am finding myself editing a lot of files that are read-only. I usually hit C-x C-q to call toggle-read-only . Then I hit C-x C-s to save and get, File foo.txt is write-protected; try to save anyway? (y or n) After hitting y , the file is saved and the permissions on the file remain read-only. Is there a way to shorten this process and make it so that simply saving a file with C-x C-s does the whole thing without prompting? Should I look into inserting chmod in before-save-hook and after-save-hook or is there a better way? Adding a call to chmod in before-save-hook would be clean way to

Is it possible to make emacs interpet an fn key as a modifier key?

感情迁移 提交于 2019-12-05 13:52:36
Is it possible to make emacs interpet an fn key as a modifier key? Can I bind f6, f.ex. to hyper? I had this: (setq ns-function-modifier 'hyper) ; set Mac's Fn key to type Hype And tried to do this: (setq <f6> 'hyper) But the latter did not work. I'd prefer not making the OS as a whole see f9 as some sort of modifier key (making it possible to more easily use the function keys for different purposes in other apps). Edit: It seems like one possible solution is to bind f9 to C-x @ h but when I try to get the documentation for the function C-x @ or C-x @ h I don't get any result. (It only shows a

Non-interactive emacs regex substitute

一曲冷凌霜 提交于 2019-12-05 13:47:21
Is there a (non-interactive) function in emacs lisp that replaces a matched regex in an arbitrary string? i.e. (sub regex search-string replace-string) as in (sub "[^.x/]" "beef./xxfoo" "") ;; => "./xx" Yes, see function replace-regexp-in-string . Simple as that. And to replace matching text in a buffer, you have replace-regexp . The replacement does not need to be a literal string, but can involve retrieving parts of the regexp match and other manipulations. Use C-h f to see the doc for these functions. 来源: https://stackoverflow.com/questions/27235293/non-interactive-emacs-regex-substitute

in elisp's let, how do you reference a variable bound in the same let while binding another variable?

一个人想着一个人 提交于 2019-12-05 13:44:53
问题 (let ((a 1) (b (+ a 1))) (message a)) This throws the error Debugger entered--Lisp error: (void-variable a) What's the canonical way to do this? 回答1: The canonical way is to use let* (also note that I added a %s format string to your message form): (let* ((a 1) (b (+ a 1))) (message "%s" a)) The let* function allows you to reference other variables that have previously been defined. 来源: https://stackoverflow.com/questions/6794691/in-elisps-let-how-do-you-reference-a-variable-bound-in-the-same