Emacs funcs.
- “after” macro definition after宏可以指定加载某些插件后自动运行一段特定的代码
(if (fboundp 'with-eval-after-load)
(defmacro after (feature &rest; body)
"After FEATURE is loaded, evaluate BODY."
(declare (indent defun))
`(with-eval-after-load ,feature ,@body))
(defmacro after (feature &rest; body)
"After FEATURE is loaded, evaluate BODY."
(declare (indent defun))
`(eval-after-load ,feature
'(progn ,@body))))))
(defun default-font-width ()
"Return the width in pixels of a character in the current
window's default font. More precisely, this returns the
width of the letter ‘m’. If the font is mono-spaced, this
will also be the width of all other printable characters."
(let ((window (selected-window))
(let ((window (selected-window))
(let ((window (selected-window))
(let ((window (selected-window))
(remapping face-remapping-alist))
(with-temp-buffer
(make-local-variable 'face-remapping-alist)
(setq face-remapping-alist remapping)
(set-window-buffer window (current-buffer))
(insert "m")
(aref (aref (font-get-glyphs (font-at 1) 1 2) 0) 4))))
;;简易的,只能为指定的文件处理为只读
(define-derived-mode org-read-only-mode org-mode "Org + read-only"
"Major mode for readonly org file."
(read-only-mode 1))
(add-to-list 'auto-mode-alist '("\\FILE.org\\'" . org-read-only-mode))
;;统一处理,设置了一个钩子
(defvar read-only-file-list
(list (expand-file-name "~/test.org")))
(defun enable-read-only-fn ()
(when (member (expand-file-name (buffer-file-name)) read-only-file-list)
(read-only-mode 1)))
(add-hook 'find-file-hook #'enable-read-only-fn)
(defun sl-toggle-tab-width-setting ()
"Toggle setting tab widths between 4 and 8."
(interactive)
(setq-local tab-width (case tab-width (2 4) (4 8) (8 2)))
(setq-local c-basic-offset tab-width)
(redraw-display)
(message "tab-width is %s now" tab-width))
(eval-after-load 'hideshow
'(progn
(declare-function 'hs-already-hidden-p "hideshow")
(declare-function 'hs-show-all "hideshow")
(declare-function 'hs-hide-all "hideshow")
(defun sl-toggle-hideshow-all ()
"Toggle hideshow all."
(interactive)
(hs-life-goes-on
(if (hs-already-hidden-p)
(hs-show-all)
(hs-hide-all))))
(define-key-after
hs-minor-mode-menu
[\(SL\)Toggle\ Show/Hide\ all]
'(menu-item "(SL)Toggle Show/Hide all..." sl-toggle-hideshow-all
:help "Toggle Show/Hide all in current buffer..")
'Toggle\ Hiding)
(define-key hs-minor-mode-map (kbd "C-M-;") 'sl-toggle-hideshow-all)
(define-key hs-minor-mode-map (kbd "C-l ;") 'hs-toggle-hiding)))
(add-hook 'c-mode-common-hook
(lambda ()
;; c/c++ common settings
(declare-function c-toggle-hungry-state "cc-cmds")
(c-toggle-hungry-state 1)
;; (c-toggle-auto-hungry-state 1) ; hungry-delete and auto-newline
;; (c-set-offset 'case-label '+) ; indent the case
;; for c++11 as default
(when (eq major-mode 'c++-mode)
(when (boundp 'company-clang-arguments)
(setq-local company-clang-arguments (add-to-list 'company-clang-arguments "--std=c++11"))))
))