Basic emacs configuration

From 清冽之泉
Jump to navigation Jump to search

basic

(set-language-environment "UTF-8")
(set-default-coding-systems 'utf-8-unix)
;; (setq package-archives '(("gnu"   . "http://1.15.88.122/gnu/")
;;                          ("melpa" . "http://1.15.88.122/melpa/")))

;; (set-face-attribute 'default nil :font "DejaVu Serif:pixelsize=30")
;; (set-fontset-font t 'han "TW-MOE-Std-Kai:pixelsize=30")
;; (set-fontset-font t 'han "WenQuanYi Zen Hei:pixelsize=25" nil 'append)
;; DejaVu Serif, TW-MOE-Std-Kai, WenQuanYi Micro Hei
(set-fontset-font t 'han "WenQuanYi Micro Hei:pixelsize=20")

onoff

(setq inhibit-splash-screen t)
(setq make-backup-files nil)
(setq create-lockfiles nil)
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(setq custom-enabled-themes '(sanityinc-tomorrow-day))

(setq suggest-key-bindings 10) ;十秒后建议才消失
(show-paren-mode) ;显示对应括号
(electric-pair-mode) ;自动右括号
(delete-selection-mode t)

(global-auto-revert-mode t)
(global-visual-line-mode t)

packages

;; List the packages want to install
(setq package-list '(
		     benchmark-init
		     use-package
		     which-key
		     company
		     magit
		     yaml-mode
		     yasnippet
		     smart-compile
		     markdown-mode
		     lsp-mode
		     sdcv

		     ;; auctex
		     ;; let-alist ;; for pdf-tools
		     ;; tablist   ;; for pdf-tools
		     ;; cask      ;; for pdf-tools
		     ;; pdf-tools
		     ;; youdao-dictionary

		     ;; Opt
		     ;; ace-window
		     web-mode
		     projectile
		     htmlize
		     edit-server
		     mediawiki
		     ))

(unless package-archive-contents
  (package-refresh-contents))

;; Install the missing packages
(dolist (package package-list)
  (unless (package-installed-p package)
    (package-install package)))

;; (pdf-tools-install)

alias

(defalias 'yes-or-no-p 'y-or-n-p)
(defalias 'qr 'query-replace)
(defalias 'rr 'replace-regexp)
(defalias 'bs 'bookmark-set)
(defalias 'bj 'bookmark-jump)
(defalias 'dc 'describe-char)
(defalias 'sl 'sort-lines)
(defalias 'cr 'comment-region)
(defalias 'ur 'uncomment-region)
(defalias 'lm 'list-matching-lines)
(defalias 'md 'edit-server-done)
(defalias 'sd 'server-edit 1)

defun

q-open-init-file

(defun q-open-init-file()
  (interactive)
  (dired "~/.emacs.d/lisp/"))

say-ok-after-server-edit

;; 抄自 https://www.emacswiki.org/emacs/YesOrNoP,负作用不详,symbol-function 不懂
;; 作用为:建议server-edit函数执行后的询问是否保存,一概选是
;; (defadvice server-edit (around auto-confirm compile activate)
  ;; (cl-letf (((symbol-function 'yes-or-no-p) (lambda (&rest args) t))
  ;;           ((symbol-function 'y-or-n-p) (lambda (&rest args) t)))
  ;;   ad-do-it)
  ;; (sanityinc/maybe-suspend-frame))

(defadvice kill-current-buffer (around auto-confirm compile activate)
  (cl-letf (((symbol-function 'yes-or-no-p) (lambda (&rest args) t))
            ((symbol-function 'y-or-n-p) (lambda (&rest args) t)))
    ad-do-it)
  (sanityinc/maybe-suspend-frame))

q-compile-run-c

(defun q-compile-run-c ()
  "Compile C code, my first elisp program.

When run f8, C code will compile and print out some messages.

ARG1 `mediawiki-site'.

ARG2 `mediawiki-browse'.

See URL `http://xahlee.info/' to learn more practice code experience.

See  `magit'.

See Info node `(emacs) grep'.

Type \\[dired] to go into dired.

Type f8 to run this function.

Clickable list of all keys of a given keymap name.
\\{emacs-lisp-mode-map}"
  (interactive)
  (save-buffer)
  (delete-other-windows)
  (setq i (buffer-name))
  (setq o (file-name-sans-extension (file-name-nondirectory (buffer-file-name (current-buffer)))))
  (switch-to-buffer (eshell))
  (split-window-right -100)
  (eshell-bol)
  (kill-visual-line)
  (insert "cc -O2 " i " -lm -o " o " && ./" o)
  (eshell-send-input)
  (other-window 1)
  (end-of-buffer)
  (switch-to-buffer i)
  (other-window 1))

switch-other-window-to-buffer

(defun switch-other-window-to-buffer (name)
  (other-window 1)
  (switch-to-buffer name)
  (other-window 1))

run-scheme

;; 这行必须写,否则报错:找不到scheme函数
(require 'cmuscheme)

;; 是否指定用chezscheme都无所谓,emacs自己能找到,更没必要找chezscheme二进制文件
;; 这些应该是purcell的配置设置好了的,留待后究
;; 若要写,chez不行;scheme或chezscheme可行。

;; bypass the interactive question and start the default interpreter
(defun scheme-proc ()
  "Return the current Scheme process, starting one if necessary."
  (unless (and scheme-buffer
               (get-buffer scheme-buffer)
               (comint-check-proc scheme-buffer))
    (save-window-excursion
      (run-scheme scheme-program-name)))
  (or (scheme-get-process)
      (error "No current process. See variable `scheme-buffer'")))

(defun scheme-split-window ()
  (cond
   ((= 1 (count-windows))
    (split-window-vertically (floor (* 0.68 (window-height))))
    ;; (split-window-horizontally (floor (* 0.5 (window-width))))
    (switch-other-window-to-buffer "*scheme*"))
   ((not (member "*scheme*"
                 (mapcar (lambda (w) (buffer-name (window-buffer w)))
                         (window-list))))
    (switch-other-window-to-buffer "*scheme*"))))

(defun scheme-send-last-sexp-split-window ()
  (interactive)
  (scheme-split-window)
  (scheme-send-last-sexp))

(defun scheme-send-definition-split-window ()
  (interactive)
  (scheme-split-window)
  (scheme-send-definition))

(add-hook 'scheme-mode-hook
          (lambda ()
            (paredit-mode 1)
            ;;            (define-key scheme-mode-map (kbd "<f5>") 'scheme-send-last-sexp-split-window)
            (define-key scheme-mode-map (kbd "<f5>") 'scheme-send-definition-split-window)))

t-mw-define

(defun t-mw-define ()
  (interactive)
  "give mediawiki define element a :"
  (replace-regexp "^ ?" ": " nil))

keys

(global-set-key (kbd "<f1>") 'sdcv-search-pointer+)
(global-set-key (kbd "<f2>") 'switch-to-buffer)
(global-set-key (kbd "<f4>") 'q-open-init-file)
(global-set-key (kbd "<f5>") 'eval-buffer)
(global-set-key (kbd "<f8>") 'q-compile-run-c)
(global-set-key (kbd "<f9>") 'read-only-mode)
(global-set-key (kbd "<f12>") 'kill-current-buffer)

hooks

(add-hook 'after-init-hook 'benchmark-init/activate)
(add-hook 'dired-mode-hook  'dired-hide-details-mode t)

;; (add-hook 'after-init-hook #'auto-save-visited-mode)
;; (setq auto-save-visited-interval 1)
;; (add-hook 'pdf-view-mode-hook 'pdf-view-auto-slice-minor-mode)

tranlate

sdcv

;; 直接按 f1 即可用
;; 需 sudo apt install stardict sdcv,待验证
;; 需 posframe

(require 'sdcv)
;; (require 'company-english-helper) ;; 似乎存在字体 bug,对硬件要求很高,也不实用,暂且搁置

(setq sdcv-say-word-p t)
(setq sdcv-dictionary-data-dir "/home/qlzq/Documents/En") ;setup directory of stardict dictionary
(setq sdcv-dictionary-simple-list ;setup dictionary list for simple search
      '("简明英汉字典增强版"))
(setq sdcv-dictionary-complete-list ;setup dictionary list for complete search Etymonline
      '("简明英汉字典增强版"))

(global-set-key (kbd "C-x t C-d") 'sdcv-search-input)
(global-set-key (kbd "C-x t d") 'sdcv-search-pointer+)
(global-set-key (kbd "<f1>") 'sdcv-search-pointer+)

goldendict

;; 直接输命令 +dict- 即可用
;; 无需额外依赖
(defun +dict-word-at-point ()
  "Search word in goldendict"
  (interactive)
  (call-process-shell-command (concat "goldendict " (current-word) " &") nil 0))

fanyi

;; 直接输入命令 fanyi- 即可用
;; 依赖 fanyi.el
;; M-x package-install RET fanyi RET 即可
(custom-set-variables
 '(fanyi-providers '(fanyi-haici-provider
                     fanyi-youdao-thesaurus-provider
                     fanyi-etymon-provider
                     fanyi-longman-provider)))

mediawiki

'(mediawiki-site-alist
   '(("name" "http://n.n.n.n/mediawiki/" "user" "passwd" nil "Main Page")
     ("name" "https://someplace.com/mediawiki/" "user" "passwd" nil "Main Page")))

end

(setq company-minimum-prefix-length 3)
(global-company-mode t)
;; (setq markdown-command "/usr/bin/pandoc")

(provide 'init-local)
;; init-local.el ends here.