SpaceEmacs Rock Day5 学习笔记
Table of Contents
1 SpaceEmacs Day 5
1.1 Fix smartparens quote issue
- not parens "'" in emacs-lisp-mode
;; not parens ' in emacs-lisp-mode (sp-local-pair 'emacs-lisp-mode "'" nil :actions nil)
- Hightight enclossing parens
(define-advice show-paren-function (:around (fn) fix-show-paren-function) "Hightight enclossing parens." (cond ((looking-at-p "\\s(") (funcall fn)) (t (save-excursion (ignore-errors (backward-up-list)) (funcall fn))))) (add-hook 'emacs-lisp-mode-hook 'show-paren-mode)
1.2 Editing large web page
- remove window "\r"
(defun hidden-dos-eol () "Do not show ^M in files contains mixed UNIX and DOS line encodings." (interactive) (setq buffer-display-table (make-display-table)) (aset buffer-display-table ?\^M [])) (defun remove-dos-eol () "Replace DOS eolns CR LF with Unix eolns CR" (interactive) (goto-char (point-min)) (while (search-forward "\r" nil t) (replace-match "")))
1.2.1 Web-mode
- M+; auto comment
(defun my-web-mode-indent-setup() (setq web-mode-markup-indent-offset 2) ;; web-mode, html tag in html file (setq web-mode-css-indent-offset 2) ;; web-mode, css in html file (setq web-mode-code-indent-offset 2) ;; web-mode, js code in html file ) (add-hook 'web-mode-hook 'my-web-mode-indent-setup) (defun my-togoole-web-indent () (interactive) ;; web development (if (or (eq major-mode 'js-mode) (eq major-mode 'js2-mode)) (progn (setq js-indent-level (if (= js-indent-level 2) 4 2)) (setq js2-basic-offset (if (= js-basic-offset 2) 4 2)))) (if (eq major-mode 'web-mode) (progn (setq web-mode-markup-indent-offset (if (= web-mode-markup-indent-offset 2) 4 2)) (setq web-mode-css-indent-offset (if (= web-mode-css-indent-offset 2) 4 2)) (setq web-mode-code-indent-offset (if (= web-mode-code-indent-offset 2) 4 2)))) (if (eq major-mode 'css-mode) (setq css-indent-offset (if (= css-indent-offset 2) 4 2))) (setq indent-tabs-mode nil)) (global-set-key (kbd "C-c t i") 'my-togoole-web-indent)
1.2.2 js2-refactor
(add-hook 'js2-mode-hook #'js2-refactor-mode)
(js2r-add-keybindings-with-prefix "C-c C-m")
1.3 occur and imenu
- M-s o to open occur
- e to edit
- h to help
- improve occur
(defun occur-dwim () "Call 'occur' with a sane default." (interactive) (push (if (region-active-p) (buffer-substring-no-properties (region-beginning) (region-end)) (let ((sym (thing-at-point 'symbol))) (when (stringp sym) (regexp-quote sym)))) regexp-history) (call-interactively 'occur)) (global-set-key (kbd "M-s o") 'occur-dwim)
- improve imenu
(defun js2-imenu-make-index () (interactive) (save-excursion ;; (setq imenu-generic-expression '((nil "describe\\(\"\\(.+\\)\"" 1))) (imenu--generic-function '(("describe" "\\s-*describe\\s-*(\\s-*[\"']\\(.+\\)[\"']\\s-*,.*" 1) ("it" "\\s-*it\\s-*(\\s-*[\"']\\(.+\\)[\"']\\s-*,.*" 1) ("test" "\\s-*test\\s-*(\\s-*[\"']\\(.+\\)[\"']\\s-*,.*" 1) ("before" "\\s-*before\\s-*(\\s-*[\"']\\(.+\\)[\"']\\s-*,.*" 1) ("after" "\\s-*after\\s-*(\\s-*[\"']\\(.+\\)[\"']\\s-*,.*" 1) ("Function" "function[ \t]+\\([a-zA-Z0-9_$.]+\\)[ \t]*(" 1) ("Function" "^[ \t]*\\([a-zA-Z0-9_$.]+\\)[ \t]*=[ \t]*function[ \t]*(" 1) ("Function" "^var[ \t]*\\([a-zA-Z0-9_$.]+\\)[ \t]*=[ \t]*function[ \t]*(" 1) ("Function" "^[ \t]*\\([a-zA-Z0-9_$.]+\\)[ \t]*()[ \t]*{" 1) ("Function" "^[ \t]*\\([a-zA-Z0-9_$.]+\\)[ \t]*:[ \t]*function[ \t]*(" 1) ("Task" "[. \t]task([ \t]*['\"]\\([^'\"]+\\)" 1))))) (add-hook 'js2-mode-hook (lambda () (setq imenu-create-index-function 'js2-imenu-make-index))) (global-set-key (kbd "M-s i") 'counsel-imenu)
1.4 expand-region and iedit mode
- expand-region
;; expand-region (global-set-key (kbd "C-=") 'er/expand-region)
- iedit-mode,multiple region in edit
(global-set-key (kbd "M-s e") 'iedit-mode)
1.5 Org export
- C-c C-e to export org file to other files
1.5.1 tes java
1.5.2 test c
#include <stdio.h> int main() { printf("Hello world"); }
1.5.3 test latex
$\lg2n\sin\theta$
\(\lg2n\sin\theta\)