Using Emacs Editor For The First Time
Jun 15, 2020
5 minute read

Recently I had been learning how to programs in Racket language. editors like VSCode and vim support poorly for the Racket language. And in the document of Racket, it recommends Emacs for developing Racket project. So I decided to give it a try. The main purpose of this blog is to record some solutions to problems that happened while I using it.

Emacs GUI


Follow the installation section of Emacs document, I installed latest Emacs 26.3 successfully on the platforms Ubuntu 18.04 and MacOS 10.15.4

On Ubuntu 18.04, download the source codes of Emacs, following this section of the document.


Decompress it, compile the source codes and then install Emacs.

# decompress
tar -xvf emacs-26.3.tar.xz
cd emacs-26.3
# with GUI
# or without GUI
./configure \
    --with-x-toolkit=no \
    --with-xpm=no \
    --with-jpeg=no \
    --with-gif=no \
# compile and install
make install

On MacOS 10.15.4, Emacs can be easily installed by using Homebrew.

brew cask install emacs

New Installation On MacOS (Updated At 2020-06-16)

Using brew cask install emacs to install emacs will be unable to get full disk accessing on macOS, even if the user granting. Using emacs-plus instead, run below commands to install it.

brew tap d12frosted/emacs-plus
brew install [email protected] --with-modern-icon-pen
ln -s /usr/local/opt/[email protected]/ /Applications

Emacs-plus 27 is able to get full disk accessing on macOS if user granting. Many Thanks to dive/fix-emacs-permissions-catalina.el

Make Emacs More Beautiful

The main topic of this blog is how to configure the Emacs more beautiful. The beautiful editor did improve my programming efficiency :)

Package manager

Using straight with use-package for package managing. Create a .emacs file in the home directory with the below text.

;;; Package manager
;; Bootstrapping straight.el
(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
         'silent 'inhibit-cookies)
      (goto-char (point-max))
  (load bootstrap-file nil 'nomessage))
;; Integration with use-package
(straight-use-package 'use-package)

After setting-up the package manager, we can use it to install almost any package we want.


doom-themes seems pretty good. Copy the below example configure codes, append it into .emacs file.

;;; Theme Config
(use-package doom-themes
  :straight t
  ;; Global settings (defaults)
  (setq doom-themes-enable-bold t    ; if nil, bold is universally disabled
        doom-themes-enable-italic t) ; if nil, italics is universally disabled
  (load-theme 'doom-one-light t)
  ;; Enable flashing mode-line on errors
  ;; Enable custom neotree theme (all-the-icons must be installed!)
  ;; or for treemacs users
  (setq doom-themes-treemacs-theme "doom-colors") ; use the colorful treemacs theme
  ;; Corrects (and improves) org-mode's native fontification.


Setting-up a neat and pretty startup screen. Appends below code into .emacs file to install and setup.

;;; Dashboard
(use-package dashboard
  :straight t

See repos of emacs-dashboard for additional details.

Configure GUI on MacOS

;;; GUI Config
(when (eq system-type 'darwin)
  ;; Make the title bar and toolbar to be transparent.
  (add-to-list 'default-frame-alist
               '(ns-transparent-titlebar . t))
  (add-to-list 'default-frame-alist
               '(ns-appearance . dark))
  ;; Change the opacity of the frame.
  (add-to-list 'default-frame-alist
               '(alpha . (80 . 75))))
;; Disable dialog box
(setq use-file-dialog        nil
      use-dialog-box         nil)
;; Hide toolbar
(when (fboundp 'tool-bar-mode)
  (tool-bar-mode -1))
;; Hide scrollbar
(when (fboundp 'set-scroll-bar-mode)
  (set-scroll-bar-mode nil))

Weird Problems Happened While Using Emacs

MacOS Misc (Updated at 2020-06-16)

Dired is a directory editor on Emacs. It uses ls program. On macOS, ls does not support --dired option. Appending below codes into .emacs file to configure dired using ls without --dired.

;;; MacOS Misc
(when (string= system-type "darwin")
  (setq dired-use-ls-dired nil))

See Dired for addition details.

Produces Weird Output While Running Shell In Emacs

Use <M-x> shell <RET> to launch shell in Emacs. It produces weird output while prompt appearing every time. Some outputs like this '1337;Remote Host...CurrentDir'. It is caused by iTerm2 Shell Integration when using iTerm2 on macOS. Adding a condition [ $TERM != "dumb" ] according to the FAQ will resolve this problem.

But the shell launched inside the Emacs still has some weird output, but launch it with GUI will not produce those weird output. Such as "^[]2;", "^G^[]1;" and "^G". Those maybe are ANSI escape codes, which Emacs shell does not support currently. Use <M-x> ansi-term <RET> to get better ANSI escape code support for shell. But launching shell with ansi-term will set TERM="eterm-color". So it needs to add a new condition [ $TERM != "eterm-color" ] to apply iTerm2 Shell Integration.

I use ZSH shell, so need to modify .zshrc file to use the correct way for enabling iTerm2 Shell Integration.

# iTerm2 Shell Integration
if [ $TERM != "dumb" ] && [ $TERM != "eterm-color" ]; then
  if [ -e "${HOME}/.iterm2_shell_integration.zsh" ]; then
    source "${HOME}/.iterm2_shell_integration.zsh"

Environment Variables Are Different From User Shell To Emacs Shell

Launch shell in Emacs with $PATH variable has been changed. I google a lot of solutions but none of working fine. Luckily I find out this repository perfectly solves my problem. Using exec-path-from-shell to ensure environment variables inside Emacs look the same as in the user’s shell.

Appending below codes into .emacs file and it will work fine.

;;; Shell Configure
;; Ensure environment variables inside Emacs
;; look the same as in the user's shell.
(use-package exec-path-from-shell
  :straight t
  :if (memq window-system '(mac ns))

comments powered by Disqus