elisp

emacs lisp, how to get buffer major mode?

拥有回忆 提交于 2019-11-27 05:18:07
问题 I have tried to search Google and look in the manual, but still cannot find how to get major mode of a buffer object. Can you help me with an example or a reference. Thanks only solution I could find was to query major-mode after changing the buffer and then changing back to original buffer. Is there a better way to do it? 回答1: Is there a problem with that? (defun buffer-mode (buffer-or-string) "Returns the major mode associated with a buffer." (with-current-buffer buffer-or-string major-mode

Emacs key binding fallback

岁酱吖の 提交于 2019-11-27 04:41:37
问题 I have a minor mode. If that mode is active and the user hits DEL, I want to do some action, but only if some condition holds. If the condition holds and the action is executed I want to do nothing more after that. But if the condition fails, I don't want to do anything and let the default DEL action execute. Not sure how I could solve this. But I guess I could do it in two ways: 1) I could rebind the DEL key to a function in the minor mode and then check if the conditions holds ot not. But

Using tramp with EmacsW32 and cygwin, possible?

徘徊边缘 提交于 2019-11-27 04:41:23
I have some trouble setting up Tramp with EmacsW32 and cygwin. I have configured emacs to use cygwin as shell using w32shell. I also set the HOME enviromental variable to c:/cygwin/home/myusername Problem is that tramp seems to hang and that no connection is made: "Tramp waiting for prompts for the new shell". I have tried to turn on debugging, but still only see this message. Looking forward to get some tips on this. Thank you. Take note of the cygwin-related information on the emacs wiki: http://www.emacswiki.org/emacs/TrampMode I don't use EmacsW32, but I do successfully use TRAMP over ssh

When should Emacs #'function syntax be used?

ε祈祈猫儿з 提交于 2019-11-27 04:11:55
Basically, when should I use Emacs Lisp's function procedure? I haven't found any examples in which there's a difference in behavior if you pass functions as arguments 'like-this or #'like-this . In fact, if I evaluate (eq 'goto-char #'goto-char) it returns t . The Emacs Lisp code that I've come across rarely uses function / #' ; the authors just quote / ' everything. Example: (add-hook 'emacs-lisp-hook 'turn-on-eldoc-mode) However, I can find a few counterexamples. Here's one from the source code of Emacs 24.3's electric.el : (add-hook 'post-self-insert-hook #'electric-indent-post-self-insert

Maximize Emacs on start up? (not the fullscreen)

冷暖自知 提交于 2019-11-27 03:53:43
问题 It's common for me to press alt-f10 (in GNU/Linux) after Emacs start up for maximizing window (in the Emacs terminology, it's actually a frame). Most of the time I press thrice because I was too early to press first alt-f10 which makes some garbage appear around the minibuffer (Emacs display bug?) How can I automate this one? (Maybe with Gnome settings or with elisp?) I am using emacs24 (from bzr repo). Note that it's not the regular fullscreen I want which you would get by pressing f11. 回答1:

File extension hook in Emacs

北城余情 提交于 2019-11-27 03:49:05
问题 I'd like to run a hook for specific file extensions (i.e. not modes). I have zero experience with elisp, so I cargo-cult coded this: (defun set_tab_mode () (when (looking-at-p "\\.cat") (insert "OK") (orgtbl-mode))) (add-hook 'find-file-hook 'set_tab_mode) (Should set orgtbl minor mode for files with suffix .cat and insert text "OK", i.e. it's not only a mode setting question). Unfortunately it does not work. 回答1: Try this: (defun my-set-tab-mode () (when (and (stringp buffer-file-name)

lisp filter out results from list not matching predicate

删除回忆录丶 提交于 2019-11-27 03:43:27
问题 I am trying to learn lisp, using emacs dialect and I have a question. let us say list has some members, for which predicate evaluates to false. how do I create a new list without those members? something like { A in L: p(A) is true } . in python there is filter function, is there something equivalent in lisp? if not, how do I do it? Thanks 回答1: These functions are in the CL package, you will need to (require 'cl) to use them: (remove-if-not #'evenp '(1 2 3 4 5)) This will return a new list

in org-mode, how to fold/hide footnotes?

北城余情 提交于 2019-11-27 03:36:17
问题 In Emacs org-mode, is there a way to get inline footnote definitions to appear as collapsed? So that for instance, a line like this: This effect is due to the strength of weak ties[fn:: Newman, Mark, Albert-László Barabási, and Duncan J. Watts. 2006. The Structure and Dynamics of Networks. Princeton, NJ: Princeton University Press]. might simply appear like this: This effect is due to the strength of weak ties[✭]. I would also need a command to show the footnotes when necessary. So maybe what

Elisp: Conditionally change keybinding

南笙酒味 提交于 2019-11-27 03:33:12
问题 I'm trying to write a custom tab completion implementation which tries a bunch of different completions depending on where the point is. However, if none of the conditions for completions are met I would like tab to do what ever the current mode originally intended it to do. Something like this: (defun my-custom-tab-completion () (interactive) (cond (some-condition (do-something)) (some-other-condition (do-something-else)) (t (do-whatever-tab-is-supposed-to-do-in-the-current-mode))) ;; How do

eval-after-load vs. mode hook

我与影子孤独终老i 提交于 2019-11-27 02:52:10
Is there a difference between setting things for a mode using eval-after-load and using the mode hook? I've seen some code where define-key is used inside a major mode hook, and some other code where define-key is used in eval-after-load form. Update: For better understanding, here is an example of using eval-after-load and mode hooks with org-mode. The code can run before (load "org") or (require 'org) or (package-initialize) . ;; The following two lines of code set some org-mode options. ;; Usually, these can be outside (eval-after-load ...) and work. ;; In cases that doesn't work, try using