elisp

show org-mode outline up to a certain heading level

痞子三分冷 提交于 2019-12-17 18:36:14
问题 I'm making an outline for my thesis using org-mode, and I'd like to show all headings up to a certain level (e.g. all level-1 and level-2 headings). I haven't found anything about that in the org-mode manual. Cycling shows either only level-1 headings, or all headings, which is too much information in my outline right now. Thanks, daniel. Update: I found a workaround for his: set the variable org-cycle-max-level. This is a global setting, though. 回答1: Just stumbled on this question. One year

Is there a (repeat-last-command) in Emacs?

寵の児 提交于 2019-12-17 17:19:30
问题 Frequently, I've dug into apropos and docs looking for something like the following only to give up to get back to the task at hand: (repeat-last-command) do the last C- or M- command I just executed (to be rebound to a fn key) or sometimes the related: (describe-last-function) what keystroke did I just mistakenly issue, the effect of which I'd like to add to my bag of tricks. describe-key is close, but requires knowing what I typed. Am I simply asking too much from my trusty sidekick? 回答1:

Distinguishing files with extensions, from hidden files and no extensions

旧城冷巷雨未停 提交于 2019-12-17 17:11:36
问题 I'm having difficulty distinguishing files with extensions, from files without extensions, and hidden files. I'm using (file-name-extension (dired-get-file-for-visit)) in dired-mode, and the type of file extension determines what action to take -- e.g., open in Emacs, or open externally with a particular application. A hidden file (e.g., .hidden ) returns a value of nil instead of "hidden" . A file with no extension (e.g., foo ) also returns a value of nil . Can anyone suggest an alternative

How do I pass a function as a parameter to in elisp?

别来无恙 提交于 2019-12-17 16:18:42
问题 I'm trying to pass one method to another in elisp, and then have that method execute it. Here is an example: (defun t1 () "t1") (defun t2 () "t1") (defun call-t (t) ; how do I execute "t"? (t)) ; How do I pass in method reference? (call-t 't1) 回答1: First, I'm not sure that naming your function t is helping as 't' is used as the truth value in lisp. That said, the following code works for me: (defun test-func-1 () "test-func-1" (interactive "*") (insert-string "testing callers")) (defun func

Eclipse-like Line Commenting in Emacs

南笙酒味 提交于 2019-12-17 16:10:05
问题 In Eclipse, highlighting multiple rows and pressing Ctrl+/ comments each of the lines of the selection. Emacs has a function comment-or-uncomment-region that is close what I want, but behaves differently if the region only partially covers the lines I'm trying to comment. Is there any way I make a function similar to comment-or-uncomment-region , but have it comment each of the lines of the region regardless of how the region is selected? In other words, I want the function to act as though

How do I set the size of Emacs' window?

半腔热情 提交于 2019-12-17 15:08:10
问题 I'm trying to detect the size of the screen I'm starting emacs on, and adjust the size and position the window it is starting in (I guess that's the frame in emacs-speak) accordingly. I'm trying to set up my .emacs so that I always get a "reasonably-big" window with it's top-left corner near the top-left of my screen. I guess this is a big ask for the general case, so to narrow things down a bit I'm most interested in GNU Emacs 22 on Windows and (Debian) Linux. 回答1: If you want to change the

Emacs shell scripts - how to put initial options into the script?

烂漫一生 提交于 2019-12-17 08:54:33
问题 Inspired by Stack Overflow question Idomatic batch processing of text in Emacs? I tried out an Emacs shell script with the following headline: #!/usr/bin/emacs --script I put some Emacs Lisp code in it, and saved it as textfile rcat. Since the --script option does not prevent the loading of the site-start file, I had a lot of Loading /etc/emacs/site-start.d/20apel.el (source)... Loading /etc/emacs23/site-start.d/35elib-startup.el (source)... Loading /etc/emacs23/site-start.d/50auctex.el

How do I do closures in Emacs Lisp?

我是研究僧i 提交于 2019-12-17 08:48:08
问题 I'm trying to create a function on the fly that would return one constant value. In JavaScript and other modern imperative languages I would use closures: function id(a) { return function() {return a;}; } but Emacs lisp doesn't support those. I can create mix of identity function and partial function application but it's not supported either. So how do I do that? 回答1: Stupid idea: how about: (defun foo (x) `(lambda () ,x)) (funcall (foo 10)) ;; => 10 回答2: Found another solution with lexical

eval-after-load vs. mode hook

让人想犯罪 __ 提交于 2019-12-17 07:04:29
问题 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. ;;

c++-mode-hook and c-mode-hook appears to run twice

﹥>﹥吖頭↗ 提交于 2019-12-14 02:46:08
问题 I use this command to start emacs $ emacs -Q c-mode-test.el then I use C-xC-e to eval every line (require 'cc-mode) (add-hook 'c-mode-common-hook '(lambda () (print "hello"))) (add-hook 'c-mode-hook '(lambda () (print "hello c"))) (c-mode) after this, the minibuffer shows "hello" "hello c" "hello c" nil and c++-mode-hook run just the same (add-hook 'c++-mode-hook '(lambda () (print "hello c++"))) (c++-mode) the minibuffer "hello" "hello c++" "hello c++" nil why it run twice or something wrong