diff --git a/lisp/init-autoload.el b/lisp/init-autoload.el index 79dd1e45ee..36871a5b6a 100644 --- a/lisp/init-autoload.el +++ b/lisp/init-autoload.el @@ -13,7 +13,6 @@ (autoload 'ace-pinyin-jump-char "ace-pinyin" "" t) (autoload 'ace-pinyin-jump-char-2 "ace-pinyin" "" t) (autoload 'gmail2bbdb-import-file "gmail2bbdb" "" t) -(autoload 'auto-save-enable "auto-save" "" t) (autoload 'typewriter-mode "typewriter-mode" "" t) (autoload 'mybigword-show-big-words-from-file "mybigword" "" t) (autoload 'mybigword-show-big-words-from-current-buffer "mybigword" "" t) diff --git a/lisp/init-misc.el b/lisp/init-misc.el index dff4e2a3cb..aae7f20b8f 100644 --- a/lisp/init-misc.el +++ b/lisp/init-misc.el @@ -7,6 +7,29 @@ ;; Set `auto-window-vscroll' to nil to avoid triggering `format-mode-line'. (setq auto-window-vscroll nil) +;; {{ auto save set up +(defvar my-auto-save-exclude-major-mode-list + '(message-mode + c-mode) + "The major modes where auto-save is disabled.") + +(setq auto-save-visited-interval 2) + +(defun my-auto-save-visited-mode-setup () + "Auto save setup." + ;; turn off `auto-save-visited-mode' in certain scenarios + (message "my-auto-save-visited-mode-setup called") + (when (or (not (buffer-file-name)) + (file-remote-p (buffer-file-name)) + (my-file-too-big-p (buffer-file-name)) + (memq major-mode my-auto-save-exclude-major-mode-list)) + (setq-local auto-save-visited-mode nil))) +(my-run-with-idle-timer 2 #'auto-save-visited-mode) +(add-hook 'auto-save-visited-mode-hook #'my-auto-save-visited-mode-setup) +;; (add-hook 'text-mode-hook #'my-auto-save-visited-mode-setup) +;; (add-hook 'prog-mode-hook #'my-auto-save-visited-mode-setup) +;; }} + ;; {{ auto-yasnippet ;; Use C-q instead tab to complete snippet ;; - `aya-create' at first, input ~ to mark the thing next @@ -220,69 +243,6 @@ In each rule, 1st item is default directory, 2nd item is the shell command.") ))) ;; }} -(defun my-generic-prog-mode-hook-setup () - "Generic programming mode set up." - (when (buffer-too-big-p) - - (when (my-should-use-minimum-resource) - (font-lock-mode -1))) - - (add-hook 'after-save-hook #'my-save-run-function nil t) - - (my-company-ispell-setup) - - (unless (my-buffer-file-temp-p) - ;; trim spaces from end of changed line - (ws-butler-mode 1) - - (unless (featurep 'esup-child) - (cond - ((not my-disable-lazyflymake) - (my-ensure 'lazyflymake) - (lazyflymake-start)) - (t - (flymake-mode 1))) - - (unless my-disable-wucuo - (my-ensure 'wucuo) - (setq-local ispell-extra-args (my-detect-ispell-args t)) - (wucuo-start))) - - ;; @see http://xugx2007.blogspot.com.au/2007/06/benjamin-rutts-emacs-c-development-tips.html - (setq compilation-finish-functions - '(my-compilation-finish-hide-buffer-on-success)) - - ;; fic-mode has performance issue on 5000 line C++, use swiper instead - - ;; don't spell check double words - (setq-local wucuo-flyspell-check-doublon nil) - ;; @see http://emacsredux.com/blog/2013/04/21/camelcase-aware-editing/ - (unless (derived-mode-p 'js2-mode) - (subword-mode 1)) - - ;; now css-mode derives from prog-mode - ;; see the code of `counsel-css-imenu-setup' - (when (counsel-css-imenu-setup) - ;; css color - (rainbow-mode 1) - (imenu-extra-auto-setup - ;; post-css mixin - '(("Function" "^ *@define-mixin +\\([^ ]+\\)" 1))) - (setq beginning-of-defun-function - (lambda (arg) - (ignore arg) - (let* ((closest (my-closest-imenu-item))) - (when closest - (goto-char (cdr closest))))))) - - (my-run-with-idle-timer 2 (lambda () (electric-pair-mode 1))) - - ;; eldoc, show API doc in minibuffer echo area - ;; (turn-on-eldoc-mode) - ;; show trailing spaces in a programming mod - (setq show-trailing-whitespace t))) - -(add-hook 'prog-mode-hook 'my-generic-prog-mode-hook-setup) (add-hook 'text-mode-hook #'lazyflymake-start) ;;; {{ display long lines in truncated style (end line with $) @@ -463,25 +423,6 @@ So it's at the top of clipboard manager." (setq indent-tabs-mode (not indent-tabs-mode)) (message "indent-tabs-mode=%s" indent-tabs-mode)) -(defvar my-auto-save-exclude-major-mode-list - '(message-mode) - "The major modes where auto-save is disabled.") - -;; {{ auto-save.el -(defun my-check-major-mode-for-auto-save (file) - "Check current major mode of FILE for auto save." - (ignore file) - (memq major-mode my-auto-save-exclude-major-mode-list)) - -(with-eval-after-load 'auto-save - (push 'file-remote-p auto-save-exclude) - (push 'my-file-too-big-p auto-save-exclude) - (push 'my-check-major-mode-for-auto-save auto-save-exclude) - (setq auto-save-idle 2) ; 2 seconds - (setq auto-save-slient t)) -(my-run-with-idle-timer 4 #'auto-save-enable) -;; }} - ;; {{ csv (setq csv-separators '("," ";" "|" " ")) ;; }} @@ -1315,5 +1256,67 @@ MATCH is optional tag match." (kill-new selected) (message "\"%s\" => kill-ring" selected)))) +(defun my-generic-prog-mode-hook-setup () + "Generic programming mode set up." + (when (buffer-too-big-p) + (when (my-should-use-minimum-resource) + (font-lock-mode -1))) + + (add-hook 'after-save-hook #'my-save-run-function nil t) + + (my-company-ispell-setup) + + (unless (my-buffer-file-temp-p) + ;; trim spaces from end of changed line + (ws-butler-mode 1) + + (unless (featurep 'esup-child) + (cond + ((not my-disable-lazyflymake) + (my-ensure 'lazyflymake) + (lazyflymake-start)) + (t + (flymake-mode 1))) + + (unless my-disable-wucuo + (my-ensure 'wucuo) + (setq-local ispell-extra-args (my-detect-ispell-args t)) + (wucuo-start))) + + ;; @see http://xugx2007.blogspot.com.au/2007/06/benjamin-rutts-emacs-c-development-tips.html + (setq compilation-finish-functions + '(my-compilation-finish-hide-buffer-on-success)) + + ;; fic-mode has performance issue on 5000 line C++, use swiper instead + + ;; don't spell check double words + (setq-local wucuo-flyspell-check-doublon nil) + ;; @see http://emacsredux.com/blog/2013/04/21/camelcase-aware-editing/ + (unless (derived-mode-p 'js2-mode) + (subword-mode 1)) + + ;; now css-mode derives from prog-mode + ;; see the code of `counsel-css-imenu-setup' + (when (counsel-css-imenu-setup) + ;; css color + (rainbow-mode 1) + (imenu-extra-auto-setup + ;; post-css mixin + '(("Function" "^ *@define-mixin +\\([^ ]+\\)" 1))) + (setq beginning-of-defun-function + (lambda (arg) + (ignore arg) + (let* ((closest (my-closest-imenu-item))) + (when closest + (goto-char (cdr closest))))))) + + (my-run-with-idle-timer 2 (lambda () (electric-pair-mode 1))) + + ;; eldoc, show API doc in minibuffer echo area + ;; (turn-on-eldoc-mode) + ;; show trailing spaces in a programming mod + (setq show-trailing-whitespace t))) +(add-hook 'prog-mode-hook 'my-generic-prog-mode-hook-setup) + (provide 'init-misc) ;;; init-misc.el ends here diff --git a/site-lisp/auto-save/auto-save.el b/site-lisp/auto-save/auto-save.el deleted file mode 100644 index de1092b9d5..0000000000 --- a/site-lisp/auto-save/auto-save.el +++ /dev/null @@ -1,188 +0,0 @@ -;;; auto-save.el --- Auto save files when idle - -;; Filename: auto-save.el -;; Description: Auto save files when idle -;; Author: Andy Stewart lazycat.manatee@gmail.com -;;; Maintainer: Chen Bin (redguardtoo) -;; Copyright (C) 2013 ~ 2014, Andy Stewart, all rights reserved. -;; Created: 2013-12-31 00:32:00 -;; Version: 1.0 -;; URL: -;; Keywords: autosave -;; Compatibility: GNU Emacs 23.0.60.1 -;; -;; Features that might be required by this library: -;; -;; -;; - -;;; This file is NOT part of GNU Emacs - -;;; License -;; -;; This program is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 3, or (at your option) -;; any later version. - -;; This program is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program; see the file COPYING. If not, write to -;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth -;; Floor, Boston, MA 02110-1301, USA. - -;;; Commentary: -;; -;; Auto save file when emacs idle -;; - -;;; Installation: -;; -;; Put auto-save.el to your load-path. -;; The load-path is usually ~/elisp/. -;; It's set in your ~/.emacs like this: -;; (add-to-list 'load-path (expand-file-name "~/elisp")) -;; -;; And the following to your ~/.emacs startup file. -;; -;; (require 'init-auto-save) -;; (auto-save-enable) -;; -;; Set `auto-save-slient' with non-nil if want emacs save files slient: -;; (setq auto-save-slient t) -;; -;; No need more. - -;;; Change log: -;; -;; 2014/01/04 -;; * Add new function `auto-save-enable' to enable auto-save in user config file. -;; * Add options: `auto-save-idle' and `auto-save-slient' -;; -;; 2008/10/20 -;; First released. -;; - -;;; Acknowledgements: -;; -;; -;; - -;;; TODO -;; -;; -;; - -;;; Require - - -;;; Code: - -(defgroup auto-save nil - "Auto save file when emacs idle." - :group 'auto-save) - -(defcustom auto-save-idle 2 - "The idle seconds to auto save file." - :type 'integer - :group 'auto-save) - -(defcustom auto-save-slient nil - "Nothing to dirty minibuffer if this option is non-nil." - :type 'boolean - :group 'auto-save) - -(defcustom auto-save-exclude - '("\\.avi" - "\\.mpeg" - "\\.3gp" - "\\.mp4" - "\\.mp3" - "\\.mkv" - "\\.rm" - "\\.rmvb" - "\\.pdf" - "\\.jpg" - "\\.jpeg" - "\\.png" - "\\.gif" - "\\.gz" - "\\.svg" - "\\.ico" - "\\.gpg" - "archive-contents") - "List of regexps and predicates for filenames excluded from the auto save list. -When a filename matches any of the regexps or satisfies any of the -predicates it is excluded from the auto save list. -A predicate is a function that is passed a filename to check and that -must return non-nil to exclude it." - :group 'auto-save) - -;; Emacs' default auto-save is stupid to generate #foo# files! -(setq auto-save-default nil) - -(defun auto-save-include-p (filename) - "Return non-nil if FILENAME should be included. -That is, if it doesn't match any of the `auto-save-exclude' checks." - (let* ((case-fold-search nil) - (include-p t) - (i 0) - check) - (while (and (< i (length auto-save-exclude)) include-p) - ;; If there was an error in a predicate, err on the side of - ;; keeping the file. - (setq check (nth i auto-save-exclude)) - (condition-case nil - (progn - (cond - ((stringp check) - ;; A regexp - (setq include-p (not (string-match-p check filename)))) - ((functionp check) - ;; A predicate - (setq include-p (not (funcall check filename)))))) - (error nil)) - (setq i (1+ i))) - - include-p)) - -(defun auto-save-buffers () - "Auto save all buffer." - (interactive) - (let* (autosave-buffer-list) - (save-excursion - (dolist (buf (buffer-list)) - (set-buffer buf) - (when (and (buffer-file-name) - (buffer-modified-p) - (file-writable-p (buffer-file-name)) - (auto-save-include-p (buffer-file-name))) - (push (buffer-name) autosave-buffer-list) - (if auto-save-slient - (with-temp-message "" - (basic-save-buffer)) - (basic-save-buffer)))) - ;; Tell user when auto save files. - (unless auto-save-slient - (cond - ;; It's stupid tell user if nothing to save. - ((= (length autosave-buffer-list) 1) - (message "# Saved %s" (car autosave-buffer-list))) - ((> (length autosave-buffer-list) 1) - (message "# Saved %d files: %s" - (length autosave-buffer-list) - (mapconcat 'identity autosave-buffer-list ", "))))) - ))) - -(defun auto-save-enable () - "Enable auto save." - (interactive) - (run-with-idle-timer auto-save-idle t #'auto-save-buffers)) - -(provide 'auto-save) - -;;; auto-save.el ends here