SHARE
TWEET

square bracket problem config

a guest May 9th, 2017 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;; the package manager and use-package
  2. (require 'package)
  3. (setq
  4.  package-archives '(("gnu" . "http://elpa.gnu.org/packages/")
  5.             ("org" . "http://orgmode.org/elpa/")
  6.             ("melpa" . "http://melpa.org/packages/")
  7.             ("melpa-stable" . "http://stable.melpa.org/packages/"))
  8.  package-archive-priorities '(("melpa-stable" . 1)))
  9.  
  10. (package-initialize)
  11.  
  12. (unless (package-installed-p 'use-package)
  13.   (package-refresh-contents)
  14.   (package-install 'use-package))
  15.  
  16. (eval-when-compile
  17.   (require 'use-package))
  18. (require 'diminish)
  19. (require 'bind-key)
  20.  
  21. ;; use-package always auto install packages
  22. (setq use-package-always-ensure t)
  23.  
  24. ;;; look & feel
  25. (setq-default mode-line-mule-info nil)
  26. (setq-default mode-line-modified nil)
  27. (setq-default mode-line-position nil)
  28. (setq-default mode-line-remote nil)
  29. (setq-default mode-line-client nil)
  30. (setq-default mode-line-frame-identification nil)
  31.  
  32. (use-package all-the-icons)
  33. (use-package neotree
  34.   :bind
  35.   (("C-c d" . neotree-toggle))
  36.   :config
  37.   (add-hook 'neotree-mode-hook 'evil-insert-state))
  38. (use-package nlinum)
  39.  
  40. (use-package doom-themes
  41.   :pin melpa
  42.   :diminish doom-buffer-mode
  43.   :init
  44.   :config
  45.   (load-theme 'doom-molokai t)
  46.   (tool-bar-mode -1)
  47.   (menu-bar-mode -1)
  48.   (scroll-bar-mode -1)
  49.   (line-number-mode -1)
  50.   (size-indication-mode -1)
  51.   ;; font is 1/10 of height
  52.   (set-face-attribute 'default nil :height 80)
  53.   ;;; i3-like mouse hover effect
  54.   (setq mouse-autoselect-window t)
  55.   ;;; Settings (defaults)
  56.   (setq doom-enable-bold nil    ; if nil, bolding are universally disabled
  57.     doom-enable-italic t  ; if nil, italics are universally disabled
  58.     ;; doom-one specific settings
  59.     doom-one-brighter-modeline nil
  60.     doom-one-brighter-comments nil)
  61.   ;;; OPTIONAL
  62.   ;; brighter source buffers (that represent files)
  63.   (add-hook 'find-file-hook 'doom-buffer-mode-maybe)
  64.   ;; ...if you use auto-revert-mode
  65.   (add-hook 'after-revert-hook 'doom-buffer-mode-maybe)
  66.   ;; And you can brighten other buffers (unconditionally) with:
  67.   (add-hook 'ediff-prepare-buffer-hook 'doom-buffer-mode)
  68.   ;; brighter minibuffer when active
  69.   (add-hook 'minibuffer-setup-hook 'doom-brighten-minibuffer)
  70.   ;; Enable custom neotree theme
  71.   (doom-themes-neotree-config)  ; all-the-icons fonts must be installed!
  72.   ;; Enable nlinum line highlighting
  73.   (doom-themes-nlinum-config)   ; requires nlinum and hl-line-mode
  74.   ;; Necessary for org-mode
  75.   (setq org-fontify-whole-heading-line t
  76.     org-fontify-done-headline t
  77.     org-fontify-quote-and-verse-blocks t))
  78.  
  79. ;;; automatic custom variables
  80. (setq custom-file "~/.emacs.d/custom.el")
  81. (load custom-file)
  82.  
  83. ;; backup and auto-save
  84. (setq backup-directory-alist
  85.       `(("." . ,(expand-file-name
  86.                  (concat user-emacs-directory "backup")))))
  87. (setq auto-save-file-name-transforms
  88.           `((".*" ,(concat user-emacs-directory "auto-save/") t))) (setq auto-save-interval 20)
  89. (setq auto-save-timeout 10)
  90. (setq desktop-auto-save-timeout 10)
  91. (desktop-save-mode 1)
  92. (setq delete-old-versions t
  93.   kept-new-versions 6
  94.   kept-old-versions 2
  95.   version-control t)
  96.  
  97. (use-package simple
  98.   :ensure nil
  99.   :bind
  100.   (("C-c v" . visual-line-mode)))
  101.  
  102. (use-package evil
  103.   :init
  104.   (setq evil-normal-state-tag "")
  105.   ;; separate sentences by one space
  106.   (setq sentence-end-double-space nil)
  107.   ;; paste from x clipboard in visual mode
  108.   (fset 'evil-visual-update-x-selection 'ignore)
  109.   :bind
  110.   (:map evil-normal-state-map
  111.     ("M-." . nil)
  112.     ("C-k" . my-evil-scroll-up)
  113.     ("C-j" . my-evil-scroll-down)
  114.     ("C-t" . transpose-chars)
  115.     ("K" . my-evil-split-line)
  116.     ("C-v" . scroll-up-command)
  117.     ("C-S-v" . evil-visual-block)
  118.     ("C-n" . evil-next-line)
  119.     ("C-p" . evil-previous-line)
  120.    :map evil-insert-state-map
  121.    ("C-t" . transpose-chars)
  122.    :map evil-motion-state-map
  123.    ("$" . evil-last-non-blank)
  124.    ("g_" . evil-end-of-line)
  125.    ("C-]" . nil) ;; for avy to use
  126.    ("C-v" . scroll-up-command))
  127.   :config
  128.   (defun my-evil-scroll-up ()
  129.     (interactive)
  130.     (evil-scroll-up nil))
  131.   (defun my-evil-scroll-down ()
  132.     (interactive)
  133.     (evil-scroll-down nil))
  134.   (defun my-evil-split-line ()
  135.     (interactive)
  136.     (kbd "r RET"))
  137.   (evil-define-key 'normal term-raw-map "p" 'term-paste)
  138.   (evil-define-key 'normal term-raw-map "j" 'term-send-down)
  139.   (evil-define-key 'normal term-raw-map "k" 'term-send-up)
  140.   (evil-define-key 'normal term-raw-map (kbd "RET") 'term-send-raw)
  141.   (evil-define-key 'normal term-raw-map (kbd "C-r") 'term-send-raw)
  142.   (evil-define-key 'normal term-raw-map (kbd "C-c") 'term-send-raw)
  143.   (add-hook 'emacs-lisp-mode-hook
  144.     (function (lambda ()
  145.         (setq evil-shift-width 2))))
  146.   (evil-mode 1))
  147.  
  148. (use-package evil-surround
  149.   :config
  150.   (global-evil-surround-mode 1))
  151.  
  152. (defun sync-init-el-on-save ()
  153.   "Sync .dotfiles/.emacs.d/init.el after save."
  154.   (when (eq major-mode 'emacs-lisp-mode)
  155.     (call-process "~/.dotfiles/.sync.sh")))
  156. (add-hook 'after-save-hook #'sync-init-el-on-save)
  157.  
  158. ;;; Auctex and pdf-tools
  159. (use-package tex
  160.   :ensure auctex
  161.   :config
  162.   (defun recompile-pdf-on-save ()
  163.     "Recompile latex on save with external script."
  164.     (when (eq major-mode 'latex-mode)
  165.       (call-process "~/.config/scripts/recompile-masters-thesis.sh")))
  166.   (add-hook 'after-save-hook #'recompile-pdf-on-save)
  167.   (add-hook 'LaTeX-mode-hook 'flyspell-mode))
  168.  
  169. (use-package flyspell
  170.   :bind
  171.   (:map flyspell-mode-map
  172.    ("C-:" . flyspell-save-word))
  173.   :config
  174.   (defun flyspell-save-word ()
  175.     "Save word to personal dictionary."
  176.     (interactive)
  177.     (let ((current-location (point))
  178.       (word (flyspell-get-word)))
  179.       (when (consp word)    
  180.     (flyspell-do-correct 'save nil (car word) current-location (cadr word) (caddr word) current-location)))))
  181.  
  182. (use-package openwith
  183.   :init
  184.   (setq openwith-associations '(("\\.pdf\\'" "okular" (file))))
  185.   :config
  186.   (openwith-mode t))
  187.  
  188. (use-package reftex
  189.   :diminish reftex-mode
  190.   :init
  191.   (setq reftex-plug-into-AUCTeX t)
  192.   :init
  193.   (add-hook 'LaTeX-mode-hook 'turn-on-reftex))
  194.  
  195. ;; line numbers
  196. (use-package linum-relative
  197.   :diminish linum-relative-mode
  198.   :init
  199.   (setq linum-relative-current-symbol "")
  200.   :config
  201.   (global-linum-mode t)
  202.   (linum-relative-on))
  203.  
  204. ;;; org mode
  205. (use-package org
  206.   :init
  207.   (setq org-clock-persist 'history)
  208.   (setq calendar-week-start-day 1)
  209.   (setq org-startup-truncated 'nil)
  210.   (setq org-agenda-start-with-log-mode t)
  211.   (setq org-capture-templates
  212.       '(("a" "Appointment" entry (file  "~/org/calendar.org" )
  213.      "* %?\n%^T")
  214.     ("p" "Personal journal" entry (file "~/org/personal-journal.org") "* %T %?")
  215.     ("t" "To do" entry (file "~/org/todo.org")
  216.      "* TODO %?" :prepend t)
  217.     ("l" "Laptop config" entry (file "~/org/laptop-config.org")
  218.      "* TODO %?" :prepend t)
  219.     ("m" "Miracle morning" entry (file "~/org/miracle-morning.org")
  220.      "* miracle morning\nmm%?" :unnarrowed t :clock-in t :clock-resume t)
  221.     ("e" "Miracle evening" entry (file "~/org/miracle-evening.org")
  222.      "* miracle evening\n  %?" :unnarrowed t :clock-in t :clock-resume t)
  223.     ("w" "Weekly summary" entry (file "~/org/weekly-summary.org")
  224.      "* weekly summary\nws%?" :unnarrowed t :clock-in t :clock-resume t)
  225.     ("D" "Dance notes" entry (file "~/org/dance-notes.org")
  226.      "* %?" :unnarrowed t :clock-in t :clock-resume t)
  227.     ("d" "Diet")
  228.     ("dw" "Weight" entry (file "~/org/diet-scores.org")
  229.      "* %t waga %?" :unnarrowed t)
  230.     ("ds" "Score" plain (file "~/org/diet-scores.org")
  231.      "* %t ocena %?" :unnarrowed t)
  232.     ))
  233.   :bind
  234.   (("C-c C-x C-j" . org-clock-goto)
  235.   ("C-c C-x C-i" . org-clock-in)
  236.   ("C-c C-x C-o" . org-clock-out)
  237.   ("C-C C-x C-e" . org-clock-modify-effort-estimate)
  238.   ("C-c C-x C-q" . org-clock-cancel)
  239.   ("\C-cl" . org-store-link)
  240.   ("\C-ca" . org-agenda)
  241.   ("\C-cc" . org-capture)
  242.   ("\C-cb" . org-iswitchb)
  243.   :map org-mode-map
  244.   ("M-TAB" . org-global-cycle)
  245.   ("\M-q" . toggle-truncate-lines))
  246.   :config
  247.   (unbind-key "C-'" org-mode-map) ;; for avy to use
  248.   (unbind-key "C-]" org-mode-map) ;; for avy to use
  249.   (defun org-summary-todo (n-done n-not-done)
  250.     "Switch entry to DONE when all subentries are done, to TODO otherwise."
  251.     (let (org-log-done org-log-states)   ; turn off logging
  252.       (org-todo (if (= n-not-done 0) "DONE" "TODO"))))
  253.   (add-hook 'org-after-todo-statistics-hook 'org-summary-todo)
  254.   (org-clock-persistence-insinuate)
  255.   (add-hook 'org-capture-mode-hook 'evil-insert-state)
  256.   (add-hook 'org-agenda-mode-hook (lambda () (org-gcal-sync) )))
  257.  
  258. (use-package org-bullets
  259.   :config
  260.   (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1))))
  261.  
  262. (use-package org-gcal
  263.   :pin melpa
  264.   :init
  265.   (load "~/.emacs.d/org-gcal-credentials.el")
  266.   (setq org-gcal-up-days 7) ; before today
  267.   (setq org-gcal-down-days 7)) ; after today
  268.  
  269. ;; smart partentheses
  270. (use-package smartparens
  271.   :diminish smartparens-mode
  272.   :commands
  273.   smartparens-strict-mode
  274.   smartparens-mode
  275.   sp-restrict-to-pairs-interactive
  276.   sp-local-pair
  277.   :init
  278.   (setq sp-interactive-dwim t)
  279.   :config
  280.   (require 'smartparens-config)
  281.   (sp-use-smartparens-bindings)
  282.   (sp-pair "(" ")" :wrap "C-(") ;; how do people live without this?
  283.   (sp-pair "[" "]" :wrap "s-[") ;; C-[ sends ESC
  284.   (sp-pair "{" "}" :wrap "C-{")
  285.   ;; WORKAROUND https://github.com/Fuco1/smartparens/issues/543
  286.   (bind-key "C-<left>" nil smartparens-mode-map)
  287.   (bind-key "C-<right>" nil smartparens-mode-map)
  288.   (bind-key "s-<delete>" 'sp-kill-sexp smartparens-mode-map)
  289.   (bind-key "s-<backspace>" 'sp-backward-kill-sexp smartparens-mode-map)
  290.   (show-smartparens-global-mode))
  291.  
  292. ;; scala
  293. (use-package scala-mode
  294.   :defer t
  295.   :pin melpa
  296.   :init
  297.   (setq
  298.    scala-indent:use-javadoc-style t
  299.    scala-indent:align-parameters t)
  300.   :config
  301.  
  302.   ;; prefer smartparens for parens handling
  303.   (remove-hook 'post-self-insert-hook
  304.                'scala-indent:indent-on-parentheses)
  305.   (sp-local-pair 'scala-mode "(" nil :post-handlers '(("||\n[i]" "RET")))
  306.   (sp-local-pair 'scala-mode "{" nil
  307.                :post-handlers '(("||\n[i]" "RET")
  308.                                 ("| " "SPC"))))
  309.  
  310. (use-package expand-region)
  311.  
  312. (use-package company
  313.   :diminish company-mode)
  314.  
  315. (use-package ensime
  316.   :pin melpa-stable
  317.   :diminish ensime-mode
  318.   :init
  319.   :config
  320.   (require 'ensime-expand-region))
  321.  
  322. ;; scala-mode hooks
  323. (add-hook 'scala-mode-hook
  324.           (lambda ()
  325.             (show-paren-mode t)
  326.             (smartparens-mode t)
  327.         (ensime-mode t)
  328.         (scala-mode:goto-start-of-code)))
  329.  
  330. (use-package magit
  331.   :init
  332.   (setq-default vc-handled-backends nil)
  333.   (setq-default vc-mode nil)
  334.   :config
  335.   (setq magit-completing-read-function 'ivy-completing-read)
  336.   :bind
  337.   ("C-x g" . magit-status)
  338.   ("C-x M-g" . magit-dispatch-popup))
  339.  
  340. (defun hook-diminish-auto-revert ()
  341.   (interactive)
  342.   (diminish 'auto-revert-mode))
  343. (add-hook 'auto-revert-mode-hook 'hook-diminish-auto-revert)
  344.  
  345. (use-package keychain-environment ;; so magit sees ssh-agent
  346.   :config
  347.   (keychain-refresh-environment))
  348.  
  349. (use-package flx)
  350.  
  351. (use-package ivy
  352.   :diminish ivy-mode)
  353.  
  354. (use-package counsel
  355.   :init
  356.   (setq ivy-use-virtual-buffers t)
  357.   (setq ivy-count-format "(%d/%d) ")
  358.   (setq ivy-height 12)
  359.   (setq ivy-re-builders-alist
  360.       '((t . ivy--regex-fuzzy)))
  361.   (setq ivy-initial-inputs-alist nil)
  362.   :bind
  363.   (("M-y" . counsel-yank-pop)
  364.   ("C-s" . counsel-grep-or-swiper)
  365.   ("M-x" . counsel-M-x)
  366.   ("C-x C-f" . counsel-find-file)
  367.   ("C-x f" . counsel-find-file)
  368.   ("<f1> f" . counsel-describe-function)
  369.   ("<f1> v" . counsel-describe-variable)
  370.   ("<f1> l" . counsel-find-library)
  371.   ("<f2> i" . counsel-info-lookup-symbol)
  372.   ("<f2> u" . counsel-unicode-char)
  373.   ("C-c g" . counsel-git)
  374.   ("C-c j" . counsel-git-grep)
  375.   ("C-c k" . counsel-ag)
  376.   ("C-x l" . counsel-locate)
  377.   ("C-c r" . ivy-resume)
  378.    :map ivy-minibuffer-map
  379.    ("M-y" . ivy-next-line))
  380.   :config
  381.   (defun ivy-yank-action (x)
  382.     (kill-new x))
  383.   (defun ivy-copy-to-buffer-action (x)
  384.     (with-ivy-window
  385.       (insert x)))
  386.   (ivy-set-actions
  387.   t
  388.   '(("i" ivy-copy-to-buffer-action "insert")
  389.     ("y" ivy-yank-action "yank")))
  390.   (defun counsel-yank-zsh-history ()
  391.     "Yank the zsh history"
  392.     (interactive)
  393.     (let (hist-cmd collection val)
  394.       (shell-command "history -r") ; reload history
  395.       (setq collection
  396.         (nreverse
  397.         (split-string (with-temp-buffer (insert-file-contents (file-truename "~/.zsh_history"))
  398.                         (buffer-string))
  399.               "\n"
  400.               t)))
  401.       (setq collection (mapcar (lambda (it) (replace-regexp-in-string ".*;" "" it)) collection)) ;; for zsh
  402.       (when (and collection (> (length collection) 0)
  403.         (setq val (if (= 1 (length collection)) (car collection)
  404.                 (ivy-read (format "Zsh history:") collection))))
  405.     (kill-new val)
  406.     (message "%s => kill-ring" val))))
  407.   (ivy-mode 1))
  408.  
  409. (use-package projectile
  410.   :init
  411.   (setq projectile-completion-system 'ivy)
  412.   (setq projectile-mode-line '(:eval (format " Proj[%s]" (projectile-project-name))))
  413.   :config
  414.   (projectile-global-mode))
  415.  
  416. (use-package counsel-projectile
  417.   :config
  418.   (counsel-projectile-on))
  419.  
  420. (use-package avy
  421.   :bind
  422.   (("C-'" . avy-goto-char-2)
  423.    ("C-\"" . avy-goto-char)
  424.   ("M-'" . avy-goto-word-1)
  425.   ("M-\"" . avy-goto-word-0)
  426.   ("C-]" . avy-goto-line)))
  427.  
  428. (use-package yasnippet
  429.   :diminish yas-minor-mode
  430.   :bind
  431.   (:map yas-minor-mode-map
  432.   ("<tab>" . yas-expand)
  433.   ("TAB" . yas-expand)
  434.   ("[(shift tab)]" . nil)
  435.   ("[backtab]" . nil)
  436.   ("<S-iso-lefttab>" . yas-prev-field))
  437.   :config
  438.   (yas-global-mode 1))
  439.  
  440. (use-package notifications
  441.   :config
  442.   (defun desktop-notification (time message &optional title)
  443.     "System notification at some event or timer."
  444.     (run-at-time time nil 'notifications-notify
  445.         :title (or title "alarm")
  446.         :body message
  447.         :urgency 'critical ;; low, normal, critical
  448.         :app-name "Emacs: Org")))
  449.  
  450. ;; helpful in looking for empty bindings
  451. (use-package free-keys)
  452.  
  453. (use-package which-key
  454.   :config
  455.   (which-key-mode)
  456.   :diminish which-key-mode)
  457.  
  458. (use-package expand-region
  459.   :bind
  460.   (("C-=" . er/expand-region)))
  461.  
  462. (use-package undo-tree
  463.   :diminish undo-tree-mode
  464.   :config (global-undo-tree-mode))
  465.  
  466. (defun comment-or-uncomment-region-or-line ()
  467.     "Comments or uncomments the region or the current line if there's no active region."
  468.     (interactive)
  469.     (let (beg end)
  470.         (if (region-active-p)
  471.             (setq beg (region-beginning) end (region-end))
  472.             (setq beg (line-beginning-position) end (line-end-position)))
  473.         (comment-or-uncomment-region beg end)))
  474. (global-set-key (kbd "M-;") 'comment-or-uncomment-region-or-line)
  475. (global-set-key (kbd "M-[") (kbd "["))
  476.  
  477. (use-package sh-script
  478.   :init
  479.   (setq display-buffer-alist nil)
  480.   :bind
  481.   (("C-x e" . eval-buffer)
  482.    ("C-x C-e" . eval-last-sexp)
  483.   :map sh-mode-map
  484.    ("C-c e" . eval-shell-buffer)
  485.    ("C-x C-e" . eval-shell-current-line-or-region))
  486.   :config
  487.   (defun insert-shell-output-at-position (command position)
  488.     (save-excursion
  489.       (goto-char position)
  490.       (insert (with-temp-buffer
  491.     (shell-command command t)
  492.     (buffer-string)))))
  493.   (defun eval-shell-buffer (arg)
  494.     (interactive "p")
  495.     (if (/= arg 1) ;; arg not nil
  496.     (insert-shell-output-at-position (buffer-string) (point-max))
  497.     (shell-command (buffer-string))))
  498.   (defun eval-shell-current-line-or-region (start end arg)
  499.     (interactive "r\np")
  500.     (let ((command-position
  501.       (if (use-region-p)
  502.         (list (buffer-substring start end) end)
  503.         (list (thing-at-point 'line t) (+(point-at-eol) 1)))))
  504.       (if (/= arg 1)
  505.     (apply 'insert-shell-output-at-position command-position)
  506.     (shell-command (car command-position))))))
  507.  
  508. (use-package dired-x
  509.   :ensure nil
  510.   :config
  511.   (setq-default dired-omit-files-p t)
  512.   (setq dired-omit-files (concat dired-omit-files "\\|^\\..+$"))
  513.   (setq dired-omit-mode t))
  514.  
  515. (use-package key-chord
  516.   :config
  517.   (key-chord-mode 1)
  518.   (key-chord-define evil-insert-state-map  "jk" 'evil-normal-state))
  519.  
  520. (global-set-key (kbd "M-[") (kbd "C-x 8 RET L S B R RET"))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top