Skip to content
Seong-Kook Shin edited this page Feb 28, 2016 · 5 revisions

Welcome to the emacs-scripts wiki!

Here, I will explain my customization setup those are different from vanilla GNU emacs.

uinit

The more customization you put in your init file, the more Emacs took time in startup. Sometimes it takes more than 5 seconds in my personal experiences. This is mostly due to inappropriate usage of require. To measure the loading time, I wrote simple macro called init/load:

(init/load LISP-FILE BODY...)

If the last expression in BODY returns non-nil, then load LISP-FILE in $HOME/.emacs.d/init/. Then I put uinit/summarize in the end of the $HOME/.emacs.d/init.el, and it will create a buffer named *uinit* summarizing the time spent in each LISP-FILE. The buffer provides simple binding, C-n or n for next-line, C-p or p for previous-line, and <RET> for visiting the file in the point.

0.00084  [okay] /Users/cinsk/.emacs.d/init/maven
0.00096  [okay] /Users/cinsk/.emacs.d/init/delete
0.00122  [okay] /Users/cinsk/.emacs.d/init/_latex
0.00175  [okay] /Users/cinsk/.emacs.d/init/_nxml
...
0.00201  [okay] /Users/cinsk/.emacs.d/init/_clojure
0.55762  [okay] /Users/cinsk/.emacs.d/init/_org
0.59261  [okay] /Users/cinsk/.emacs.d/init/darwin
1.34193  [okay] /Users/cinsk/.emacs.d/init/ruby
--
4.88828  TOTAL

Mode specific

org

Word joiner

In a language like Korean, we do have a grammar named 'postposition' (or postposition particle). For example, the statement "=ls= lists directory contents." translated to "=ls=는 디렉토리 내용을 나열합니다." Note that "=xxxx=" form is to use verbatim font. Due to the nature of org translate mark-ups, "=ls=" will be use verbatim font, but not "=ls=는". The thing is, org cannot handle markup if the non-space character is followed by ending '='. To overcome this, I added the word joiner character in org-emphasis-regexp-components in _org.el. The word joiner character has zero-width space which implies no line break on its position. C-c C-; can insert the word joiner at point. To solve the previous problem, type = l s = C-c C-l 는. It looks exactly "=ls=는", but org can properly handle the verbatim markup.

Zero Width Space

In org mode, you cannot make verbatim markup for something like ="hello"=. To markup this, you need to insert Unicode zero width space character in the string so that it will be =<!>"hello"<!>= where <!> represents the zero width space character. You can insert it with C-c C-'.

insert links

