Skip to content
ctchuangPublic

About

Quick Emacs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

qe - Quick Emacs Client

Purpose

  1. Launch Emacs quicker

    • How?
      • Start Emacs server first (if not already running), then launch emacsclient
  2. Launch different Emacs servers in different sessions

    • Ex: different servers for different tmux sessions and GUI mode.
    • Why?
      • We can work on one git repository in one tmux session by isolating opened buffers and tags tables ( visit-tags-table).

Usage

Use the qe command to replace emacs -nw:

$ qe
$ qe [files-to-edit]

Use the qew command to replace emacs (GUI mode):

$ qew
$ qew [files-to-edit]

If you want to kill the background server process to save memory, M-x kill-emacs to kill all the clients and the server in the current session. But the startup latency will increase next time when you run qe/qew again.

Misc

Troubleshootings

  • C-h v server-name (the currrent Emacs server/socket name)

Better UI in tmux

If you want to run multiple qe in tmux to look like a tab-like UI, add this to .emacs:

Tmux Screenshot

(defun my-tmux-getenv (variable)
  "Return VARIABLE from the environment of the selected frame's terminal."
  (getenv variable (selected-frame)))

(defun inside-tmux-p ()
  "Return non-nil if the selected frame is displayed inside a tmux pane."
  (and (my-tmux-getenv "TMUX") (my-tmux-getenv "TMUX_PANE")))

(defun my-truncate-string (string max-length)
  (if (<= (length string) max-length)
      string
    (concat (substring string 0 max-length) "..")))

(defun update-tmux-title (&rest _)
  "Update the tmux window showing the selected frame to its buffer's name."
  (when (inside-tmux-p)
    (let* ((buffer (window-buffer (selected-window)))
           (name (file-name-nondirectory
                  (or (buffer-file-name buffer) (buffer-name buffer))))
           (title (concat "e:" (my-truncate-string name 15))))
      (unless (equal title (frame-parameter nil 'my-tmux-title))
        (set-frame-parameter nil 'my-tmux-title title)
        (call-process "tmux" nil 0 nil
                      "-S" (car (split-string (my-tmux-getenv "TMUX") ","))
                      "rename-window" "-t" (my-tmux-getenv "TMUX_PANE")
                      title)))))

(add-hook 'window-configuration-change-hook #'update-tmux-title)
(add-hook 'window-selection-change-functions #'update-tmux-title)

Trivia on Mac Setup

  1. Recommended to use Homebrew to install Emacs with both GUI and terminal support:
  $ brew install --cask emacs
  1. Homebrew may register Emacs server in the background with LaunchServices of Mac OS:
  # Check
  $ brew services list

  # Stop it if you want
  $ brew services stop emacs

About

Quick Emacs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages