• When you start emacs from a shell, emacs inherits shell’s environment variables. (true on Windows, Mac, Linux)
  • On Windows, when you start emacs from GUI, emacs also inherit environment variables, from the Registry.
  • On Mac OS X, when you start emacs from GUI, emacs does not inherit environment variables from your shell, but does inherit the system-wide environment variables from 〔~/.MacOSX/environment.plist〕.
  • On Mac OS X, you can start GUI emacs from shell, like this: nohup /Applications/Emacs.app/Contents/MacOS/Emacs &. This way, it’ll inherit shell’s environment variables.

Tags: Emacs

I want to be able to press a button, and have the current file executed or compiled. The file may be a Perl, Python, PHP, Bash, script, or Java code.

Tags: Emacs Lisp

Tags: Emacs

There are several shells for Emacs, but none can match the versatility and integration with Emacs like Eshell. Eshell is a shell written entirely in Emacs-Lisp, and it replicates most of the features and commands from GNU CoreUtils and the Bourne-like shells. So by re-writing common commands like ls and cp in Emacs-Lisp, Eshell will function identically on any environment Emacs itself runs on.

Unfortunately, there is a problem: Eshell is woefully underdocumented — a rare sight in GNU Emacs — so I’ve compiled this guide to help people make full use of what Eshell has to offer.

Tags: Emacs

most emacs major modes have “hooks” mechanism. It means, you can have emacs automatically run some code, whenever the mode is loaded.

Here’s a example:

(add-hook ‘org-mode-hook ‘soft-wrap-lines) ; make org-mode wrap long lines

(defun soft-wrap-lines ()
“Make lines wrap at window edge and on word boundary,
in current buffer.”
(interactive)
(setq truncate-lines nil)
(setq word-wrap t)
)

another example, adding some personal keys to a major mode.

(add-hook ‘org-mode-hook ‘xah-org-mode-keys)

(defun xah-org-mode-keys ()
“my keybindings for org-mode. For `org-mode-hook’.”
(local-set-key (kbd “<M-up>”) ‘org-metaup)
(local-set-key (kbd “<M-down>”) ‘org-metadown)
(local-set-key (kbd “<M-left>”) ‘org-metaleft)
(local-set-key (kbd “<M-right>”) ‘org-metaright)
)

typically, if a mode is named “xyz-mode”, its hook is usually named “xyz-mode-hook”. You can find out for sure by loading the mode first, then call “describe-variable” on the hook name. Or, call “describe-function” on “xyz-mode” and go to the code and do a “list-matching-lines” for the word “hook”.

to elisp, a hook is basically just a variable, pre-defined in a major mode. The value of this variable is a list of symbols (function names). When a major mode is loaded, emacs will run all the functions.

You can look at the value of a hook anytime by calling “describe-variable”.

now, whenever you want to remove some hooks, you can do this:

(remove-hook ‘org-mode-hook ‘soft-wrap-lines)

select the line, and call “eval-region”.

whenever you made changes to the hook, you usually need to reload the mode for it to be in effect. Fastest way is simply to re-open that file.

Tags: Emacs

This page shows you how to use emacs keyboard macro feature, with several examples of real world use.

Tags: Emacs

A better Dired mode

Tags: Emacs

Just for fun :D

Tags: Emacs

Emacs is a excellent tool for file management. For example, listing files, copy/delete files, rename files, moving files, creating/deleting directory. Once you become familiar with it, you almost never go back to shell or the OS desktop for these tasks.

Tags: Emacs

This page is a short, practical, tutorial of Emacs Lisp the language.

Tags: Emacs elisp