My Emacs config, and other editor settings
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
6.2 KiB

;; Enable MELPA
(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
(not (gnutls-available-p))))
(proto (if no-ssl "http" "https")))
;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
(add-to-list 'package-archives (cons "melpa" (concat proto "://")) t)
;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://")) t)
(when (< emacs-major-version 24)
;; For important compatibility libraries like cl-lib
(add-to-list 'package-archives '("gnu" . (concat proto "://")))))
;; TODO: Test if melpa still works
;; (package-initialize)
;; Some settings from
;; make cursor movement stop in between camelCase words. (don't)
(global-subword-mode 0)
;; No beeping on windows
(setq ring-bell-function 'ignore)
;; Always highlight matching parenthesis. This is a necessity when using multiple-cursors because
;; if show-paren-mode is disabled, typing multiple closing parentheses takes a long time due to
;; the pause to highlight after each one
(show-paren-mode 1)
;; make typing delete/overwrite selected text
(delete-selection-mode 1)
;; remember cursor position, for emacs 25.1 or later
(save-place-mode 1)
;; Make garbage collection happen less often (
;; (setq gc-cons-threshold 20000000)
;; Another idea:
;; These are tricky: the higher, the more responsive flx ido is, but the slower it takes on minibuffer exit
(defun my-minibuffer-setup-hook ()
;; (setq gc-cons-threshold most-positive-fixnum))
;; (setq gc-cons-threshold 20000000))
(setq gc-cons-threshold 80000000))
(defun my-minibuffer-exit-hook ()
(setq gc-cons-threshold 800000))
(add-hook 'minibuffer-setup-hook #'my-minibuffer-setup-hook)
(add-hook 'minibuffer-exit-hook #'my-minibuffer-exit-hook)
;; stop creating those backup~ files
(setq make-backup-files nil)
;; stop creating those #auto-save# files
(setq auto-save-default nil)
;; Don't create lock files
(setq create-lockfiles nil)
;; Automatically revert buffers if file changes underneath (unless there are unsaved changes)
(global-auto-revert-mode 1)
(defun macoy-kill-transient-buffers ()
"Auto kill buffers which aren't important to let hang around. You shouldn't run this while using things which use these buffers!"
;; TODO: Make sure dependent buffers aren't broken when this happens!
(setq macoy-buffers-to-kill (list
"*Calc Trail*"
"*Ediff Registry*"
"*ag search*"
"*svn output*"
(lambda (buffer-to-kill)
(when (get-buffer buffer-to-kill)
(kill-buffer buffer-to-kill))
;; Store recently closed files so we can easily reopen them
(recentf-mode 1)
;; Smex: Smart M-x completion
(when (require 'smex)
(global-set-key (kbd "M-x") 'smex)
(global-set-key (kbd "M-X") 'smex-major-mode-commands)
;; This is your old M-x.
(global-set-key (kbd "C-M-x") 'execute-extended-command)
;; Ido enable (this might be unnecessary as Emacs comes with it by default now)
(when (require 'ido)
(ido-mode t)
;; Ido display vertically (closer to Sublime)
(ido-vertical-mode 1)
;; Ido vertical use up and down to navigate options, left-right for history/directories
(setq ido-vertical-define-keys 'C-n-C-p-up-down-left-right)
;; Don't try searching other directories when there are no matches
(setq ido-auto-merge-work-directories-length -1)
;; Ido flx settings: make ido have fuzzy sublime-like matching
(when (require 'flx-ido)
(ido-mode 1)
(ido-everywhere 1)
(flx-ido-mode 1)
;; disable ido faces to see flx highlights.
(setq ido-enable-flex-matching t)
(setq ido-use-faces nil)
(setq ido-everywhere t)
;; Use ido for recentf file selection
;; From
(defun ido-recentf-open ()
"Use `ido-completing-read' to \\[find-file] a recent file"
(find-file (ido-completing-read "Find recent file: " recentf-list))
(global-set-key (kbd "C-S-t") 'ido-recentf-open)
;; Projectile: this does "project" stuff like quick find
;; C-p for ctrl-p-like find
(when (require 'projectile)
;; Ignore autogenerated files. Doesn't work. I used customize-group projectile for ignored dirs
;; which can be found near the bottom of this file
(setq projectile-globally-ignored-files
(append '("AutoGen"
(projectile-mode 1)
;; Make projectile mode-line more minimal
(when (string-equal (user-login-name) "macoy")
(defun macoy-projectile-mode-line ()
(format " [%s]" (projectile-project-name))
(setq projectile-mode-line-function 'macoy-projectile-mode-line)
(when (string-equal (user-login-name) "mmadson")
;; Older version syntax
(setq projectile-mode-line '(:eval (format " [%s]" (projectile-project-name))))
;; File-related shortcuts
(when (require 'simpleclip)
(defun macoy-copy-buffer-filename-to-clipboard ()
(simpleclip-set-contents buffer-file-name)
(defun macoy-org-copy-file-line-link-to-clipboard ()
(simpleclip-set-contents (format "[[file:%s::%d][" buffer-file-name (line-number-at-pos)))
;; Open file in explorer
(defun browse-file-directory ()
"Open the current file's directory however the OS would."
(if default-directory
(browse-url-of-file (expand-file-name default-directory))
(error "No `default-directory' to open")))