Skip to content

Instantly share code, notes, and snippets.

@saptarshiguha
Created February 2, 2017 08:11
Show Gist options
  • Save saptarshiguha/3124abcb3cd5a5f294718af761a1eabd to your computer and use it in GitHub Desktop.
Save saptarshiguha/3124abcb3cd5a5f294718af761a1eabd to your computer and use it in GitHub Desktop.
;; load paths
;; http://zmjones.com/mac-setup.html
(setq mac-option-key-is-meta nil)
(setq mac-option-modifier 'alt)
(server-start)
;; For loading packages installed via package.el
;; see http://stackoverflow.com/questions/11127109/emacs-24-package-system-initialization-problems/11140619#11140619
(setq package-enable-at-startup nil)
(package-initialize)
(custom-set-variables '(package-archives
(quote
(
;; ("marmalade" . "http://marmalade-repo.org/packages/")
("melpa" . "http://melpa.org/packages/")
("gnu" . "http://elpa.gnu.org/packages/")))))
;; (let ((default-directory "~/.emacs.d/"))
;; (normal-top-level-add-subdirs-to-load-path))
(setq mybase "~/mystuff")
(setq load-path (cons (expand-file-name (format "%s/site-lisp" mybase)) load-path))
(set-face-attribute 'mode-line nil :height 140)
(setq ispell-program-name "/usr/local/bin/aspell")
(eval-when-compile
(require 'use-package))
(require 'diminish) ;; if you use :diminish
(require 'bind-key)
(add-hook 'markdown-mode-hook
(lambda ()
(when buffer-file-name
(add-hook 'after-save-hook
'check-parens
nil t))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; recentf
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;(run-at-time nil (* 5 60) 'recentf-save-list)
(setq recentf-max-saved-items 150)
(setq recentf-max-menu-items 75)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Matching Parentheses
;; see http://emacs-fu.blogspot.com/2009/01/balancing-your-parentheses.html
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq frame-title-format '("Emacs " "%b"))
(if window-system
(tool-bar-mode 1))
(setq make-backup-files nil)
(global-set-key (kbd "C-c o") 'occur)
(setq savehist-additional-variables ;; also save...
'(search-ring regexp-search-ring) ;; my search entries
savehist-file "~/.emacs.d/savehist") ;; keep my home clean
(savehist-mode t)
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; Add FLyspell Mode to org-mode ;;
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq org-src-fontify-natively t)
(dolist (hook '(org-mode-hook))
(add-hook hook (lambda () (flyspell-mode 1) (wc-mode)) )
(set 'split-height-threshold 80))
(defface org-block-background
'((t (:background "#FFFFEA")))
"Face used for the source block background.")
(require 'org)
(setq flyspell-issue-message-flag nil)
(global-set-key (kbd "C-x 8") 'flyspell-check-previous-highlighted-word)
;;-------------------------------------------------------------------------------
;; tabs as spaces
;;------------------------------------------------------------------------------
(setq-default indent-tabs-mode nil)
;;;;;;;;;;;;;;;;;;;;;;;
;; Bookmark Handling ;;
;;;;;;;;;;;;;;;;;;;;;;;
(require 'bm)
(global-set-key (kbd "M-'") 'bm-toggle)
(global-set-key (kbd "M-\"") 'bm-next)
;;(global-set-key (kbd "s-\"") 'bm-previous)
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;; Usage Notes
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; C-M b (move backward to beginning of paranthesis pair)
;; C-M f (move forward)
;; (load "~/mystuff/site-lisp/myESScode.el")
(require 'ess)
(require 'ess-site)
(require 'helm)
(use-package helm-swoop
:bind (("M-i" . helm-swoop)
("M-I" . helm-swoop-back-to-last-point)
("C-c M-i" . helm-multi-swoop))
:config
;; When doing isearch, hand the word over to helm-swoop
(define-key isearch-mode-map (kbd "M-i") 'helm-swoop-from-isearch)
;; From helm-swoop to helm-multi-swoop-all
(define-key helm-swoop-map (kbd "M-i") 'helm-multi-swoop-all-from-helm-swoop)
;; Save buffer when helm-multi-swoop-edit complete
(setq helm-multi-swoop-edit-save t
;; If this value is t, split window inside the current window
helm-swoop-split-with-multiple-windows t
;; Split direcion. 'split-window-vertically or 'split-window-horizontally
helm-swoop-split-direction 'split-window-vertically
;; If nil, you can slightly boost invoke speed in exchange for text color
helm-swoop-speed-or-color nil))
;; see https://writequit.org/org/
;; (helm-mode t)
(require 'helm-dired-recent-dirs)
(setq helm-ff-file-name-history-use-recentf t
helm-buffers-fuzzy-matching t
helm-everywhere t
helm-autoresize-mode t
helm-recentf-fuzzy-match t)
(setq helm-mini-default-sources '(helm-source-buffers-list
helm-source-dired-recent-dirs
helm-source-recentf
helm-source-buffer-not-found))
;; (global-set-key (kbd "C-x b") 'helm-buffers-list)
(load (format "%s/site-lisp/prelude-helm.el" mybase))
(load (format "%s/site-lisp/prelude-helm-everywhere.el" mybase))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; proper commenting and stuff like aquamacs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun comment-or-uncomment-region-or-line ()
"Comments or uncomments the region or the current line if there's no active region."
(interactive)
(let (beg end)
(if (region-active-p)
(setq beg (region-beginning) end (region-end))
(setq beg (line-beginning-position) end (line-end-position)))
(comment-or-uncomment-region beg end)
(next-line)))
(global-set-key (kbd "s-;") 'comment-or-uncomment-region-or-line)
(defun new-empty-buffer ()
"Opens a new empty buffer."
(interactive)
(let ((buf (generate-new-buffer "untitled")))
(let ((mode major-mode))
(message "Mode is %s" mode)
(switch-to-buffer buf)
(funcall mode))
(setq buffer-offer-save t)))
(global-set-key (kbd "M-t") 'new-empty-buffer )
;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Edit server
;;;;;;;;;;;;;;;;;;;;;;;;;
;;(server-start)
(add-to-list 'auto-mode-alist '("md$" . markdown-mode))
(add-hook 'markdown-mode-hook (lambda()
(set-fill-column 80)
(auto-fill-mode 1)
(flyspell-mode 1)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Lua Mode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(require 'lua-mode)
(autoload 'lua-mode "lua-mode" "Lua editing mode." t)
(add-to-list 'auto-mode-alist '("\\.lua$" . lua-mode));
(add-to-list 'auto-mode-alist '("\\.t$" . lua-mode))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Send selection to current tab in terminal
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun send-region-to-current-tab-R-app ()
"Comments or uncomments the region or the current line if there's no active region."
(interactive)
(kill-ring-save (region-beginning) (region-end))
;; (ns-copy-including-secondary)
(shell-command (format "osascript %s/programming/sendRegionToIterm.scpt" mybase))
(goto-char (region-end))
)
(defun send-region-to-current-tab-Ipython-app ()
"Comments or uncomments the region or the current line if there's no active region."
(interactive)
(kill-ring-save (region-beginning) (region-end))
;; (ns-copy-including-secondary)
(shell-command (format "osascript %s/programming/sendRegionToItermIPython.scpt" mybase))
(goto-char (region-end))
)
(global-set-key (kbd "C-x ,") 'send-region-to-current-tab-R-app)
(global-set-key (kbd "C-x /") 'send-region-to-current-tab-Ipython-app)
;;(global-set-key (kbd "s-<return>") 'send-region-to-current-tab-chrome-app)
;; (define-key input-decode-map "\e\eOA" [(meta up)])
;; (define-key input-decode-map "\e\eOB" [(meta down)])
;;https://github.com/tonsky/FiraCode/wiki/Setting-up-Emacs
(when (window-system)
(menu-bar-mode -1)
(tool-bar-mode -1)
(set-default-font "Fira Code"))
(let ((alist '((33 . ".\\(?:\\(?:==\\)\\|[!=]\\)")
(35 . ".\\(?:[(?[_{]\\)")
(38 . ".\\(?:\\(?:&&\\)\\|&\\)")
(42 . ".\\(?:\\(?:\\*\\*\\)\\|[*/]\\)")
(43 . ".\\(?:\\(?:\\+\\+\\)\\|\\+\\)")
(45 . ".\\(?:\\(?:-[>-]\\|<<\\|>>\\)\\|[<>}~-]\\)")
(46 . ".\\(?:\\(?:\\.[.<]\\)\\|[.=]\\)")
(47 . ".\\(?:\\(?:\\*\\*\\|//\\|==\\)\\|[*/=>]\\)")
(58 . ".\\(?:[:=]\\)")
(59 . ".\\(?:;\\)")
(60 . ".\\(?:\\(?:!--\\)\\|\\(?:\\$>\\|\\*>\\|\\+>\\|--\\|<[<=-]\\|=[<=>]\\||>\\)\\|[/<=>|-]\\)")
(61 . ".\\(?:\\(?:/=\\|:=\\|<<\\|=[=>]\\|>>\\)\\|[<=>~]\\)")
(62 . ".\\(?:\\(?:=>\\|>[=>-]\\)\\|[=>-]\\)")
(63 . ".\\(?:[:=?]\\)")
(92 . ".\\(?:\\(?:\\\\\\\\\\)\\|\\\\\\)")
(94 . ".\\(?:=\\)")
(123 . ".\\(?:-\\)")
(124 . ".\\(?:\\(?:|[=|]\\)\\|[=>|]\\)")
(126 . ".\\(?:[=@~-]\\)")
)
))
(dolist (char-regexp alist)
(set-char-table-range composition-function-table (car char-regexp)
`([,(cdr char-regexp) 0 font-shape-gstring]))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Web Mode for HTML because plain HTML SUCKS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-to-list 'auto-mode-alist '("\\.html?\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.css?\\'" . web-mode))
(defun my-web-mode-hook ()
"Hooks for Web mode."
(setq web-mode-markup-indent-offset 2)
(setq web-mode-css-indent-offset 2)
(setq web-mode-code-indent-offset 2)
(setq web-mode-enable-css-colorization t)
(setq web-mode-enable-block-face t)
(setq web-mode-enable-comment-keywords t)
(setq web-mode-enable-current-element-highlight t)
(setq web-mode-enable-current-column-highlight t)
)
(add-hook 'web-mode-hook 'my-web-mode-hook)
;; ample theme: https://github.com/jordonbiondo/ample-theme
;; zenburn: https://github.com/bbatsov/zenburn-emacs
;;(require 'color-theme)
;;(color-theme-initialize)
;;(load-theme 'leuven t)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Rust
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Enable company globally for all mode
;; (global-company-mode )
;; Reduce the time after which the company auto completion popup opens
;; (setq company-idle-delay 0.2)
;; Reduce the number of characters before company kicks in
;; (setq company-minimum-prefix-length 1)
;; Set path to racer binary
(setq racer-cmd "/Users/sguha/.cargo/bin/racer")
;; Set path to rust src directory
(setq racer-rust-src-path "/Users/sguha/rust/rust/src")
;; Load rust-mode when you open `.rs` files
(add-to-list 'auto-mode-alist '("\\.rs\\'" . rust-mode))
;; Setting up configurations when you load rust-mode
(add-hook 'rust-mode-hook
'(lambda ()
;; Enable racer
(racer-activate)
;; Hook in racer with eldoc to provide documentation
(racer-turn-on-eldoc)
;; Use flycheck-rust in rust-mode
(add-hook 'flycheck-mode-hook #'flycheck-rust-setup)
;; Use company-racer in rust mode
(set (make-local-variable 'company-backends) '(company-racer))
;; Key binding to jump to method definition
(local-set-key (kbd "M-.") #'racer-find-definition)
;; Key binding to auto complete and indent
(local-set-key (kbd "TAB") #'racer-complete-or-indent)))
(delete-selection-mode 1)
(message "Saptarshi has loaded")
;; see https://www.emacswiki.org/emacs/Comments_on_CopyAndPaste
;;(global-set-key "\C-w" 'clipboard-kill-region)
;;(global-set-key "\M-w" 'clipboard-kill-ring-save)
;;(global-set-key "\C-y" 'clipboard-yank)
(show-paren-mode 1)
(use-package undo-tree
:init (global-undo-tree-mode t)
:defer t
:diminish ""
:config
(progn
(define-key undo-tree-map (kbd "C-x u") 'undo-tree-visualize)
(define-key undo-tree-map (kbd "C-/") 'undo-tree-undo)))
(use-package ido
:config
(use-package ido-ubiquitous)
(use-package flx-ido
:init (flx-ido-mode 1)
:config (setq ido-use-faces nil))
(use-package ido-vertical-mode
:init (ido-vertical-mode t))
(setq ido-use-virtual-buffers nil
;; this setting causes weird TRAMP connections, don't set it!
;;ido-enable-tramp-completion nil
ido-enable-flex-matching t
ido-auto-merge-work-directories-length nil
ido-create-new-buffer 'always
ido-use-filename-at-point 'guess
ido-max-prospects 10))
(use-package multiple-cursors
:bind (("C-S-c C-S-c" . mc/edit-lines)
("C->" . mc/mark-next-like-this)
("C-<" . mc/mark-previous-like-this)
("C-c C-<" . mc/mark-all-like-this)))
(defun beautify-json ()
(interactive)
(let ((b (if mark-active (min (point) (mark)) (point-min)))
(e (if mark-active (max (point) (mark)) (point-max))))
(shell-command-on-region b e "python -mjson.tool" (current-buffer) t)))
(defun xah-forward-block (&optional φn)
"Move cursor forward to the beginning of next text block.
A text block is separated by blank lines. In most major modes,
this is similar to `forward-paragraph', but this command's
behavior is the same regardless of syntax table."
(interactive "p")
(search-forward-regexp "\n[\t\n ]*\n+" nil "NOERROR" φn))
(defun xah-backward-block (&optional φn)
"Move cursor backward to previous text block.
See: `xah-forward-block'"
(interactive "p")
(dotimes (ξn φn) (if (search-backward-regexp "\n[\t\n ]*\n+" nil "NOERROR")
(progn
(skip-chars-backward "\n\t "))
(progn (goto-char (point-min))))))
(global-set-key (kbd "<C-up>") 'xah-backward-block)
(global-set-key (kbd "<C-down>") 'xah-forward-block)
;;Use M-{ and M-} to activate the abbove(opt+shift+{)
(defun copy-from-osx ()
(shell-command-to-string "pbpaste"))
(defun paste-to-osx (text &optional push)
(let ((process-connection-type nil))
(let ((proc (start-process "pbcopy" "*Messages*" "pbcopy")))
(process-send-string proc text)
(process-send-eof proc))))
(if (eq system-type 'darwin)
(
(setq interprogram-cut-function 'paste-to-osx)
(setq interprogram-paste-function 'copy-from-osx)
(setq save-interprogram-paste-before-kill t)
))
;;(setq x-select-enable-clipboard t)
(require 'gist)
(set-face-attribute 'fringe nil
:foreground (face-foreground 'default)
:background (face-background 'default))
(require 'poly-R)
(require 'poly-markdown)
(add-to-list 'auto-mode-alist '("\\.md" . poly-markdown-mode))
(add-to-list 'auto-mode-alist '("\\.Snw" . poly-noweb+r-mode))
(add-to-list 'auto-mode-alist '("\\.Rnw" . poly-noweb+r-mode))
(add-to-list 'auto-mode-alist '("\\.Rmd" . poly-markdown+r-mode))
(add-to-list 'ibuffer-never-show-predicates ".*\\[.*\\]$")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment