elisp

How to break out from maphash in Emacs Lisp?

天大地大妈咪最大 提交于 2019-12-11 02:16:43
问题 I need to exit early from maphash when I've found what I was looking for. (defun find-in-hash (str hash) (let ((match nil)) (maphash (lambda (key value) (if (string-prefix-p str key) (setq match key))) hash) match)) How would I do this in Emacs Lisp? 回答1: As explained in how to interrupt maphash you can place a maphash inside a block and exit the block via return-from , i.e. use the form (block stop-mapping (maphash ;; Function to call for all entries in ht. ;; A condition for when to stop

Save original function, locally rebind it with flet and call original function from inside new?

痞子三分冷 提交于 2019-12-11 01:58:56
问题 subj. Something like: (lexical-let (oldf #'original-func) (flet ((original-func (arg) do-something (funcall oldf arg))) do-something)) don't work :( 回答1: Hopefully this will help you with the syntax, calling swap-function calls foo1 but executes foo2. You could write this as a useful macro with-replace-function which binds the old function with the new function while executing a body you pass in. (defun foo1() (insert "hi foo1")) (defun foo2() (insert "hi foo2")) (defun swap-function(old new)

How can I change a word in a buffer using elisp?

江枫思渺然 提交于 2019-12-11 01:54:49
问题 How can I change the word at point using elisp? Something quite like (upcase-word) but using my own function? Background: I've written a function that detects the base of the number at point and can convert it to any other base. What I would like to do is to change the number directly in the buffer. TIA Markus 回答1: Try this code. I've included a sample interactive function using upcase : (defun change-word-at-point (fun) (cl-destructuring-bind (beg . end) (bounds-of-thing-at-point 'word) (let

Emacs Lisp: How to use ad-get-arg and ad-get-args?

耗尽温柔 提交于 2019-12-11 01:51:58
问题 I'm not sure I am using ad-get-args and ad-get-arg right. For example, the following code doesn't work. (defun my-add (a b) (+ a b)) (defadvice my-add (after my-log-on activate) (message "my-add: %s" (ad-get-args))) (my-add 1 2) The last expression causes an error: Debugger entered--Lisp error: (void-function ad-get-args). The following doesn't work either. (defun my-substract (a b) (- a b)) (defadvice my-substract (around my-log-on activate) (message "my-substract: %s" (ad-get-arg 0)) (ad-do

how to return function in elisp

谁说我不能喝 提交于 2019-12-11 01:41:52
问题 This is related to this question: elisp functions as parameters and as return value (defun avg-damp (n) '(lambda(x) (/ n 2.0))) Either (funcall (avg-damp 6) 10) or ((avg-damp 6) 10) They gave errors of Symbol's value as variable is void: n and eval: Invalid function: (avg-damp 6) respectively. 回答1: The reason the first form does not work is that n is bound dynamically, not lexically: (defun avg-damp (n) (lexical-let ((n n)) (lambda(x) (/ x n)))) (funcall (avg-damp 3) 12) ==> 4 The reason the

Filtering result from running start-process in emacs/elisp

孤街浪徒 提交于 2019-12-11 01:39:10
问题 I have the following code to run python and get the result in scratch buffer. (defun hello () "Test, just prints Hello, world to mini buffer" (interactive) (start-process "my-process" "*scratch*" "python" "/Users/smcho/Desktop/temp/hello.py") (message "Hello, world : I'm glad to see you")) (define-key global-map "\C-ck" 'hello) The python code is as follows. if __name__ == "__main__": print "hello, world from Python" Using C-c k gives me the following code in scratch buffer. hello, world from

How do I run a command just after the emacs frame has been rendered?

只愿长相守 提交于 2019-12-11 01:29:34
问题 I'm trying to figure out how to use Emacs Code Browser (ECB) and one of the things you can do with it is set ecb-windows-width to decide how wide the ecb windows are. The problem is this sequence: Frame pops up on screen. ecb-activate gets called, scaled according to ecb-windows-width. default-frame-alist parameters kick in, frame gets resized. The problem is that due to this order the width of the ecb window is set before the frame gets resized, and then doesn't get scaled. So I'd like to

How to get reliable indentation in elisp

家住魔仙堡 提交于 2019-12-10 23:47:10
问题 I'm new to Emacs. I'm trying to write an elisp function that works across all modes. Specifically, I want to write a function that inserts braces (a bit like insert-parentheses ) in the same way the following key sequence does for a dumb editor that only supports auto-indent: "{" <ret> "}" <up-arrow> <end> <ret> <tab> This key sequence works for both Java and C# (bsd) style indentation. I need it to work in all brace-y emacs modes, and also in plain text files - I have other formats that have

How can I tweak this elisp function to distinguish between C-d & DEL?

人盡茶涼 提交于 2019-12-10 23:18:03
问题 Here's my current function (blindly copy-pasted from a website) (defun tweakemacs-delete-one-line () "Delete current line." (interactive) (beginning-of-line) (kill-line) (kill-line)) (global-set-key (kbd "C-d") 'tweakemacs-delete-one-line) There are two quirks here that I want to get rid of. 1) This actually rebinds DEL to the same function. I want my DEL to remain "delete one character". 2) There needs to be a condition where it will not double-kill if the line is only a newline character.

Emacs - Undefine Prefix Key

北战南征 提交于 2019-12-10 21:15:42
问题 I somehow managed to define the 'M' (capital em) key as a prefix key in sqlplus-mode which is preventing me from typing an M. How can I unset this prefix key in this mode? 回答1: Short term fix: M-x local-set-key M self-insert-command Long term fix, find the spot in your .emacs file which defines it a ssuch. @tripleee's comment does sound like a likely candidate for what went wrong. 来源: https://stackoverflow.com/questions/10820058/emacs-undefine-prefix-key