elisp

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

◇◆丶佛笑我妖孽 提交于 2019-12-10 08:30:45
问题 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

Switching between color themes in Emacs ( < v.24)

时间秒杀一切 提交于 2019-12-10 04:12:12
问题 Update: Note that this thread does not applyt o recent versions of Emacs (24+). Emacs now comes with it's own powerful color theming system (e.g. see a review here) that does not required loading the external package color-theme . I have the following code snippet in my .emacs file, where I defined a few aliases that allow me to switch conveniently between a couple of color themes using short extended commands: (require 'color-theme) (eval-after-load "color-theme" '(progn (color-theme

Does learning one Lisp help in learning the other?

大城市里の小女人 提交于 2019-12-10 02:33:40
问题 Is there any synergy between learning different Lisp languages? I'm currently learning Emacs Lisp, as it is immediately useful in my daily Emacs usage, however i'm fascinated with all Lisps, so maybe someday i will learn and use others. Will learning Emacs Lisp help me, when i start digging in Common Lisp, Scheme or Clojure? In other words, will it be for me like learning a completely new language, or some notions and paradigms are common? I'm also interested in comparison of unique

Why not quoting lambda?

老子叫甜甜 提交于 2019-12-10 02:25:36
问题 I was told that I shouldn't quote lambda in, say, (global-set-key (quote [f3]) '(lambda () (interactive) (other-window -1) )) I tried that indeed if I don't quote lambda, it works equally well (global-set-key (quote [f3]) (lambda () (interactive) (other-window -1) )) However, I don't understand why the latter works (and is also being preferred, and now that the latter works, why the former also works). If the lambda expression is defined as an other function, we would have called (global-set

Advice for “kill-ring-save”

情到浓时终转凉″ 提交于 2019-12-09 21:10:39
问题 I want to evaluate certain conditions before allowing a user to copy a text. As far as I know, I need an advice for "kill-ring-save" . I need to ignore the user request to Copy that text if conditions are not met and allow it if are satisfied. How can I do this? (UPDATE) -- MORE ABOUT CONSTRAINTS: only in specific mode of Emacs (e.g. NXML mode) this advice should be applied and only when one/more specific conditions are met. 回答1: Quick proof of concept; you don't tell what your constraints

Python dictionary or map in elisp

北城余情 提交于 2019-12-09 17:29:57
问题 What is the equivalent of a python dictionary like {'a':1, 'b':2} in elisp? And again, does elisp have any map-reduce api? 回答1: Association lists are the most commonly used associative containers in elisp. It is just a list of key-value cons cells like this ((key . value)) . You can use the assoc function to get a value corresponding to a key and rassoc to get a key with the required value. Elisp comes with the built-in function mapcar which does map, but AFAIK there is no good fold facility.

how to answer yes or no automatically in emacs

自闭症网瘾萝莉.ら 提交于 2019-12-09 15:50:19
问题 I binded function semantic-symref to key C-c C-r like this: (global-set-key (kbd "C-c C-r") 'semantic-symref) everytime I pressed C-c C-r , it prompted: Find references for xxxxx? (y or n) How can I answer it automatically? I tryed using lambda function like this, but failed (global-set-key (kbd "C-c C-r") (lambda() (interactive) (semantic-symref "yes"))) 回答1: The answer by @huitseeker is quite neat and effective. After four years, with flet and defadvice being obsolete, I wrote the following

Force emacs recent files using recentf to ignore specified files (.windows and .revive for example)

喜夏-厌秋 提交于 2019-12-09 14:52:15
问题 I have always been bugged by the fact that when exiting with revive.el and windows.el enabled it opens a file and writes to it called .revive and .windows. These are saved so it goes in the recent files list. Is there anyway to make it ignore these files or any other files I desire. 回答1: A way to make recentf ignore some files is to add appropriate regexps to recentf-exclude list: (add-to-list 'recentf-exclude "\\.windows\\'") (add-to-list 'recentf-exclude "\\.revive\\'") This will prevent

Higher-order functions in Elisp

允我心安 提交于 2019-12-09 09:56:50
问题 I created a function that returns a function in Elisp: (defun singleton-set (elem) (defun f (n) (= n elem)) f) I try to run this in IELM, and it fails: ELISP> (singleton-set 5) *** Eval error *** Symbol's value as variable is void: f ELISP> ((singleton-set 5) 5) *** Eval error *** Invalid function: (singleton-set 5) Due to What is the difference between Lisp-1 and Lisp-2? i changed the code to (defun singleton-set (elem) (defun f (n) (= n elem)) #'f) And invocation to (funcall (singleton-set

Programmatically selecting a region

一曲冷凌霜 提交于 2019-12-09 08:48:16
问题 I want to perform the same action that one does by hitting C-Space + moving the arrow keys, but in elisp. Failing to find the right function (if they just were logically grouped in namespaces or somehow tagged...). Which one is it? 回答1: You can translate keystrokes to elisp using C-h k key . You'll notice the elisp function for setting the mark set-mark-command , takes one non-optional argument. Emacs uses the special interactive function to allow elisp functions to be written naturally with