elisp

Emacs lisp lambda with lexical binding?

我是研究僧i 提交于 2019-12-10 20:45:24
问题 I set out to write this code snippet for "git add -p": (add-hook 'diff-mode-hook (lambda() (mapc (lambda(k) (lexical-let ((kk k)) (define-key diff-mode-map k (lambda()(interactive) (if (region-active-p) (replace-regexp "^." kk nil (region-beginning) (region-end)) (insert kk)))))) (list " " "-" "+")))) It works as I want, it's just the ugliness of 'lexical-let in the middle that bothers me. I had to add it, since the nested lambda didn't see the variable 'k. Is there a better way to write this

Resize occur window in Emacs

寵の児 提交于 2019-12-10 19:10:56
问题 When entering occur mode for example (occur "test") the frame splits into two windows as shown below: As seen the Occur buffer is taking up too much space on the frame, since there is only two matches (for the text "test"). I would like to shrink that window accordingly. I tried the following code: (defun test-occur () (interactive) (occur "test") (save-window-excursion (other-window 1) (let (( win (selected-window)) (n (count-lines (point-min) (point-max))) (h (window-body-height))) (let (

How can I unbind C-tab from jedi:complete?

亡梦爱人 提交于 2019-12-10 19:04:05
问题 With jedi-mode enabled, the C-tab is bound to jedi:complete . How can I unbind it so that I can then bind it back to other-window ? I've tried: (global-set-key (kbd "C-`") 'jedi:complete) (global-set-key [C-tab] 'other-window) (global-unset-key (kbd "<C-tab>")) (defcustom jedi:key-complete (kbd "C-`") "Keybind for command `jedi:complete'." :group 'jedi) None of them is getting me the desired results. 回答1: You can use: (define-key jedi-mode-map (kbd "<C-tab>") nil) None of the commands with

Emacs - set mark on edit location

只谈情不闲聊 提交于 2019-12-10 18:49:08
问题 I want emacs to add last edit location to the mark ring, so I can jump back to previous edit locations. Ideally this would only mark one edit location per line. When I edit another line, the last edit location on that line would be added to the ring, and so forth. I'm not familiar with Lisp to implement this myself. If anyone knows of a plugin or can kindly provide a solution that would be great! :) 回答1: Session.el provides this functionality bound to "C-x C-/" or session-jump-to-last-change

How to set a key-binding to work in certain modes in emacs and not others

微笑、不失礼 提交于 2019-12-10 18:38:56
问题 I'm sorry if this is a stupid question but I've been searching on how to do this for hours. I want certain elisp functions to bind to specific key-bindings and for those key-bindings to call a function depending on the mode that the current buffer is in. I'll give an example. (defun sml-create-comment () "Documentation.." (interactive) (code-to-insert-comment)) I want this function to be binded to a key, for example 'C-c c'. If I was in sml-mode and typed 'C-c c' it would make an sml comment;

Creating a POST with url elisp package in emacs: utf-8 problem

*爱你&永不变心* 提交于 2019-12-10 15:19:13
问题 I'm currently creating a Rest client for making blog posts much in the spirit of pastie.el. The main objective is for me to write a textile in emacs and make a post to a Rails application that will create it. It is working fine until I type anything in either spanish or japanese, then I get a 500 error. pastie.el has this same problem also by the way. Here is the code: (require 'url) (defun create-post() (interactive) (let ((url-request-method "POST") (url-request-extra-headers '(("Content

What does ad-activate do?

扶醉桌前 提交于 2019-12-10 15:08:31
问题 In an answer, I noticed: ;; Align with spaces only (defadvice align-regexp (around align-regexp-with-spaces) "Never use tabs for alignment." (let ((indent-tabs-mode nil)) ad-do-it)) (ad-activate 'align-regexp) This sounds promising, but... what does it do?! I tried eval-region on the block of code. But for me, all it does is adding the following to the align-regexp docs: This function is advised. Around-advice `align-regexp-with-spaces': Never use tabs for alignment. I don't seem to be able

ido-mode binding masked by global-set-key

帅比萌擦擦* 提交于 2019-12-10 15:07:02
问题 stackoverflow! In the past few days I was trying to customize my emacs a little bit and I faced the problem that I don't know how to approach. What I'm trying to do is to define a global keybinding and an ido-mode keybinding that would use the same keys to do different things. Ido-mode keybinding is defined this way: (defun ido-my-keys () "Add my keybindings for ido." (define-key ido-completion-map (kbd "M-<return>") 'ido-invoke-in-vertical-split) ) (add-hook 'ido-setup-hook 'ido-my-keys) And

Elisp: Saving a position, inserting text before it, and returning to the same location

别等时光非礼了梦想. 提交于 2019-12-10 14:54:10
问题 I am currently working on an elisp function that moves to another location, executes a function, then returns to the position. My only problem is that if the function inserts text, the position that I saved is no longer where I want to be. For example, say I have the following string: Hello World And let's say I'm at the 'W' at position 6. And let's say I want to insert another "Hello" to the beginning like this: Hello Hello World The way I'm doing it now, I would store 6 in a variable,

Emacs Lisp: #s does not create a new hash table each time

余生长醉 提交于 2019-12-10 14:47:15
问题 I have the following function: (defun inc-map () (let ((ht #s(hash-table test contents-hash))) (dolist (i (list 1 2 3 4)) (let ((old-val (or (gethash "foo" ht) 0))) (puthash "foo" (+ 1 old-val) ht))) ht)) Despite the fact that this function seems to define the ht symbol locally, the function doesn't seem to be referentially transparent. In particular, calling it once returns the hash table "foo" -> 4 , calling it a second time returns "foo" -> 8 , a third time returns "foo" -> 12 and so on.