Skip to content

Instantly share code, notes, and snippets.

@0x17de
Last active January 16, 2017 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0x17de/17d82a9fd19238717439ae1f5860f941 to your computer and use it in GitHub Desktop.
Save 0x17de/17d82a9fd19238717439ae1f5860f941 to your computer and use it in GitHub Desktop.
;;http://ergoemacs.org/emacs/emacs_package_system.html
(when (>= emacs-major-version 24)
(require 'package)
(add-to-list
'package-archives
'("melpa" . "http://melpa.org/packages/")
t)
(package-initialize))
;;initial setup of recommended packages i use
(defun dotemacs-install()
(interactive)
(package-install 'doremi)
(package-install 'doremi-cmd)
(package-install 'doremi-frm)
(package-install 'multiple-cursors)
(package-install 'color-theme-sanityinc-tomorrow))
;;Git diff fix
(setq vc-handled-backends ())
;;Tab fix
;(global-set-key (kbd "TAB") 'insert-tab-char) ; same as Ctrl+i
;(global-set-key (kbd "<tab>") 'insert-tab-char)
;(electric-indent-mode 0)
(global-set-key (kbd "<backtab>") 'insert-tab-char)
;;Tab width
(setq-default indent-tabs-mode nil)
(setq tab-width 4)
(setq default-tab-width 4)
(defvaralias 'c-basic-offset 'tab-width)
(defvaralias 'cperl-indent-level 'tab-width)
;;Diff adjustements
(setq ediff-split-window-function 'split-window-horizontally)
;;/etc/etc-update.conf
;diff_command="emacs-diff %file1 %file2"
;using_editor=1
;merge_command="emacs-merge %orig %new %merged"
(unless (display-graphic-p)
(require 'mouse)
;;http://stackoverflow.com/questions/3466643/emacs-unicode-xterm-mouse-escape-sequences-and-wide-terminals
(xterm-mouse-mode t)
(defun track-mouse (e))
(setq mouse-sel-mode t))
;(mouse-choose-completion)
;;Multi cursor edit
(when (require 'multiple-cursors nil 'noerror)
(global-set-key (kbd "C-M-z C-c") 'mc/edit-lines)
(global-set-key (kbd "C-M-z >") 'mc/mark-next-like-this)
(global-set-key (kbd "C-M-z <") 'mc/mark-previous-like-this)
(global-set-key (kbd "C-M-z |") 'mc/mark-all-like-this)
(global-unset-key (kbd "M-<down-mouse-1>"))
(global-set-key (kbd "M-<mouse-1>") 'mc/add-cursor-on-click))
;;Mouse scroll
(defun up-slightly () (interactive) (scroll-up 5))
(defun down-slightly () (interactive) (scroll-down 5))
(global-set-key [mouse-4] 'down-slightly)
(global-set-key [mouse-5] 'up-slightly)
;;Auto indentation
(add-to-list 'load-path "guess-style")
(autoload 'guess-style-set-variable "guess-style" nil t)
(autoload 'guess-style-guess-variable "guess-style")
(autoload 'guess-style-guess-all "guess-style" nil t)
;(setq-default tab-always-indent nil)
;;No splash screen
(setq inhibit-startup-message t)
;;Selection/Clipboard improvements
(delete-selection-mode t)
(transient-mark-mode t)
(setq x-select-enable-clipboard t)
(setq mouse-yank-at-point t)
;(setq interprogram-paste-function 'x-cut-buffer-or-selection-value)
;;Disable bars
(when (display-graphic-p)
(scroll-bar-mode -1)
(tool-bar-mode -1))
(menu-bar-mode -1)
;;No backup files
(setq make-backup-files nil)
(setq auto-save-default nil)
;;Yes or no short
(defalias 'yes-or-no-p 'y-or-n-p)
(setq icomplete-mode t)
;(setq completion-cycle-threshold t)"
(setq completion-auto-help t)
;;Just kill buffer without asking
(global-set-key [(control x) (k)] 'kill-this-buffer)
;;Show matching parentheses
(show-paren-mode 1)
(setq show-paren-delay 0)
;(when
;(require 'auto-complete-c-headers)
;(add-to-list 'ac-sources 'ac-source-c-headers)
;;Compile functions
(defun compile-cmake ()
"Compile a project in the tree"
(interactive)
(let* ((default-directory (or (upward-find-dir "build") "."))
(compile-command (concat "cd " default-directory " && " compile-command " -C build")))
(compile compile-command)))
(defun compile-make ()
"Compile a project in the tree"
(interactive)
(let* ((default-directory (or (upward-find-file "Makefile") "."))
(compile-command (concat "cd " default-directory " && " compile-command)))
(compile compile-command)))
(defun compile-policy ()
(interactive)
(let* ((compile-command (concat compile-command " && semodule -i " (replace-regexp-in-string "\.\\(te\\|if\\|fc\\)$" ".pp" buffer-file-name))))
(compile compile-command)))
;;Compile hotkeys
(global-set-key (kbd "C-M-z C-a") 'compile-cmake)
(global-set-key (kbd "C-M-z C-M-a") 'compile-make)
(global-set-key (kbd "C-M-z C-s") 'compile-policy)
;;Helper functions
(defun insert-tab-char ()
"insert a tab char. (ASCII 9, \t)"
(interactive)
(insert "\t"))
(defun defguard (guard)
"Inserts guard header for C++"
(interactive "sGuard name: ")
(save-excursion
(beginning-of-buffer)
(insert (concat "#ifndef " (upcase guard) "_H\n#define " (upcase guard) "_H\n\n"))
(end-of-buffer)
(insert "\n#endif")
(jump-to-register)))
(defun upward-find-dir (filename &optional startdir)
"Move up directories until we find a certain filename. If we
manage to find it, return the containing directory. Else if we
get to the toplevel directory and still can't find it, return
nil. Start at startdir or . if startdir not given"
(let ((dirname (expand-file-name
(if startdir startdir ".")))
(found nil) ; found is set as a flag to leave loop if we find it
(top nil)) ; top is set when we get
; to / so that we only check it once
; While we've neither been at the top last time nor have we found
; the file.
(while (not (or found top))
; If we're at / set top flag.
(if (string= (expand-file-name dirname) "/")
(setq top t))
; Check for the file
(if (file-directory-p (expand-file-name filename dirname))
(setq found t)
; If not, move up a directory
(setq dirname (expand-file-name ".." dirname))))
; return statement
(if found dirname nil)))
(defun upward-find-file (filename &optional startdir)
"Move up directories until we find a certain filename. If we
manage to find it, return the containing directory. Else if we
get to the toplevel directory and still can't find it, return
nil. Start at startdir or . if startdir not given"
(let ((dirname (expand-file-name
(if startdir startdir ".")))
(found nil) ; found is set as a flag to leave loop if we find it
(top nil)) ; top is set when we get
; to / so that we only check it once
; While we've neither been at the top last time nor have we found
; the file.
(while (not (or found top))
; If we're at / set top flag.
(if (string= (expand-file-name dirname) "/")
(setq top t))
; Check for the file
(if (file-exists-p (expand-file-name filename dirname))
(setq found t)
; If not, move up a directory
(setq dirname (expand-file-name ".." dirname))))
; return statement
(if found dirname nil)))
(setq *is-a-mac* (eq system-type 'darwin))
(setq *cygwin* (eq system-type 'cygwin) )
(setq *linux* (or (eq system-type 'gnu/linux) (eq system-type 'linux)) )
(defun copy-to-x-clipboard ()
(interactive)
(if (region-active-p)
(progn
(cond
((and (display-graphic-p) x-select-enable-clipboard)
(x-set-selection 'CLIPBOARD (buffer-substring (region-beginning) (region-end))))
(t (shell-command-on-region (region-beginning) (region-end)
(cond
(*cygwin* "putclip")
(*is-a-mac* "pbcopy")
(*linux* "xsel -ib")))
))
(message "Yanked region to clipboard!")
(deactivate-mark))
(message "No region active; can't yank to clipboard!")))
(defun paste-from-x-primary()
(interactive)
(cond
((and (display-graphic-p) x-select-enable-clipboard)
(insert (x-get-selection 'CLIPBOARD)))
(t (shell-command
(cond
(*cygwin* "getclip")
(*is-a-mac* "pbpaste")
(t "xsel -op"))
1))
))
(defun paste-from-x-clipboard()
(interactive)
(cond
((and (display-graphic-p) x-select-enable-clipboard)
(insert (x-get-selection 'CLIPBOARD)))
(t (shell-command
(cond
(*cygwin* "getclip")
(*is-a-mac* "pbpaste")
(t "xsel -ob"))
1))
))
;(defun x-get-selection-internal(x)
; (paste-from-x-primary x))
(defun my/paste-in-minibuffer ()
(local-set-key (kbd "M-y") 'paste-from-x-clipboard)
)
(add-hook 'minibuffer-setup-hook 'my/paste-in-minibuffer)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(ansi-color-faces-vector
[default default default italic underline success warning error])
'(ansi-color-names-vector
["#242424" "#e5786d" "#95e454" "#cae682" "#8ac6f2" "#333366" "#ccaa8f" "#f6f3e8"])
'(custom-enabled-themes (quote (sanityinc-tomorrow-bright)))
'(custom-safe-themes
(quote
("1b8d67b43ff1723960eb5e0cba512a2c7a2ad544ddb2533a90101fd1852b426e" default)))
'(dired-mode-hook (quote (dired-hide-details-mode)))
'(show-paren-mode t))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((t (:height 76 :width semi-condensed)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment