alchem0x2A / .emacs.d

My .emacs.d configuration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

.emacs.d my Emacs configuration settings

My .emacs.d configurations

Overview

Editor UI design

  • Use moe-theme for the color scheme

Mac-specified features to mimic a “modern” editor

See the section below

Global Mac-specific features

Maximize the use of ⌘ (super) key in Emacs according to personal behavior.

Server and client configurations

On top of out-of-box GNU Emacs.app in macOS, we use a server-client model for running GUI / terminal text editing. The following behavior is desired according to personal preferences:

  • The emacs server is alive within an active session of Emacs.app, i.e. the Emacs icon is shown in the dashboard.
  • Terminal editing of a file is done by a wrapped version of emacsclient. If the emacs server is not alive, activate the GUI Emacs.app
  • No launchctl process should be involved as the user could not have elevated privilege.

To do this, we require both settings on server and client sides:

Server side

  • When opening Emacs.app, the init.el script will automatically enable emacs server using (server-start).
  • The window close button only hides the application but not quitting it, making further client sessions doable. (Solution from: https://lists.gnu.org/archive/html/help-gnu-emacs/2016-01/msg00236.html)
  • REAL quitting is done by (save-buffers-kill-emacs) or ⌘+Q

Client side

On the client side, the desired behavior is run the text editor by simply as:

ec FILE_NAME1 FILE_NAME2 ...

where ec is a function wrapper of emacsclient that automatically determines if the server on Emacs.app has started.

The following snippet should be loaded by the .bash_profile or any related shell init scripts:

function ec_wrapper {
    GREEN='\033[0;32m'
    NC='\033[0m'
    buffers=$@
    cmd="emacsclient -nqc"
    # Excecute command
    $cmd $buffers &> /dev/null
    return_code=$?
    if (( $return_code != 0))
    then
        pid=$(pgrep -ai "emacs")
        # If emacs current running?
        if (( ${#pid} == 0 ))	# No pid returned
        then   # No emacs running, then open the GUI
            emacs --chdir $(pwd) $@ & &> /dev/null
            suc=$?
            return $suc
        else
            echo "There is a running Emacs instance but I can't find find the server."
            echo -e "Run ${GREEN}M-x server-start${NC} in Emacs to enable it."
        fi
    else
        return 0			# Success
    fi
}

alias ec=ec_wrapper

Window navigation

  • s-w: delete current window (no kill buffer). Equivalent to C-x 0
  • s-<left>: Move to the beginning of line
  • s-<right>: Move to the end of line
  • s-<up>: Move to beginning of buffer. Equivalent to <home> (Fn + Left on Mac keyboard)
  • s-<down>: Move to end of buffer. Equivalent to <end> (Fn + Right on Mac keyboard)
  • M-s-<up>: Move to upper window
  • M-s-<down>: Move to lower window
  • M-s-<left>: Move to left window
  • M-s-<right>: Move to right window

Undo / redo

The original undo/ redo functionalities of Emacs are fancy but also complicated when implementing redo. We use undo-tree mode to manage all the undo / redo history in Emacs.

The following key bindings are used by convention:

  • s-z: undo using undo-tree-undo
  • s-Z: redo using undo-tree-red

Note in the undo-tree mode, the key C-x u is binded to visualize the undo tree. I personally don’t prefer this approach and set C-x u to the usual undo binding defined by Emacs.

Delete behavior

The default behavior of “kill” in emacs is a fancy feature but not so appealing to users like me (coming from background of Sublime, XCode etc.) The annoying part of the default behavior comes for the following scenario:

  1. Copy some text from another buffer to the kill-ring
  2. Go to the buffer that you want to edit, delete the regions with keys like C-<backspace>, s-<backspace> etc.
  3. Now the last kill-ring becomes the text you deleted (killed) during step 2, and you have to go explicitly to the kill-ring to find out what needs to be pasted

This default behavior is avoided by explicitly invoking the delete functions (see settings/editor.el for details). In brief, the following key-bindings will not save the deleted region to kill-ring:

  • s-<backspace>: delete all contents of the line before the position. Will not greedily delete when invoking multiple times.
Maybe change to consecutive deleteEND
  • s-<kp-delete>: delete all contents of the line after the position. No greedy deletion.
  • C-<backspace>, M-<backspace>: backward delete a word or subword. When syntax-subword-mode is present, use the syntax-subword-forward method to locate subword; otherwise the normal subword-forward.
  • C-<kp-delete>, M-<kp-delete>: backward delete a word or subword.

Select and comment

Use convention from other text editors.

  • s-l: select current line
  • s-/: comment current line / region, enabled with Emacs version

>25.0

The usual key-binding M-; (comment-dwim) is used when you want to append some comment at the end of a line.

About

My .emacs.d configuration


Languages

Language:Emacs Lisp 99.6%Language:YASnippet 0.4%