Last active
March 26, 2019 11:20
-
-
Save c02y/3023dde0a8eeedc65d2c6861e4fd278c to your computer and use it in GitHub Desktop.
use emacsclient to speed up startup of Emacs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
remove dired+ and bookmark+ packages | |
clean dired+ config | |
;; (setq desktop-save 'ask) | |
;;desktop-save ask means always ask | |
;; (desktop-save-mode nil) | |
(setq confirm-kill-emacs 'y-or-n-p) | |
(defun ask-before-closing () | |
"Useful to be used in emacsclient to avoid accident exit of Emacs like 'Save desktop?'." | |
(interactive) | |
(if (y-or-n-p (format "Really exit Emacs? ")) | |
(save-buffers-kill-terminal) | |
(message "Canceled frame close!"))) | |
(when (daemonp) | |
(global-set-key (kbd "C-x C-c") 'ask-before-closing)) | |
function emm -d 'emacsclient, new daemon if not exists, -r to kill the daemon' | |
set -l options 'r' | |
argparse -n emm $options -- $argv | |
or return | |
if set -q _flag_r | |
pkill -f 'emacs --daemon' | |
and echo "emacs --daemon killed!" | |
end | |
# if the daemon is not running, run it, otherwise run client | |
if test $DISPLAY | |
emacsclient -n -a "" -c $argv ^/dev/null | |
else | |
emacsclient -a "" -t $argv ^/dev/null | |
end | |
end | |
replace emacs with emm when editing a file using emacs | |
function fu -d 'fu command and prompt to ask to open it or not' | |
# $argv could be builtin keyword, function, alias, file(bin/script) in $PATH, abbr | |
# And they all could be defined in script or temporally (could be found in any file) | |
set found 0 | |
# Check `type` output, NOTE: `type` doesn't support abbr | |
if type $argv ^/dev/null # omit the result once error(abbr or not-a-thing) returned, $status = 0 | |
set found 1 # for not-a-thing | |
set result (type $argv) | |
end | |
if abbr --show | head -n1 | grep "abbr -a -U" ^/dev/null >/dev/null | |
set abbr_show "abbr -a -U --" | |
else | |
set abbr_show "abbr" | |
end | |
# NOTE: $argv may also be defined as an abbr like rm command | |
abbr --show | grep "$abbr_show $argv " # Space to avoid the extra abbr starting with $ARGV | |
if test $status = 0 | |
# in case $argv existes in both `type` and `abbr --show` | |
# function may be `function func` and `function func -d ...` | |
if test $found = 1 -a (echo (grep -w -E "^alias $argv |^function $argv |^function $argv\$" $FISH_CONFIG_PATH)) | |
echo "$argv is in both `type` and `abbr --list`, found definition in $FISH_CONFIG_PATH" | |
abbrc | |
# continue, use the result of `type` | |
else # only exists in `abbr --show` | |
set found 1 | |
set result (abbr --show | grep "$abbr_show $argv ") | |
end | |
else if test $status != 0 -a $found != 1 | |
echo "$argv is not a thing!" | |
return | |
end | |
set result_1 (printf '%s\n' $result | head -1) | |
if test (echo $result_1 | grep -E "$abbr_show $argv |is a function with definition") # defined in fish script | |
if test (echo $result_1 | grep -E "is a function with definition") | |
# 1. function or alias -- second line of output of fu ends with "$path @ line $num_line" | |
set -l result_2 (printf '%s\n' $result | sed -n "2p") | |
set def_file (echo $result_2 | awk -v x=4 '{print $x}') | |
if test "$def_file" = "-" # alias, no definition file is printed | |
set def_file $FISH_CONFIG_PATH | |
end | |
set num_line (grep -n -w -E "^alias $argv |^function $argv |^function $argv\$" $def_file | cut -d: -f1) | |
if not test $num_line # empty | |
echo "$argv is an alias/functions in `alias/functions` but not defined in $def_file, may be defined temporally or in other file!" | |
if test $def_file = $FISH_CONFIG_PATH | |
functions -e $argv | |
echo "$argv is erased!" | |
end | |
return | |
end | |
else # 2. abbr | |
set def_file $FISH_CONFIG_PATH | |
set num_line (grep -n "^abbr $argv " $def_file | cut -d: -f1) | |
if not test $num_line # empty | |
echo "$argv is an abbr in `abbr --show` but not defined in $FISH_CONFIG_PATH, may be defined temporally or in other file!" | |
if test $def_file = $FISH_CONFIG_PATH | |
abbr -e $argv | |
echo "$argv is erased!" | |
end | |
return | |
end | |
end | |
echo | |
read -n 1 -p 'echo "Open the file containing the definition? [y/N]: "' -l answer | |
if test "$answer" = "y" -o "$answer" = " " | |
vim $def_file +$num_line | |
end | |
else if test (echo $result_1 | grep -i "is a builtin") | |
# 3. $argv in builtin like if | |
return | |
else # 4. $argv is a file in $PATH | |
set -l file_path (echo $result_1 | awk 'NF>1{print $NF}') | |
file $file_path | grep "symbolic link" # print only $argv is symbolic link | |
file (readlink -f $file_path) | grep -E "ELF|script|executable" # highlight | |
if test (file (readlink -f $file_path) | grep "script") # script can be open | |
echo | |
read -n 1 -p 'echo "Open the file for editing?[y/N]: "' -l answer | |
if test "$answer" = "y" -o "$answer" = " " | |
vim $file_path | |
end | |
end | |
end | |
end | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;;;;;;; theme & font | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; | |
;; font and size of startup | |
;; | |
;; List all fonts available to emacs | |
;; (print (font-family-list)) | |
;; | |
;; Test font in current session; | |
;; Set font for all windows, keep window size fixed | |
;; (set-frame-font "PragmataPro-10" t t) | |
;; set font for all windows, don't keep window size fixed | |
;; (set-frame-font "PragmataPro-10" nil t) | |
(defun set-frame-size-according-to-resolution () | |
(interactive) | |
(if window-system | |
(progn | |
;; Setting font size will affect frame size, so set font size first | |
;; But it still slightly affect the frame size even using this order | |
;; or Monaco, Bitstream Vera Sans Mono, Liberation Mono | |
(if (> (x-display-pixel-width) 1500) | |
(cond | |
((find-font (font-spec :name "PragmataPro")) | |
(set-frame-font "PragmataPro-13.5")) | |
((find-font (font-spec :name "Input Mono Compressed")) | |
(set-frame-font "Input Mono Compressed-13.5"))) | |
(cond | |
((find-font (font-spec :name "PragmataPro")) | |
(set-frame-font "PragmataPro-12")) | |
((find-font (font-spec :name "Input Mono Compressed")) | |
(set-frame-font "Input Mono Compressed-12")))) | |
(setq width-chars (/ (/ (x-display-pixel-width) (frame-char-width)) 2)) | |
(setq height-lines (- (/ (x-display-pixel-height) (frame-char-height)) 4)) | |
(setq default-frame-alist | |
`((top . 0) (left . 0) | |
(width . ,width-chars) | |
(height . ,height-lines))) | |
;; the following two settings are specifically for afternoon-theme | |
;; the combination colors of highlighted line and comments | |
;; (custom-set-faces | |
;; '(font-lock-comment-face | |
;; ((t (:foreground "gray60" :slant italic :weight normal :family "Menlo"))) | |
;; )) | |
;; (set-face-background 'highlight "gray30") | |
))) | |
;; | |
;; theme | |
;; | |
;; Enabling a light theme temporarily, use M-x load-theme <TAB> flatui if you | |
;; want to enable it after start up, add the two lines like below | |
;; | |
;; | |
;; afternoon | |
;; (require 'afternoon-theme) | |
;; | |
;; ;; molokai | |
;; (load-theme 'molokai t) | |
;; (require 'molokai-theme) | |
;; | |
;; moe-theme, a very colorful and powerful theme | |
;; for more setting at https://github.com/kuanyui/moe-theme.el | |
;; Put all theme configuration into the display-graphic-p block | |
(if (daemonp) | |
;; for emacs --deamon, do not load theme/font in terminal Emacs | |
(add-hook 'after-make-frame-functions | |
(lambda (frame) | |
(select-frame frame) | |
(when (display-graphic-p) | |
(set-frame-size-according-to-resolution) | |
;; the following will get rid of prompt when M-x load-theme, treat all | |
;; themes as safe | |
(setq custom-safe-themes t) | |
(require 'moe-theme) | |
;; Resize titles | |
(setq moe-theme-resize-markdown-title '(1.3 1.2 1.1 1.0 1.0 1.0)) | |
(setq moe-theme-resize-org-title '(1.3 1.2 1.1 1.0 1.0 1.0 1.0 1.0 1.0)) | |
;; disable default mode-line buffer-id highlight | |
(setq moe-theme-highlight-buffer-id nil) | |
(moe-dark)))) | |
(when (display-graphic-p) | |
(progn | |
(set-frame-size-according-to-resolution) | |
;; the following will get rid of prompt when M-x load-theme, treat all | |
;; themes as safe | |
(setq custom-safe-themes t) | |
(require 'moe-theme) | |
;; Resize titles | |
(setq moe-theme-resize-markdown-title '(1.3 1.2 1.1 1.0 1.0 1.0)) | |
(setq moe-theme-resize-org-title '(1.3 1.2 1.1 1.0 1.0 1.0 1.0 1.0 1.0)) | |
;; disable default mode-line buffer-id highlight | |
(setq moe-theme-highlight-buffer-id nil) | |
(moe-dark)))) | |
;; | |
;; disable scroll-bar-mode in newly created frame |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment