My Emacs Configuration

Good emacs configuration

Good articles

Emacs on Windows10

Set terminal in Windows10 (for GitBash and msys2)

  • refs

  • Edit .bash_profile in home directory:

    alias ll="ls -la"
    alias ls='ls --color'
    
    ##############
    ### Basics ###
    ##############
    
    # Don't wait for job termination notification
    set -o notify
    
    # Enables UTF-8 in Putty.
    # See http://www.earth.li/~huggie/blog/tech/mobile/putty-utf-8-trick.html
    echo -ne '\e%G\e[?47h\e%G\e[?47l'
    
    # My pretty prompt (Yay!)
    PS1='\[\e[32;40m\]\u\[\e[0m\]\[\e[34;40m\]\H\[\e[0m\]\[\e[40;1m\]\w\[\e[0m\] '
    
    # Start SSH Agent
    #----------------------------
    
    SSH_ENV="$HOME/.ssh/environment"
    
    function run_ssh_env {
      . "${SSH_ENV}" > /dev/null
    }
    
    function start_ssh_agent {
      echo "Initializing new SSH agent..."
      ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
      echo "succeeded"
      chmod 600 "${SSH_ENV}"
    
      run_ssh_env;
    
      ssh-add ~/.ssh/id_rsa;
    }
    
    if [ -f "${SSH_ENV}" ]; then
      run_ssh_env;
      ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
        start_ssh_agent;
      }
    else
      start_ssh_agent;
    fi
    
    • To generate ssh-key pairs

      ssh-keygen -t rsa -C "hyperion_z@outlook.com"
      
  • After installing git for windows (it also contains ssh), configure git global info

    git config --global user.name "zwpdbh"
    git config --global user.email "hyperion_z@outlook.com"
    
    # To set repository-specific username/email configuration:
    # 1. From the command line, change into the repository directory.
    # 2. git config user.name "FIRST_NAME LAST_NAME"
    # 3. git config user.email "MY_NAME@example.com"
    # 4. Verify it: cat .git/config
    

Install Emacs

  • Install Emacs from Index of /gnu/emacs/pretest/windows
  • Edit system environment variables for Windows10
    • add “C:\Program Files\Emacs\x86_64\bin” into path variable
  • Now, you should run emacs & from gitbash.

(optional) Emacs in WSL

  • ref: https://github.com/hubisan/emacs-wsl

  • enable ssh

    • edit /etc/ssh/sshd_config
      • change PassworldAuthentication to yes
      • change connection port from 22 to 2222
    • restart sshd
      • service ssh status check sshd status
      • sudo service ssh --full-restart
        • If you meet error: sshd: no hostkeys available – exiting. Run: /usr/bin/ssh-keygen -A
    • In case meet error: “could not load host key”
      • run ssh-keygen -A
    • Automatically start ssh server on boot on Windows Subsystem for Linux
  • use MobaXterm to connect

    • address: 127.0.0.1
    • port: 2222
  • make emacsclient use our defined emacs theme, edit ~/.bashrc

    # set a fancy prompt (non-color, unless we know we "want" color)
    # case "$TERM" in
    #     xterm-color|*-256color) color_prompt=yes;;
    # esac
    export TERM=xterm-256color
    
  • To start emacs without GUI, run emacs -nw

  • Blurry problem for Emacs GUi via MobaXterm

    • right click mobaxterm executable or shortcut
    • change high DPI settings
    • in section High DPI scaling override
    • select application from dropdown list
  • Avoid Git username and password

  • Use native browser in Windows10

    • Delete ubuntu firefox: sudo apt remove firefox.
  • sometimes, you need to run docker inside WSL, see: setting up docker for windows and wsl

    • Install and run docker desktop for windows10 (as server)

    • Add the following setting

      ### for let linux system use remote, our pc docker server
      export DOCKER_HOST=tcp://localhost:2375
      export DOCKER_HOST=tcp://127.0.0.1:2375
      

(optional) Emacs in msys2

pacman -Syu

pacman -Su base-devel
pacman -Su mingw-w64-x86_64-toolchain
pacman -Su mingw-w64-x86_64-gcc
pacman -Su mingw-w64-x86_64-cmake
pacman -Su make

# install Emacs dependencies
pacman -Su mingw-w64-x86_64-ctags mingw-w64-x86_64-zlib mingw-w64-x86_64-xpm-nox mingw-w64-x86_64-gnutls mingw-w64-x86_64-libwinpthread

# install Emacs optional dependencies
pacman -Su mingw-w64-x86_64-giflib mingw-w64-x86_64-libjpeg-turbo mingw-w64-x86_64-libpng mingw-w64-x86_64-librsvg mingw-w64-x86_64-libtiff mingw-w64-x86_64-imagemagick mingw-w64-x86_64-libxml2 mingw-w64-x86_64-librsvg mingw-w64-x86_64-graphviz

# install Emacs
pacman -Su mingw-w64-x86_64-emacs

Emacs on Mac OSX

Indentation for Lisp and Elisp

Terminal setup

