Skip to content

Latest commit

 

History

History
662 lines (502 loc) · 15.9 KB

config-term.org

File metadata and controls

662 lines (502 loc) · 15.9 KB

Emacs configuration file

Theme

Theme configuration

I have a few options, for easy switching.

(unless (display-graphic-p) (load-theme 'tsdh-dark))

;;(set-default-font "DejaVu Sans Mono 12")

Spaceline

Modeline inspired by the spacemacs distribution

    ;; enable spacemacs mode-line
    (use-package spaceline
      :ensure t
      :init 
      (progn 
      ;; size of modeline
         (setq powerline-height 20)
;;         (setq spaceline-highlight-face-func 'spaceline-highlight-face-evil-state)
)
      :config
      (require 'spaceline-config)
    ;;    (setq spaceline-buffer-encoding-abbrev-p nil)
    ;;    (setq spaceline-line-column-p nil)
    ;;    (setq spaceline-line-p nil)
    ;;    (setq powerline-default-separator (quote arrow))
    ;;  (spaceline-emacs-theme)
      (spaceline-spacemacs-theme)
      (setq
    ;;      spaceline-buffer-encoding-abbrev-p nil
            spaceline-window-numbers-unicode t
            )
    ;;        spaceline-minor-modes-separator nil
            (powerline-reset)
      )

    ;; Change some powerline colors in the terminal
      (unless (display-graphic-p) 
              (set-face-background 'powerline-inactive2 "color-233")
              (set-face-foreground 'powerline-inactive2 "white")
              (set-face-background 'powerline-inactive1 "cyan")
              (set-face-foreground 'powerline-inactive1 "white")
              (set-face-foreground 'mode-line "white")
  ;;            (set-face-background 'mode-line-inactive "")
             (set-face-foreground 'mode-line-inactive "white")
      )
   ;; change vertical divider line
      (set-face-background 'fringe "gray42") 
      (set-fringe-style 4)
      (scroll-bar-mode 0)

Which key passage

This displays completion options when you type emacs shortcuts.

(use-package which-key
  :ensure t
  :config (which-key-mode))

Org-mode config

Org bullets

fancy org-bullets

  ;; Org bullets
  (use-package org-bullets
    :ensure t
    :config 
      (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))
  )

  ;; change size of org titles
  (custom-set-faces
    '(org-level-1 ((t (:inherit outline-1 :height 1.5))))
    '(org-level-2 ((t (:inherit outline-2 :height 1.3))))
    '(org-level-3 ((t (:inherit outline-3 :height 1.1))))
    '(org-level-4 ((t (:inherit outline-4 :height 1.0))))
    '(org-level-5 ((t (:inherit outline-5 :height 1.0))))
  )
(setq org-list-allow-alphabetical t)

Org indent mode

;; Add org indent mode
(add-hook 'org-mode-hook 'org-indent-mode)

Org-sidebar

;(use-package org-sidebar
;    :ensure t)

Text and faces

Change some org-mode faces.

   (set-face-foreground 'org-document-info-keyword "Red")
 
   (set-face-attribute 'org-block nil :background
                      (color-darken-name
                      (face-attribute 'default :background) 8))
   (set-face-attribute 'org-block-begin-line nil :background
                      (color-darken-name
                      (face-attribute 'default :background) 14))

(custom-set-faces
 '(italic ((t (:foreground "blue" :slant italic)))))

Open PDFs externally

(add-to-list 'org-file-apps '("pdf" . "okular %s"))

Copy RTF text directly.

(use-package ox-clip
    :ensure t)

(global-set-key (kbd "C-x M-w") 'ox-clip-formatted-copy)

Latex export

Book class with no parts, just chapters

;; (add-to-list 'org-latex-classes
;;            '("book-noparts"
;;               "\\documentclass{book}"
;;               ("\\chapter{%s}" . "\\chapter*{%s}")
;;               ("\\section{%s}" . "\\section*{%s}")
;;               ("\\subsection{%s}" . "\\subsection*{%s}")
;;               ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
;;               ("\\paragraph{%s}" . "\\paragraph*{%s}")
;;               ("\\subparagraph{%s}" . "\\subparagraph*{%s}")))

org-ref and reftex package

For easy references and bibliographies

;; (use-package reftex
;;     :ensure t)

;; (use-package org-ref
;;     :ensure t
;;     :after org)

Minor fixes

Line and column numbers

(setq line-number-mode t)
(setq column-number-mode t)

Electric pair mode

Automatically pair matching parenthesis ()

;; electric pair mode
(electric-pair-mode t)

color code different parenthesis

Scrolling behavior

Scroll 1 line at a time.

;; Change scrolling behavior
(setq scroll-conservatively 100)

Disable bell sound

;; Disable bell sound
(setq ring-bell-function 'ignore)

Highlight cursor line

  ;; Highlite cursor line and set color
  (global-hl-line-mode t)
;;  (set-face-background hl-line-face "gray25")

  ;; Highlight only one-line in visual-line-mode
  ;; (defun highlight-visual-line ()
  ;;   (save-excursion
  ;;     (cons (progn (beginning-of-visual-line) (point))
  ;;           (progn (end-of-visual-line) (point)))))

;; (setq hl-line-range-function
;;       (lambda()
;;          (save-excursion
;;            (cons
;;             (progn
;;               (beginning-of-visual-line)
;;               (point))
;;             (progn
;;               (beginning-of-visual-line 2)
;;               (point))))))

;;  (setq hl-line-range-function 'highlight-visual-line)

Disable auto-indent mode(electric indent mode)

;; disable auto-indent mode
(when (fboundp 'electric-indent-mode) (electric-indent-mode -1))

Disable emacs startup screen

;; Disable startup screen.
(setq inhibit-startup-screen t)

Enable ibuffer

;; enable ibuffer
(global-set-key (kbd "C-x C-b") 'ibuffer)

Follow window splits

Make cursor go to new window after a split

(defun split-and-follow-horizontally ()
  (interactive)
  (split-window-below)
  (balance-windows)
  (other-window 1))
(global-set-key (kbd "C-x 2") 'split-and-follow-horizontally)

(defun split-and-follow-vertically ()
  (interactive)
  (split-window-right)
  (balance-windows)
  (other-window 1))
(global-set-key (kbd "C-x 3") 'split-and-follow-vertically)

Highlight matching parentheses

(show-paren-mode 1)
;; (set-face-background 'show-paren-match "grey40")

Change ‘yes-or-no’ to ‘y-or-n’

(defalias 'yes-or-no-p 'y-or-n-p)

Enable system clock in emacs

(display-time-mode 1)

Make bash shell the default bash in ansi-term

(defvar my-term-shell "/bin/bash")
(defadvice ansi-term (before force-bash)
  (interactive (list my-term-shell)))
(ad-activate 'ansi-term)

;; Set shortcut
(global-set-key (kbd "C-x t b") 'ansi-term)

Quickly visit configuration file

(defun config-visit ()
  (interactive)
  (find-file "~/.emacs.d/config.org"))
(global-set-key (kbd "C-c e") 'config-visit)

Shift Select

This should work in all modes, including org-mode. Must be in insert state.

(setq shift-select-mode 1)
(setq org-support-shift-select 1)

Backups in different folder

(setq backup-directory-alist '(("." . "~/EmacsBackups")))

Mac HOME and END keys

(global-set-key (kbd "<home>") 'move-beginning-of-line)
(global-set-key (kbd "<end>") 'move-end-of-line)

IVY and swiper

For completion of file and buffer selection, etc....

swiper is a better search package (C-s)

;; Ivy for completion. 
(use-package ivy
  :ensure t
  :config (ivy-mode 1)
)

;; swiper for faster search
(use-package swiper
  :ensure t
  :bind (
  ("C-r" . swiper-isearch-backward)
  ("C-s" . swiper))
)

Better window switching

Two options here: ace-window and switch-window

Ace-window

(use-package ace-window
   :ensure t
   :bind ("M-o" . ace-window)
   :delight
   :config (ace-window-display-mode 1)
   )

Programing specifics

Fortran

GAMESS uses src for F77 files.

(add-to-list 'auto-mode-alist '("\\.src\\'" . fortran-mode))

;; setup files with .f90 to be read as f90
(add-to-list 'auto-mode-alist '("\\.f90\\'" . f90-mode))
(add-to-list 'auto-mode-alist '("\\.F90\\'" . f90-mode))

General Package

The general package adds space leader key style keybindings.

Taken from https://github.com/suyashbire1/emacs.d/blob/master/init.el

  (use-package general
    :ensure t
    :after which-key
    :config
    (general-override-mode 1)

    (defun find-user-init-file ()
      "Edit the `user-init-file', in same window."
      (interactive)
      (find-file user-init-file))
    (defun load-user-init-file ()
      "Load the `user-init-file', in same window."
      (interactive)
      (load-file user-init-file))

    ;;Taken from http://emacsredux.com/blog/2013/05/04/rename-file-and-buffer/
    (defun rename-file-and-buffer ()
      "Rename the current buffer and file it is visiting."
      (interactive)
      (let ((filename (buffer-file-name)))
        (if (not (and filename (file-exists-p filename)))
            (message "Buffer is not visiting a file!")
          (let ((new-name (read-file-name "New name: " filename)))
            (cond
             ((vc-backend filename) (vc-rename-file filename new-name))
             (t
              (rename-file filename new-name t)
              (set-visited-file-name new-name t t)))))))


    (defun disable-all-themes ()
      "disable all active themes."
      (dolist (i custom-enabled-themes)
        (disable-theme i)))

    (defadvice load-theme (before disable-themes-first activate)
      (disable-all-themes))

    ;; Following lines to cycle through themes adapted from ivan's answer on
    ;; https://emacs.stackexchange.com/questions/24088/make-a-function-to-toggle-themes
    (setq my/themes (custom-available-themes))
    (setq my/themes-index 0)

    (defun my/cycle-theme ()
      "Cycles through my themes."
      (interactive)
      (setq my/themes-index (% (1+ my/themes-index) (length my/themes)))
      (my/load-indexed-theme))

    (defun my/load-indexed-theme ()
      (load-theme (nth my/themes-index my/themes)))

    (defun load-leuven-theme ()
      "Loads `leuven' theme"
      (interactive)
      (load-theme 'leuven))

    (defun load-dichromacy-theme ()
      "Loads `dichromacy' theme"
      (interactive)
      (load-theme 'dichromacy))

    (general-create-definer tyrant-def
;;      :states '(normal visual insert motion emacs)
      :prefix "M-m"
;;      :non-normal-prefix "M-m"
     )

    (general-create-definer despot-def
;;      :states '(normal insert emacs)
      :prefix "M-m"
;;      :non-normal-prefix "M-m"
     )

    ;; (general-define-key
    ;;   :keymaps 'key-translation-map
    ;;   "ESC" (kbd "C-g"))

    (general-def
      "C-x x" 'eval-defun)

    (tyrant-def

      ""     nil
      "c"   (general-simulate-key "C-c")
      "h"   (general-simulate-key "C-h")
      "u"   (general-simulate-key "C-u")
      "x"   (general-simulate-key "C-x")
      "<SPC>" (general-simulate-key "M-x")

      ;; Package manager
      "lp"  'list-packages

      ;; Theme operations
      "t"   '(:ignore t :which-key "themes")
      "tn"  'my/cycle-theme
      "tt"  'load-theme
      "tl"  'load-leuven-theme
      "td"  'load-dichromacy-theme

      ;; Quit operations
      "q"	  '(:ignore t :which-key "quit emacs")
      "qq"  'kill-emacs
      "qz"  'delete-frame

      ;; Buffer operations
      "b"   '(:ignore t :which-key "buffer")
      "bb"  'mode-line-other-buffer
      "bd"  'kill-this-buffer
      "b]"  'next-buffer
      "b["  'previous-buffer
      "bq"  'kill-buffer-and-window
      "bR"  'rename-file-and-buffer
      "br"  'revert-buffer

      ;; Window operations
      "w"   '(:ignore t :which-key "window")
      "wm"  'maximize-window
      "w/"  'split-window-horizontally
      "wv"  'split-window-vertically
      "wm"  'maximize-window
      "wu"  'winner-undo
      "ww"  'other-window
      "wd"  'delete-window
      "wD"  'delete-other-windows

      ;; File operations
      "f"   '(:ignore t :which-key "files")
      "fc"  'write-file
      "fe"  '(:ignore t :which-key "emacs")
      "fed" 'find-user-init-file
      "feR" 'load-user-init-file
      "fj"  'dired-jump
      "fl"  'find-file-literally
      "fR"  'rename-file-and-buffer
      "fs"  'save-buffer

      ;; Applications
      "a"   '(:ignore t :which-key "Applications")
      "ad"  'dired
      ":"   'shell-command
      ";"   'eval-expression
      "ac"  'calendar
      "oa"  'org-agenda)

    ;; (general-def doc-view-mode-map
    ;;   "j"   'doc-view-next-line-or-next-page
    ;;   "k"   'doc-view-previous-line-or-previous-page
    ;;   "gg"  'doc-view-first-page
    ;;   "G"   'doc-view-last-page
    ;;   "C-d" 'doc-view-scroll-up-or-next-page
    ;;   "C-f" 'doc-view-scroll-up-or-next-page
    ;;  "C-b" 'doc-view-scroll-down-or-previous-page) 

    ;; (general-def  outline-minor-mode-map
    ;;   "zn"  'outline-next-visible-heading
    ;;   "zp"  'outline-previous-visible-heading
    ;;   "zf"  'outline-forward-same-level
    ;;   "zB"  'outline-backward-same-level)

    (general-def package-menu-mode-map
      "i"   'package-menu-mark-install
      "U"   'package-menu-mark-upgrades
      "d"   'package-menu-mark-delete
      "u"   'package-menu-mark-unmark
      "x"   'package-menu-execute
      "q"   'quit-window)

    (general-def calendar-mode-map
      "h"   'calendar-backward-day
      "j"   'calendar-forward-week
      "k"   'calendar-backward-week
      "l"   'calendar-forward-day
      "0"   'calendar-beginning-of-week
      "^"   'calendar-beginning-of-week
      "$"   'calendar-end-of-week
      "["   'calendar-backward-year
      "]"   'calendar-forward-year
      "("   'calendar-beginning-of-month
      ")"   'calendar-end-of-month
      "SPC" 'scroll-other-window
      "S-SPC" 'scroll-other-window-down
      "<delete>" 'scroll-other-window-down
      "<"   'calendar-scroll-right
      ">"   'calendar-scroll-left
      "C-b" 'calendar-scroll-right-three-months
      "C-f" 'calendar-scroll-left-three-months
      "{"   'calendar-backward-month
      "}"   'calendar-forward-month
      "C-k" 'calendar-backward-month
      "C-j" 'calendar-forward-month
      "gk"  'calendar-backward-month
      "gj"  'calendar-forward-month
      "v"   'calendar-set-mark
      "."   'calendar-goto-today
      "q"   'calendar-exit)
    )

  (use-package suggest
    :general (tyrant-def "as" 'suggest))

Dired

Set a few Dired enhancements

(setq dired-dwim-target t)

(use-package dired-narrow
:ensure t
:config
(bind-key "C-c C-n" #'dired-narrow)
(bind-key "C-c C-f" #'dired-narrow-fuzzy)
(bind-key "C-x C-N" #'dired-narrow-regexp)
)

(use-package dired-subtree :ensure t
  :after dired
  :config
  (bind-key "<tab>" #'dired-subtree-toggle dired-mode-map)
  (bind-key "<backtab>" #'dired-subtree-cycle dired-mode-map))

Dictionary

Add dictionary

(use-package dictionary
  :ensure t)

(use-package synosaurus
  :ensure t)

Rigrep

(use-package deadgrep 
:ensure t)

(use-package rg
:ensure t
:commands rg)

(global-set-key (kbd "<f5>") #'deadgrep)