To insert links to the reference (e.g. manual pages, Javadoc APIs, RFC document, etc.), consider to use `C-c C-l'. You can insert a conventional web URL, or, you may insert special links like:

man:printf(3)
java:java.lang.String
rfc:7230

For your information, links in org is expressed "[[link][description]]". If you insert a link like above, org will automatically insert followings:

[[man:printf(3)][printf]]          # http://man7.org/linux/man-pages/man3/printf.3.html
[[java:java.lang.String][String]]  # http://docs.oracle.com/javase/8/docs/api/java/lang/String.html
[[rfc:7230][RFC 7230]]             # http://www.rfc-editor.org/rfc/rfc7230.txt

If you stroke C-c C-o on those links, it will launch a web browser with URLs in above comment.

sourcefy

C-c s or M-x cinsk/org-sourcefy will enclose the current region as #BEGIN_SRC ... #END_SRC. It also provides completion for the major mode of the source block.

If you want to insert line numbers on the region, call C-c n or M-x line-numbers-on-region.

export to HTML.

If you export your org file in HTML, you'll automatically enabled mathjax. See the demo here.

Bootstrap CSS is automatically enabled.

cc mode

  • In c-mode, and c++-mode, abbrev-mode will be enabled.
  • M-F, M-B, M-D works similarly to M-f, M-b, M-d except in subword unit/
  • M-{ and M-} bound to c-beginning-of-defun, and c-end-of-defun respectively.
  • C-M-{ and C-M-} are bound to c-up-conditional-with-else and c-down-conditional-with-else.
  • c-warn-mode is automatically enabled.
  • C-x C-e always asks for the argument to the cpp. Convenient to insert arguments like -I..
  • In a linux source files, enable "K&R" style.

hungry delete

C-c C-d or M-x delete-chars-forward-with-syntax will delete all characters from point until a character with different syntax element appears. This will be very convenient, for example, if you want to delete all whitespaces until next non-whitespace characters.

ediff

The official ediff provides so called wide display (m key), that modify the frame wide temporarily for the ediff session. The idea is great, however, somewhat inconvenient. It only update the width frame parameter, so that the resulting frame may not fit to the desktop screen.

My tweak is, calculate the desired window/frame width for the ediff window (little bit better than vanilla's), and move the frame's left if the resulting frame will not fit to the desktop screen. There is a variable, cinsk/ediff-wide-display-policy to control the movement policy. It's value should be one of left, right, center, maximize, or fullscreen. First three policy governs the position of left frame parameters. If the policy is left, then it will try to preserve the left frame parameter as best as it could. The rest two policies, maximize and fullscreen calls toggle-frame-maximized and toggle-frame-fullscreen respectively.

If you're using desktop computer with more than two monitors with one logical desktop display, left will be probably best choice. If you're using Mac with/without the external monitors, either maximize or fullscreen may suit you better.

Home brewed modules

vc-dirx

vc-dirx provides vc/dir, a convenient alternative to vc-dir.

I've been using lots of version control system, Clearcase (ek!), CVS, Subversion, Bitkeeper, now GIT. Although Emacs provide /vc/ package, there are many rich alternatives, pcvs (now it's built in to vanilla version), and magit (excellent GIT frontend). My favorites are pcvs for CVS, and magit for GIT. Even though the entry point of those functions are different, I do want to use single entry point shortcut for raising entry point command similar to vc-dir.

(defvar vc/dir-function-alist
  '((Git . (vc/magit-status egg-status git-status))
    (SVN . svn-status)
    (CVS . vc/cvs-status))
  "association list for (VC-SYSTEM . DIR-FUNCTIONS)")

Here, for example, if the current buffer belongs to the GIT repository, vc/magit-status will be called if available. If not, egg-status will be called, otherwise git-status will be called. If none of those works, then vc-dir is called.

I already bound vc/dir to f12 key like this:

(when (locate-library "vc-dirx")
  (global-set-key [f12] 'vc/dir)
  (global-set-key [(control ?x) ?j] 'vc/dir))

sunrise commander

Admittedly, I do not use sunrise commander a lot. However, if I were dealing with lots of file operations, I would definitely use sunrise commander. If you don't know the sunrise commander, it's a file manager very similar to the midnight commander. Here are some of customization that I made:

Sunrise commander requires wide windows. You'll need about 160-character-wide window if you want to feel comfortable. Since I usually stick to 80-character-wide window, it is very inconvenient to switch to 160-width from 80-width or vice versa.

My idea was, when I entry the sunrise commander, I want to wide the current frame to launch the sunrise commander. And, if I am to quit, I want the current frame to back to the my previous setting, normally 80-character-width. In addition to this, when widening the current frame, I do not want to move the frame coordinate unless the widen frame does not fit to the display system. For these requirements, I already bound helper functions to sr-init-hook and sr-quit-hook.

Another thing is, I usually uses two monitors (in one huge display mode), and have several Emacs frames. So it's natural that I want to visit a file from Sunrise commander to another frame, not the same frame that Sunrise commander resides. See _sunrise.el for this setup. In addition to this, in a file visiting frame, if you run sunrise-cd-frame (which already bound to C-c C-j), you'll back to the frame that Sunrise resides.

shell

I'm trying to use eshell intentionally, however, some complicated command-line won't run in eshell. Perhaps I did not provide the command with proper eshell syntax, but I don't have enough time and memory to fix them.

  • C-c d will invoke M-x shell.
  • *shell* buffer will be the login shell. (easy to test .profile or .bash_profile)
  • *shell* will aware of UTF-8 encoding. (Perhaps it's okay in recent Emacs without this.)
  • *shell* will support ANSI colors
  • C-M-? will invoke eshell and move to the directory of the current buffer.

mail

I've already set up Emacs for sending mails using my Google account. Feel free to read mail.el. If you want to use M-x mail using your Google account, create $HOME/.authinfo looks like this:

machine imap.gmail.com login [email protected] password PASSWORD port 993
machine smtp.gmail.com login [email protected] password PASSWORD port 587

Make sure that .authinfo has the access mode, 600.

Korean

I am using 3-bul-sik keyboard layout to type Korean. Feel free to read korean.el.

Fonts

I create simple key bindings to zoom in/out the current font size using the mouse wheel in fontutil.el. C-wheel-up will increase the fontsize by 1.1 factor (110%), and C-wheel-down will decrease the font size by 0.9 (90%).

There are some known problems on CJKV glyph handling on current Emacs. The thing is, characters of CJKV are wider than latin-based alphabets, and most of them are fixed width. Tranditionally, it's best that the CJKV glyphs have exactly double width of fixed latin glyphs. Unfortunately, most of the font providers ignore this fact, so that CJKV glyphs does not have double width. Worse, some of CJKV fonts have very poor latin glyphs, so most CJKV people are accustomed to use two fonts; one for CJKV, and another for the latin glyphs. I have selected some of pairs so that the Korean font width can be exactly double width of the latin font. Look fontutil.el You may call M-x font/set-font to select one of those pre-selected fontset. Do not worry if some of fonts are unavailable in your system, since font/remove-unavailable will automatically delete unavailable fontset.

dwim-compile

M-x compile uses default-directory of the current buffer to execute a build command of user's choice. If the build tool (e.g. make, sbt, gradle, maven, etc.) requires that it should be executed in a project root directory, you will need to pass a build command to M-x compile something like this, cd $PROJECT-ROOT; make. This can be very inconvenient if the project's directory hierarchy is somewhat deep.

dwim-c/compile in dwim-compile.el is bound to C-c c and it provides several enhancements over compile:

  • to provide a default command-line per major mode of the current buffer.
  • to update default-directory based on the project's build tool configuration file.
  • to execute build tool specific Emacs command
  • to select one build tool if multiple configurations are detected.

For example, if you have a gradle project in /home/cinsk/src/myproject, then it will have a file named build.gradle there. Assuming that the current buffer is editing /home/cinsk/src/myproject/src/main/java/hello/heelo.java, then if you want to run gradle build, then, you'll need to provide something like cd ~/src/myproject; gradle build. With dwim-c/compile, you just need to stroke C-c c.

capitalize+

If you're editing a source buffer with camel case, which I hate, you have my sympathy by the way. Anyway, one problem of camel case is, it is very difficult to type fast and it is very easy to type with wrong case. For example, I typed "Springapplication" where "SpringApplication" needed. Or, I typed "setOutputstream" where "setOutputStream" needed.

Emacs provides capitalize-word, but it was not helping much. So I bound M-c to capitalize-word+, which I define in capitalize+.el.

Suppose you typed "setoutputstream", and the point is in the middle of the word. Pressing M-c several times may give you one of these:

Setoutputstream
setOutputStream
SETOUTPUTSTREAM
setoutputstream

Converting the first character to capital letter, and converting all to capital or lower case are easy. The difficult one is, how to produce something like "setOutputStream". There are many implementations that can provide this. Analyzing the word for the phonetic component cannot help abbreviations like "setHTTPVersion". One of the not-perfect, but reasonable solution will be, searching all buffers for that word, and use the case of that buffer. If there are multiple choices, then capitalize-word+ will give the next choices from the current one.