;;; siren-core-editor.el --- jimeh's Emacs Siren: Editor settings. ;;; Commentary: ;; Default editor settings for Siren. ;;; Code: ;; don't use tabs to indent (setq-default indent-tabs-mode nil) ;; but maintain correct appearance (setq-default tab-width 8) ;; Newline at end of file (setq require-final-newline t) ;; Visual Line mode - wrap lines (visual-line-mode t) ;; Show matching parentheses (show-paren-mode t) ;; Delete the selection with a keypress (delete-selection-mode t) ;; Save place in files (setq save-place-file (expand-file-name "saveplace" siren-cache-dir)) (save-place-mode 1) ;; Electric behavior ;; (electric-layout-mode t) ;; Cursor (if window-system (progn (blink-cursor-mode t) (setq initial-frame-alist (cons '(cursor-type . bar) (copy-alist initial-frame-alist))) (setq default-frame-alist (cons '(cursor-type . bar) (copy-alist default-frame-alist)))) (blink-cursor-mode -1)) ;; Backup files (setq backup-by-copying t delete-old-versions t kept-new-versions 10 kept-old-versions 0 vc-make-backup-files t version-control t backup-directory-alist `((".*" . ,(expand-file-name "backup" siren-cache-dir)))) ;; Auto-save files (let ((auto-save-dir (expand-file-name "autosave/" siren-cache-dir))) (unless (file-exists-p auto-save-dir) (make-directory auto-save-dir)) (setq auto-save-interval 20 auto-save-file-name-transforms `((".*" ,auto-save-dir t)))) ;; smart tab behavior - indent or complete (setq tab-always-indent 'complete) ;; revert buffers automatically when underlying files are changed externally (global-auto-revert-mode t) ;; diminish keeps the modeline tidy (use-package diminish) (diminish 'visual-line-mode) ;; Enable mouse support when running in a console (unless window-system (require 'mouse) (xterm-mouse-mode t) (defun track-mouse (e)) (setq mouse-sel-mode t) (global-set-key [mouse-4] (lambda () (interactive) (scroll-down 1))) (global-set-key [mouse-5] (lambda () (interactive) (scroll-up 1))) ;; (global-set-key [mouse-4] 'scroll-down-line) ;; (global-set-key [mouse-5] 'scroll-up-line) ) ;; savehist keeps track of some history (require 'savehist) (setq savehist-additional-variables ;; search entries '(search-ring regexp-search-ring) ;; save every minute savehist-autosave-interval 60 ;; keep the home clean savehist-file (expand-file-name "savehist" siren-cache-dir)) (savehist-mode +1) ;; Recentf (require 'recentf) (setq recentf-save-file (expand-file-name "recentf" siren-cache-dir) recentf-max-saved-items 5000 recentf-max-menu-items 1000 ;; disable recentf-cleanup on Emacs start, because it can cause ;; problems with remote files recentf-auto-cleanup 'never recentf-exclude '("\\.git.*" "\\.hg.*" "\\.svn.*")) (defun siren-recentf-exclude-p (file) "A predicate to decide whether to exclude FILE from recentf." (let ((file-dir (file-truename (file-name-directory file)))) (-any-p (lambda (dir) (string-prefix-p dir file-dir)) (mapcar 'file-truename (list siren-cache-dir package-user-dir))))) (add-to-list 'recentf-exclude 'siren-recentf-exclude-p) (recentf-mode +1) ;; meaningful names for buffers with the same name (require 'uniquify) (setq uniquify-buffer-name-style 'post-forward-angle-brackets uniquify-separator "/" uniquify-after-kill-buffer-p t ; rename after killing uniquified uniquify-ignore-buffers-re "^\\*") ; don't muck with special buffers ;; Display whitespace characters globally (diminish 'whitespace-mode) (diminish 'global-whitespace-mode) (setq whitespace-line-column 80) ;; Customize Whitespace Characters ;; - Newline: \u00AC = ¬ ;; - Tab: \u2192 = → ;; \u00BB = » ;; \u25B6 = ▶ (setq whitespace-display-mappings (quote ((newline-mark ?\n [?\u00AC ?\n] [?$ ?\n]) (tab-mark ?\t [?\u2192 ?\t] [?\u00BB ?\t] [?\\ ?\t])))) (setq whitespace-style (quote (face tabs trailing space-before-tab newline indentation space-after-tab tab-mark newline-mark empty))) ;; enabled change region case commands (put 'upcase-region 'disabled nil) (put 'downcase-region 'disabled nil) ;; automatically indenting yanked text if in programming-modes (defun yank-advised-indent-function (beg end) "Do indentation, as long as the region isn't too large." (if (<= (- end beg) siren-yank-indent-threshold) (indent-region beg end nil))) (defmacro advise-commands (advice-name commands class &rest body) "Apply advice named ADVICE-NAME to multiple COMMANDS. The body of the advice is in BODY." `(progn ,@(mapcar (lambda (command) `(defadvice ,command (,class ,(intern (concat (symbol-name command) "-" advice-name)) activate) ,@body)) commands))) (advise-commands "indent" (yank yank-pop) after "If current mode is one of `siren-yank-indent-modes', indent yanked text (with prefix arg don't indent)." (if (and (not (ad-get-arg 0)) (not (member major-mode siren-indent-sensitive-modes)) (or (derived-mode-p 'prog-mode) (member major-mode siren-yank-indent-modes))) (let ((transient-mark-mode nil)) (yank-advised-indent-function (region-beginning) (region-end))))) ;; make a shell script executable automatically on save (add-hook 'after-save-hook 'executable-make-buffer-file-executable-if-script-p) ;; .zsh file is shell script too (add-to-list 'auto-mode-alist '("\\.zsh\\'" . shell-script-mode)) ;; saner regex syntax (require 're-builder) (setq reb-re-syntax 'string) (provide 'siren-core-editor) ;;; siren-core-editor.el ends here