elisp

let and flet in emacs lisp

笑着哭i 提交于 2019-12-20 08:29:25
问题 I don't know if you would call it the canonical formulation, but to bind a local function I am advised by the GNU manual to use 'flet': (defun adder-with-flet (x) (flet ( (f (x) (+ x 3)) ) (f x)) ) However, by accident I tried (after having played in Scheme for a bit) the following expression, where I bind a lambda expression to a variable using 'let', and it also works if I pass the function to mapcar*: (defun adder-with-let (x) (let ( (f (lambda (x) (+ x 3))) ) (car (mapcar* f (list x)) ))

The difference between setq and setq-default in Emacs Lisp

风流意气都作罢 提交于 2019-12-20 08:09:17
问题 I have a question about Emacs Lisp. What is the difference between setq and setq-default ? I am very confused about it. Tutorials say setq takes effect in the local buffer while setq-default affects all buffers. For example, if I wrote (setq a-var a-vars-value) in init.el , I found after starting Emacs and opening a new buffer, the a-var is also there and its value is a-vars-value . I thought it was not supposed to be there. It seems there is no difference between setq and setq-default . Is

Emacs Key Binding Precedence

﹥>﹥吖頭↗ 提交于 2019-12-20 06:42:38
问题 I'm frustrated with the default behavior of autocomplete overriding key bindings used by yasnippets . Is there a way to set a precedence so that tab will try to expand a snippet before trying to autocomplete the word? Quick disclosure: I'm using evil-mode. 回答1: If they're both minor modes, then precedence is determined by the order of elements in minor-mode-map-alist which, unless explicitly manipulated, is simply determined by the order in which the libraries were loaded. Ensure that

How to use `setcdr` with buffer-local variables

ⅰ亾dé卋堺 提交于 2019-12-20 04:26:26
问题 I am experiencing behavior using setcdr that would seem to suggest that it is not confined to buffer-local variables containing the same name in different buffers. I have tried using with-current-buffer , but that does not correct the issue. For example, buffer-A and buffer-B both contain a local-variable named variable-one , which is a cons cell -- e.g., (overlay-string t) , and setcdr is being used to set the cdr value to either t or nil . Is there a way to ensure that setcdr remains

Emacs — creating a custom highlight parentheses function

China☆狼群 提交于 2019-12-20 03:29:09
问题 I'm looking for some assistance, please, further modifying the following already modified excerpt from the highlight-parentheses library: https://github.com/nschum/highlight-parentheses.el [Fn 1.] GOAL : The goal is to use something like mapcar or dolist to automatically replace INSERT-FACE-HERE with a different face from the variable my-parens-faces each time while does a loop . The visual effect will be a rainbow coloring of parentheses based on the level of nesting. I am removing the

Function that remove specific lambda from a hook in Emacs

对着背影说爱祢 提交于 2019-12-20 02:07:47
问题 I found this macro, to run code for specific project path: (defmacro project-specifics (name &rest body) `(progn (add-hook 'find-file-hook (lambda () (when (string-match-p ,name (buffer-file-name)) ,@body))) (add-hook 'dired-after-readin-hook (lambda () (when (string-match-p ,name (dired-current-directory)) ,@body))))) and I use it: (project-specifics "projects/test" (message "z")) And I work on modification that will remove prevoius lambda from the hook, so far I have helper functions (defun

Function that remove specific lambda from a hook in Emacs

久未见 提交于 2019-12-20 02:06:30
问题 I found this macro, to run code for specific project path: (defmacro project-specifics (name &rest body) `(progn (add-hook 'find-file-hook (lambda () (when (string-match-p ,name (buffer-file-name)) ,@body))) (add-hook 'dired-after-readin-hook (lambda () (when (string-match-p ,name (dired-current-directory)) ,@body))))) and I use it: (project-specifics "projects/test" (message "z")) And I work on modification that will remove prevoius lambda from the hook, so far I have helper functions (defun

Value of the dired-directory

只愿长相守 提交于 2019-12-20 01:40:55
问题 I wanted to run a script in the location of the current buffer, or, if it is a dired buffer - to run the script on the current dired directory. The current dired directory seems to be stored in dired-directory variable. Indeed it is - but when I try to make use of it - it sometimes gives me the previous dirs instead of the current one: (defun bk-konsoles () "Calls: bk-konsoles.bash" (interactive) (let ((curDir (if (memq major-mode '(dired-mode sr-mode)) dired-directory (if (buffer-file-name)

How do I handle password prompts when calling elisp from the terminal

末鹿安然 提交于 2019-12-19 10:52:15
问题 I'm trying to use elisp as a shell script language. I'm writing a script where I need access to a file encrypted with gpg. I'm not sure how to handle the password prompt. In the examples below, he program is called from the command line (bash). First try: #!/usr/bin/emacs --script (setq passwd-file "~/password.gpg") (save-excursion (let ((passwd-buffer (find-file passwd-file))) (switch-to-buffer passwd-buffer) (princ (buffer-substring 1 30)))) This lets me enter the password in the terminal,

How to type a dynamic file entry for org capture

◇◆丶佛笑我妖孽 提交于 2019-12-19 10:43:14
问题 I'm trying to figure out if there is some way to create a dynamic file name for capture in emacs org-mode. ("z" "test" entry (file+headline ***A date specific headline*** "Notes")) "** %^{prompt}") Is there some simple way to pass a date and year to the file part, so that I can have a file dynamically created for each month. What I'd like is something like this: (concat "/home/me/file/report_notes_" (format-time-string "%m_%Y") ".org") Edit - I've finally got it working, using backquoting: `(