Learn Emacs in 21 Days: day 5 学习笔记

子龙山人Learn Emacs in 21 Days: day 5 学习笔记
Youtube
youku

继续上一回

emacs lisp mode不补全单引号

 (sp-local-pair 'emacs-lisp-mode "'" nil :actions nil)

删除scrach buffer

M-x ibuffer

D
x

不在括号的结尾也让括号显示高亮

(define-advice show-paren-function (:around (fn) fix-show-paren-function)
  "Highlight enclosing parens."
  (cond ((looking-at-p "\\s(") (funcall fn))
        (t (save-excursion
             (ignore-errors (backward-up-list))
             (funcall fn)))))

隐藏/删除windows下保存文件可能存在的^M

(defun hidden-dos-eol ()
  "Do not show ^M in files containing mixed UNIX and DOS line endings."
  (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 "")))

打造emacs成web开发工具

安装并配置web-mode

(setq auto-mode-alist
      (append
       '(("\\.js\\'" . js2-mode))
        '(("\\.html\\'" . web-mode))
       auto-mode-alist))

配置缩进

;; config for web mode
(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
  )

(defun my-toggle-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 (= js2-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-toggle-web-indent)

js-refactor

https://github.com/magnars/js2-refactor.el

occur

popwin

可以安装并配置popwin 具体参考视频
customize-group popwin
right
weith

occur

M-s o 输入要搜索的内容
M-x ^occur-edit-mode/e 编辑查找出来的内容
C-c C-c 可以将修改的内容同步用buffer里

默认光标的内容作为查找内容

  (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 "M-s o" 'occur-dwim)

imenu 可以跳转到对应的函数

M-x imenu

expand-region and iedit mode

config

C-=可以选择不断地扩展选中区域

(global-set-key (kbd "C-=") 'er/expand-region)

iedit

iedit可以同时编辑多个区域

C-; 可以激活iedit-mode

iedit和uccor混合使用

M-s o occur-mode打开查找内容
e 进入编辑模式
c-= 选择需要编辑的内容
c-; 激活iedit-mode 
C-c C-c 使用occur中的修改内容生效

bonus

改变选中区域颜色

M-x customize-face
stackoverflow

org

可以导出org文件

C-c C-e

你可能感兴趣的:(emacs)