elisp

Update multi-term buffer name based on PWD

烈酒焚心 提交于 2019-12-19 10:32:24
问题 If I use konsole or other terminal, the terminal tag name can change based on PWD. But in multi-term, the buffer name is *terminal<number>* . This is not very nice. Because when I switch between them, the name is not very informative. So I want to rename it based on PWD. I find that the Enter key is bind to term-send-raw, so I write a function (defadvice term-send-raw (around rename-term-name activate) (progn (rename-buffer (concat "⇒ " (shell-command-to-string "pwd | xargs basename | tr -d '

Emacs Lisp: How to use interactive (for conditional arguments)?

怎甘沉沦 提交于 2019-12-19 09:22:11
问题 I want to ask a second question to the user depending on the answer to the first one. (defun something (a b) (interactive (list (read-number "First num: ") (read-number "Second num: "))) (message "a is %s and b is %s" a b)) So I need a way to test the entry values : (defun something-else (a &optional b) (interactive (list (read-number "First num: ") (if (< a 2) (read-number "Second num: ")))) (message "a is %s" a)) But if: Symbol's value as variable is void: a Question : How can I use

How does emacs url package handle authentication?

限于喜欢 提交于 2019-12-19 09:12:53
问题 I have not seen a really good example on the web. How can I add authentication to a request like this: (defun login-show-posts () (interactive) (let ((url-request-method "GET") (url-request-extra-headers '(("Content-Type" . "application/xml")))) (url-retrieve "http://localhost:3000/essay/1.xml" (lambda (status) (switch-to-buffer (current-buffer)) )))) if for example, the user and pass is admin:admin? 回答1: I got the impression that url.el was designed mostly for interactive operations, i.e.

Formatting a header in an Emacs function to print a buffer to PDF w/ line wrapping

女生的网名这么多〃 提交于 2019-12-19 08:56:30
问题 Rupert Swarbrick came up with the following three functions to print an Emacs buffer to pdf in which lines are wrapped (this is not normally the case when using ps-print* functions). The problem is this function is that to achieve this line wrapping, a copy of the current buffer has to be made. This effectively breaks the capability of ps-print-buffer-with-faces to display a correct header on top of each page in the resulting PDF file. As part of his solution, Rupert Swarbrick wrote a

Is there a way to obtain the function name of current function?

∥☆過路亽.° 提交于 2019-12-19 07:28:33
问题 (defun foo () (send-to-debug-log "Error. Function terminated." (get-current-function-name))) I currently do this: (defun foo () (send-to-debug-log "Error. Function terminated." 'foo))) Hard coding the function name seems not to be a good practice. Any suggestion to implement the get-current-function-name or get-function-name-that-call-me . 回答1: (defun foo () (send-to-debug-log "Error. Function terminated." (nth 1 (backtrace-frame 2)))) 回答2: With the package which-function-mode (in melpa), you

How to redefine a key inside a “minibuffer” mode-map?

戏子无情 提交于 2019-12-19 07:11:29
问题 I'm trying to redefine the keys used to navigate the history when inside several commands accepting regexps and offering C-p / C-n history navigation. I'd like to use other keys, in addition to C-p / C-n. For example when using occur or replace-regexp , C-p and C-n can be used to go to previous and next elements. I've tried several things but can't make it work. I think I'm missing the "big picture" here. Which mode-map do I need to modify, when and how? Everything I tried failed. P.S: Note

How do I delete the newline from a process output?

别说谁变了你拦得住时间么 提交于 2019-12-19 05:13:36
问题 I call git get the toplevel dir (according to Is there a way to get the git root directory in one command? ). (let ((tmpbuffer (get-buffer-create (make-temp-name "git")))) (call-process "git" nil tmpbuffer nil "rev-parse" "--show-toplevel") (with-current-buffer tmpbuffer (with-output-to-string (princ (buffer-string)) (kill-buffer)))) But there's a trailing newline in the string returned. I'm not sure how to get rid of it. 回答1: I think you can do (replace-regexp-in-string "\n$" "" (shell

I can't find this: How do I use 4 SPACES instead of a TAB in EMACS?

爷,独闯天下 提交于 2019-12-19 03:24:09
问题 I am making the jump to EMACS, and I can't find what I need to do in my .emacs file to get php-mode AND all other modes to insert 4 spaces instead of a TAB. Help? UPDATE: When I hit tab I still get 8 spaces in a plain file with the given answers. In php-mode I still get 2 spaces. Hitting tab in php mode does nothing, tab in regular EMACS adds 8 spaces. UPDATE2: This is what I have in my .emacs : (require 'color-theme) (color-theme-calm-forest) (setq-default indent-tabs-mode nil) (setq-default

Emacs M-x commands for invoking “GUI-style” menus

人走茶凉 提交于 2019-12-18 21:29:10
问题 Question: How could I find out the M-x equivalent commands for doing GUI-based operations in Emacs, in those cases where my Emacs-variant uses OS-specific desktop functionality? Background: Conventional understanding states that everything in Emacs is a command, and that commands can be invoked via M-x, as long as you know the name of the command. Assuming this statement is correct, what is the way to find the name of the commands used to trigger the "GUI-style" menus in a "desktop" based

Make Emacs less aggressive about indentation

╄→尐↘猪︶ㄣ 提交于 2019-12-18 17:14:27
问题 Emacs reindents the current line whenever I type certain things, like ";" or "//". This is pretty annoying, since there are a whole lot of places where it isn't smart enough to indent correctly. How do I disable this feature? I still want to be able to indent the line with TAB, but I don't want any source code I type to cause it to reindent. (I'm using Dylan Moonfire's C# mode, but this probably applies to any cc-mode.) 回答1: Try running c-toggle-electric-state to turn off the electric action