elisp

Emacs Per File Customization

梦想的初衷 提交于 2019-12-20 10:55:10
问题 I have an Emacs Lisp file with custom macros I want fontified and indented differently. The code looks like: (defmacro* when-let ((var value) &rest body) `(let ((,var ,value)) (when ,var ,@body))) (defun func () (when-let (a 1) a)) I want when-let fontified as a font-lock-keyword and indented as above. I know I can do this in my .emacs file but I'd prefer to make it a directory local or file local customization. The problem is that directory local and file local customizations seem to be

Walk up the directory tree

China☆狼群 提交于 2019-12-20 10:38:27
问题 The file tree is as follwing: - foo - lorem - ipsum <- - baz <- - bar - baz The currently visited file is ipsum . Now I want to find the first baz and the directory it is in. How do I walk up the tree from ipsum in elisp? 回答1: You want locate-dominating-file . 回答2: (defun parent-directory (dir) (unless (equal "/" dir) (file-name-directory (directory-file-name dir)))) (defun find-file-in-heirarchy (current-dir fname) "Search for a file named FNAME upwards through the directory hierarchy,

Improved tab in Emacs

折月煮酒 提交于 2019-12-20 10:27:13
问题 I want to override the bad default tabbing scheme in emacs so that it will work like most other editors (eclipse, notepad++). I want to set it so that regardless of mode, tab will insert a tab, and pressing enter will keep me at my current tab depth. I tried this, but it does nothing: (global-set-key (kbd "TAB") 'tab-to-tab-stop) (setq default-tab-width 4) ;; 8 is way too many 回答1: To make the Enter key take you to the next line and indent it automatically, you can put (global-set-key (kbd

Emacs lisp “shell-command-on-region”

旧巷老猫 提交于 2019-12-20 10:25:34
问题 In GNU Emacs, I want to run a program, figlet, on the currently selected text. I then want to comment the region which is produced. I have figured out how to do it using the standard Emacs commands: set mark with C-<space> at the start of the word move cursor to the end of the word C-u M-x shell-command-on-region RET figlet RET M-x comment-region RET However, I have failed to work out how to write an Emacs lisp program to do all this. Here is my attempt: (defun figlet-region () (interactive)

Sync Emacs AUCTeX with Sumatra PDF

江枫思渺然 提交于 2019-12-20 09:47:29
问题 With these lines in my init.el I am able to sync the Emacs LaTeX buffer with Sumatra: (setq TeX-source-correlate-mode t) (setq TeX-source-correlate-method 'synctex) (setq TeX-view-program-list '(("Sumatra PDF" ("\"C:/bin86/SumatraPDF/SumatraPDF.exe\" -reuse-instance" (mode-io-correlate " -forward-search %b %n ") " %o")))) (setq TeX-view-program-selection '(((output-dvi style-pstricks) "dvips and start") (output-dvi "Yap") (output-pdf "Sumatra PDF") (output-html "start"))) To set a double

maintaining multiple emacs configurations at the same time

二次信任 提交于 2019-12-20 09:38:33
问题 I want to maintain multiple emacs configurations like emacs-prelude, emacs-starter-kit, and my own custom emacs configuration simultaneously on same user account on same pc. for that i have setup directories like .emacs1.d, .emacs2.d, .emacs3.d. Each emacs user directory has a init.el file that should be loaded on startup. Instead of .emacs file i prefer using init.el file. How do i load these custom config directories? I tried running emacs --eval '(setq user-emacs-directory "~/.emacs1.d/")'

How to automatically do org-mobile-push org-mobile pull in emacs

筅森魡賤 提交于 2019-12-20 09:17:42
问题 Since I am using org-mode to track my todo list in emacs, I like the iPhone app: MobileOrg, with it, I can access my todo list all day. But here's the problem: I have to manually org-mobile-push my changes from local file to mobile phone through dropbox, and org-mobile-pull the changes made by phone back. How to make that automatically? Like adding some recipes in dotemacs file. 回答1: Add these two lines to dot emacs file: (add-hook 'after-init-hook 'org-mobile-pull) (add-hook 'kill-emacs-hook

Emacs: automatically replace LaTeX to Unicode symbols

扶醉桌前 提交于 2019-12-20 09:02:23
问题 In Emacs I frequently use math symbols when I write my theory summaries of math textbooks. I use org-mode to structure information and I know about at least two methods of entering special symbols: Using embedded LaTeX: enter its representation in the form \land then press C-c C-x \ ( org-toggle-pretty-entities ) to view it literally; Using C-x 8 RET ( insert-char ). I want it however to behave the following way: I enter the LaTeX representation, and it is automatically converted into the

emacs mode-specific custom key bindings: local-set-key vs define-key

时光怂恿深爱的人放手 提交于 2019-12-20 08:59:39
问题 After a few years customizing my .emacs file, I find I used two different kinds of constructs to setup major-mode-specific key bindings: 1. using a hook and local-set-key . For example: (defun my/bindkey-recompile () "Bind <F5> to `recompile'." (local-set-key (kbd "<f5>") 'recompile)) (add-hook 'c-mode-common-hook 'my/bindkey-recompile) I would say this construct makes it easy to use the same key bindings for different major-modes by adding the same function to all relevant major-mode hooks

How to determine operating system in elisp?

和自甴很熟 提交于 2019-12-20 08:31:09
问题 How do I programmatically determine which OS Emacs is running under in ELisp? I would like to run different code in .emacs depending on the OS. 回答1: The system-type variable: system-type is a variable defined in `C source code'. Its value is darwin Documentation: Value is symbol indicating type of operating system you are using. Special values: `gnu' compiled for a GNU Hurd system. `gnu/linux' compiled for a GNU/Linux system. `darwin' compiled for Darwin (GNU-Darwin, Mac OS X, ...). `ms-dos'