Emacs in Microsoft Windows

Set terminal env

# for WSL, running docker
# see: https://nickjanetakis.com/blog/setting-up-docker-for-windows-and-wsl-to-work-flawlessly
export PATH="$PATH:$HOME/.local/bin"

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/.local/bin" ] ; then
    PATH="$HOME/.local/bin:$PATH"
fi



### set my terminial configuration
alias ll="ls -la"
alias ls='ls --color'

# export TERM=xterm-color
export TERM=xterm-256color
export GREP_OPTIONS='--color=auto' GREP_COLOR='1;32'
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad

export COLOR_NC='\e[0m' # No Color
export COLOR_WHITE='\e[1;37m'
export COLOR_BLACK='\e[0;30m'
export COLOR_BLUE='\e[0;34m'
export COLOR_LIGHT_BLUE='\e[1;34m'
export COLOR_GREEN='\e[0;32m'
export COLOR_LIGHT_GREEN='\e[1;32m'
export COLOR_CYAN='\e[0;36m'
export COLOR_LIGHT_CYAN='\e[1;36m'
export COLOR_RED='\e[0;31m'
export COLOR_LIGHT_RED='\e[1;31m'
export COLOR_PURPLE='\e[0;35m'
export COLOR_LIGHT_PURPLE='\e[1;35m'
export COLOR_BROWN='\e[0;33m'
export COLOR_YELLOW='\e[1;33m'
export COLOR_GRAY='\e[0;30m'
export COLOR_LIGHT_GRAY='\e[0;37m'
### end of terminal configuration

### for let linux system use remote, our pc docker server
export DOCKER_HOST=tcp://localhost:2375
export DOCKER_HOST=tcp://127.0.0.1:2375

### setup path for go
export PATH=$PATH:/usr/local/go/bin
  • add the above content into ~/.bashrc

Setup zsh

Font

Latex

DONE Render LaTeX fragments in Org-mode

DOING Org-babel

R

JavaScript

Org

Use emacs to create blog sites

Examples of website created from Emacs’s org-mode

Different staitc site generators with org

Org-mode to GitHub pages with Jekyll

Org file to blog using: Hugo, ox-hugo and Netlify

Troubleshootings

Keybindings behave different from GUI in pure text terminal

Copy and Paste from clipboard

Font is not set in terminal

  • In terminal, font is controlled by the terminal app. So, go to the terminal app’s option and change it to use installed font.

Error loading autoloads: (epg-error no usable configuration OpenPGP)

  • Emacs’ version: Emacs26.3 in MSYS2
  • reproduce this error: Meta-x epa-list-keys
  • solution

Apt install error: ument

  • description
    • When try to fix it with sudo apt install -f, following errors show up

      dpkg: error processing archive /var/cache/apt/archives/emacs25-common_25.3~2.gitc09215a-kk1+18.04_all.deb (--unpack):
       trying to overwrite '/usr/share/emacs/site-lisp/subdirs.el', which is also in package emacs26-common 26.3~1.git96dd019-kk1+18.04
      dpkg-deb: error: paste subprocess was killed by signal (Broken pipe)
      Errors were encountered while processing:
       /var/cache/apt/archives/emacs25-common_25.3~2.gitc09215a-kk1+18.04_all.deb
      
  • Solution

Cannot open load file: No such file or directories, adaptive-wrap

  • Description
    • can not do further operation, even open file or switch buffer
  • Solution
    • delete use-package and re-install use-package

DOING Network: make client process failed: Connection refused

  • Description

    Contacting host: raw.githubusercontent.com:443
    open-network-stream: make client process failed: Connection refused, :name, raw.githubusercontent.com, :buffer, #<killed buffer>, :host, raw.githubusercontent.com, :service, 443, :nowait, nil, :tls-parameters, nil
    
    • When I run M-x all-the-icons-install-fonts. The above shows in message and font is not downloaded.
  • Solution

DOING Chinese characters could not be displayed properly

Font missing

  • Description
    • There is a missfont.log

      mktextfm ecrm1000
      
      • Probably is caused by latex/tex feature.
  • Solution
    • On Ubuntu

      sudo apt-get install texlive-fonts-recommended
      

DONE org-latex-preview failed with errror: Please adjust ‘dvipng’ part of ‘org-preview-latex-process-alist’

  • Description
    • For preview latex in org-mode, such as: \[e^{\pi i }=-1\] (Run: C-c C-x C-l which is org-latex-preview), show error message

      Creating LaTeX preview...
      org-compile-file: File "/tmp/orgtexHB1HLg.dvi" wasn’t produced.  Please adjust ‘dvipng’ part of ‘org-preview-latex-process-alist’.
      
  • Solution
    • Install LaTex for Linux, TexLive

      sudo apt install texlive-xetex
      
    • In Emacs configuration

      (setq org-latex-compiler "xelatex")
      
  • Test \[e^{\pi i }=-1\]
Frank Zhao
Frank Zhao
Computer Science Engineer

My interests include Compiler, distributed system and Symbolic Computation.

Related