Skip to content

proxyserver2023/.emacs.d

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alamin’s Emacs Configuration

Introduction

(setq user-full-name "Md. Alamin Mahamud")
(setq user-email-address "alamin.ineedahelp@gmail.com")

General Settings

Maximum Workspace

(if (fboundp 'menu-bar-mode)(menu-bar-mode -1))
(if (fboundp 'tool-bar-mode)(tool-bar-mode -1))
(if (fboundp 'scroll-bar-mode)(scroll-bar-mode -1))

(setq inhibit-startup-message t)

Default Settings

  ;; Show keystrokes in progress
  (setq echo-keystrokes 0.1)

  ;; fringe-style
  (fringe-mode '(0 . 0))

  ;; Answering just 'y' or 'n' will do
  (defalias 'yes-or-no-p 'y-or-n-p)


  (if (display-graphic-p)
      (setq linum-format "%4d ")
    (setq linum-format "%4d \u2502 "))

  (add-hook 'global-mode-hook 'linum-mode)

  ;; default tab width
  (setq-default tab-width 8)
  (setq-default indent-tabs-mode 1)

  ;; auto save
  (defun full-auto-save ()
    (interactive)
    (save-excursion
      (dolist (buf (buffer-list))
        (set-buffer buf)
        (if (and (buffer-file-name) (buffer-modified-p))
            (basic-save-buffer)))))
  (add-hook 'auto-save-hook 'full-auto-save)

(setq gc-cons-threshold 10000000)

(windmove-default-keybindings)

Emacs Server

(require 'server)
(unless (server-running-p)
  (server-start))

Custom Settings File

(setq custom-file
      (expand-file-name "custom.el" user-emacs-directory))
(load custom-file)

Load Path

(add-to-list 'load-path (concat user-emacs-directory "lisp"))

Load Secrets

(load "~/.emacs.d/.secrets")

Backup files

;; Put Backup files neatly away
(let ((backup-dir "~/.emacs.d/backups")
      (auto-saves-dir "~/.emacs.d/auto-saves/"))

  (dolist (dir (list backup-dir auto-saves-dir))
    (when (not (file-directory-p dir))
      (make-directory dir t)))

  (setq backup-directory-alist         `(("." . ,backup-dir))
        auto-save-file-name-transforms `((".*" ,auto-saves-dir t))
        auto-save-list-file-prefix     (concat auto-saves-dir ".saves-")
        tramp-backup-directory-alist   `((".*" . ,backup-dir))
        tramp-auto-save-directory       auto-saves-dir
  )
  
  )


(setq backup-by-copying   t   ; Don't delink hardlinks
      delete-old-versions t   ; Clean up the backups
      version-control     t   ; Use version numbers on backups
      kept-new-versions   5   ; keep some new versions
      kept-old-versions   2   ; and some old ones, too
      )

Editing Settings

(setq global-mark-ring-max 5000         ; increase mark ring to contains 5000 entries
      mark-ring-max 5000                ; increase kill ring to contains 5000 entries
      mode-require-final-newline t      ; add a newline to end of file
      tab-width 4                       ; default to 4 visible spaces to display a tab
      )


(delete-selection-mode)
(global-set-key (kbd "RET") 'newline-and-indent)

(setq kill-ring-max 5000 ; increase kill-ring capacity
      kill-whole-line t  ; if NIL, kill whole line and move the next line up
      )

(add-hook 'diff-mode-hook (lambda ()
                            (setq-local whitespace-style
                                        '(face
                                          tabs
                                          tab-mark
                                          spaces
                                          space-mark
                                          trailing
                                          indentation::space
                                          indentation::tab
                                          newline
                                          newline-mark))
                            (whitespace-mode 1)))

Helpers

Editing As ROOT

(defun edit-current-file-as-root ()
  "Edit the file that is associated with the current buffer as root"
  (interactive)
  (if (buffer-file-name)
      (progn
        (setq file (concat "/sudo:localhost:" (buffer-file-name)))
        (find-file file))
    (message "Current buffer does not have an associated file.")))

Keybindings

Frequent Files Shortcut

;; notes.org
(global-set-key
 (kbd "\e\en")
 (lambda()
   (interactive)
   (find-file "~/Dropbox/org/notes.org")))



;; main config file
(global-set-key
 (kbd "\e\ec")
 (lambda()
   (interactive)
   (find-file "~/.emacs.d/README.org")))

;; main index file
(global-set-key
 (kbd "\e\ei")
 (lambda()
   (interactive)
   (find-file "~/Dropbox/org/index.org")))


;; reference for future use
(global-set-key
 (kbd "\e\er")
 (lambda()
   (interactive)
   (find-file "~/Dropbox/org/reference.org")))

;; tickler.org
(global-set-key
 (kbd "\e\et")
 (lambda()
   (interactive)
   (find-file "~/Dropbox/org/tickler.org")))

;; someday.org
(global-set-key
 (kbd "\e\es")
 (lambda()
   (interactive)
   (find-file "~/Dropbox/org/someday.org")))

;; projects.org
(global-set-key
 (kbd "\e\ep")
 (lambda()
   (interactive)
   (find-file "~/Dropbox/org/projects.org")))

;; waiting.org
(global-set-key
 (kbd "\e\ew")
 (lambda()
   (interactive)
   (find-file "~/Dropbox/org/waiting.org")))

;; now.org
(global-set-key
 (kbd "\e\eN")
 (lambda()
   (interactive)
   (find-file "~/Dropbox/org/now.org")))

;; links
(global-set-key
 (kbd "\e\el")
 (lambda()
   (interactive)
   (find-file "~/Dropbox/org/links.org")))

;; hotlist
(global-set-key
 (kbd "\e\eh")
 (lambda()
   (interactive)
   (find-file "~/Dropbox/org/hotlist.org")))

;; finance
(global-set-key
 (kbd "\e\ef")
 (lambda()
   (interactive)
   (find-file "~/Dropbox/org/finance.org")))

;; appointments meetings
(global-set-key
 (kbd "\e\eg")
 (lambda()
   (interactive)
   (find-file "~/Dropbox/org/gcal.org")))

;; i3wm config
(global-set-key
 (kbd "\e\e3")
 (lambda()
   (interactive)
   (find-file "~/.i3/config")))


;; .zshrc
(global-set-key
 (kbd "\e\ez")
 (lambda()
   (interactive)
   (find-file "~/.zshrc")))

;; ends here

Kill this buffer

(global-set-key (kbd "C-x k") 'kill-this-buffer)

Appearnace

Scratch Buffer

(setq initial-scratch-message (
                               concat
                               "One Brick A Day, "
                               user-login-name
                               " - Emacs ♥ you!\n\n"
                               "| HEALTH   | SPEAK         | PROGRAMMING | Investments |\n"
                               "|----------|---------------|-------------|-------------|\n"
                               "| YOGA     | SPEAKING      | GO          | Investments |\n"
                               "| EXCR     | CONVERSATION  |             |             |\n"
                               "|          |               |             |             |\n"  
                               "|          |               |             |             |\n"  
                               ))

Icons

(use-package all-the-icons)

Neotree

; (use-package neotree
;   :ensure t)

; (require 'neotree)
; (global-set-key [f8] 'neotree-toggle)

Fonts

   (set-face-attribute 'default nil
                        ;;:font "Source Code Pro"
                        :font "MonacoB"
                        :height 80
                        :weight 'bold
                        :width 'normal
    )
;; (set-face-attribute 'default nil :font "MonacoB" :weight 'bold :height '10)

Theme

(use-package atom-one-dark-theme)
(load-theme 'atom-one-dark t) 

Package Initialization

(require 'package)
  
(setq package-archives nil)
(setq package-archives
      '(
        ("org"       . "https://orgmode.org/elpa/")
        ("gnu"       . "http://elpa.gnu.org/packages/")
        ("melpa"     . "http://melpa.org/packages/")
        ;("marmalade" . "http://marmalade-repo.org/packages/")
        )
      )

(package-initialize)

(unless (and (file-exists-p "~/.emacs.d/elpa/archives/gnu")
             (file-exists-p "~/.emacs.d/elpa/archives/melpa")
             (file-exists-p "~/.emacs.d/elpa/archives/melpa-stable")
             (file-exists-p "~/.emacs.d/elpa/archives/marmalade")
             )
  (package-refresh-contents))


;; use-package
(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))

(setq use-package-verbose t)
(setq use-package-always-ensure t)
(require 'use-package)

Packages

ace-window ace-jump-mode

(use-package ace-window
:init
(progn
(setq aw-scope 'frame)
(global-set-key (kbd "C-x O") 'other-frame)
(setq aw-keys '(?a ?s ?d ?f ?j ?k ?l ?o))
(global-set-key [remap other-window] 'ace-window)
(custom-set-faces
 '(aw-leading-char-face
   ((t (:inherit ace-jump-face-foreground :height 3.0)))))))

(use-package ace-jump-mode
  :config
  (define-key global-map (kbd "C-c SPC") 'ace-jump-mode))
(require 'cc-mode)
(require 'semantic)

(global-semanticdb-minor-mode 1)
(global-semantic-idle-scheduler-mode 1)
(global-semantic-stickyfunc-mode 1)

(semantic-mode 1)

(defun alexott/cedet-hook ()
  (local-set-key "\C-c\C-j" 'semantic-ia-fast-jump)
  (local-set-key "\C-c\C-s" 'semantic-ia-show-summary))

(add-hook 'c-mode-common-hook 'alexott/cedet-hook)
(add-hook 'c-mode-hook 'alexott/cedet-hook)
(add-hook 'c++-mode-hook 'alexott/cedet-hook)

;; Enable EDE only in C/C++
(require 'ede)
(global-ede-mode)

anzu

(use-package anzu
  :init
  (global-anzu-mode)
  (global-set-key (kbd "M-%") 'anzu-query-replace)
  (global-set-key (kbd "C-M-%") 'anzu-query-replace-regexp))

clean-aindent mode

(use-package clean-aindent-mode
  :init
  (add-hook 'prog-mode-hook 'clean-aindent-mode))

comment-dwim-2

(use-package comment-dwim-2
  :bind (("M-;" . comment-dwim-2))
  )

company

(use-package company
    :ensure t
    :diminish
    :config
    (add-hook 'after-init-hook 'global-company-mode)

    (setq company-idle-delay t)

    (use-package company-go
      :ensure t
      :config
      (add-to-list 'company-backends 'company-go))

    (use-package company-anaconda
      :ensure t
      :config
      (add-to-list 'company-backends 'company-anaconda)))

I don’t want suggestions from open files / buffers to be automatically lowercased as these are often camelcase function names.

(setq company-dabbrev-downcase nil)

dtrt indent

(use-package dtrt-indent
  :init
  (dtrt-indent-mode 1)
  (setq dtrt-indent-verbosity 0))

duplicate-thing

(use-package duplicate-thing
:ensure t
:config
(require 'duplicate-thing)
(global-set-key (kbd "M-c") 'duplicate-thing))

editorconfig

(use-package editorconfig
  :ensure t
  :config
  (editorconfig-mode 1))

exec-path-from-shell

(use-package exec-path-from-shell
  :ensure t
  :if (memq window-system '(mac ns x))
  :config
  (setq exec-path-from-shell-variables '("PATH" "GOPATH" "GOROOT"))
  (exec-path-from-shell-initialize))

expand-region

(use-package expand-region
  :config
  (require 'expand-region)
  (global-set-key (kbd "M-m") 'er/expand-region))

flycheck

  (use-package flycheck
    :ensure t
    :diminish flycheck-mode
    :config
    (global-flycheck-mode))

; As-you-type error highlighting
(add-hook 'after-init-hook #'global-flycheck-mode)
  

helm

(use-package helm
  :init
  (progn
    (require 'helm-config)
    (require 'helm-grep)
    ;; To fix error at compile:
    ;; Error (bytecomp): Forgot to expand macro with-helm-buffer in
    ;; (with-helm-buffer helm-echo-input-in-header-line)
    (if (version< "26.0.50" emacs-version)
        (eval-when-compile (require 'helm-lib)))

    (defun helm-hide-minibuffer-maybe ()
      (when (with-helm-buffer helm-echo-input-in-header-line)
        (let ((ov (make-overlay (point-min) (point-max) nil nil t)))
          (overlay-put ov 'window (selected-window))
          (overlay-put ov 'face (let ((bg-color (face-background 'default nil)))
                                  `(:background ,bg-color :foreground ,bg-color)))
          (setq-local cursor-type nil))))

    (add-hook 'helm-minibuffer-set-up-hook 'helm-hide-minibuffer-maybe)
    ;; The default "C-x c" is quite close to "C-x C-c", which quits Emacs.
    ;; Changed to "C-c h". Note: We must set "C-c h" globally, because we
    ;; cannot change `helm-command-prefix-key' once `helm-config' is loaded.
    (global-set-key (kbd "C-c h") 'helm-command-prefix)
    (global-unset-key (kbd "C-x c"))

    (define-key helm-map (kbd "<tab>") 'helm-execute-persistent-action) ; rebihnd tab to do persistent action
    (define-key helm-map (kbd "C-i") 'helm-execute-persistent-action) ; make TAB works in terminal
    (define-key helm-map (kbd "C-z")  'helm-select-action) ; list actions using C-z

    (define-key helm-grep-mode-map (kbd "<return>")  'helm-grep-mode-jump-other-window)
    (define-key helm-grep-mode-map (kbd "n")  'helm-grep-mode-jump-other-window-forward)
    (define-key helm-grep-mode-map (kbd "p")  'helm-grep-mode-jump-other-window-backward)

    (when (executable-find "curl")
      (setq helm-google-suggest-use-curl-p t))

    (setq helm-google-suggest-use-curl-p t
          helm-scroll-amount 4 ; scroll 4 lines other window using M-<next>/M-<prior>
          ;; helm-quick-update t ; do not display invisible candidates
          helm-ff-search-library-in-sexp t ; search for library in `require' and `declare-function' sexp.

          ;; you can customize helm-do-grep to execute ack-grep
          ;; helm-grep-default-command "ack-grep -Hn --smart-case --no-group --no-color %e %p %f"
          ;; helm-grep-default-recurse-command "ack-grep -H --smart-case --no-group --no-color %e %p %f"
          helm-split-window-in-side-p t ;; open helm buffer inside current window, not occupy whole other window

          helm-echo-input-in-header-line t

          ;; helm-candidate-number-limit 500 ; limit the number of displayed canidates
          helm-ff-file-name-history-use-recentf t
          helm-move-to-line-cycle-in-source t ; move to end or beginning of source when reaching top or bottom of source.
          helm-buffer-skip-remote-checking t

          helm-mode-fuzzy-match t

          helm-buffers-fuzzy-matching t ; fuzzy matching buffer names when non-nil
                                        ; useful in helm-mini that lists buffers
          helm-org-headings-fontify t
          ;; helm-find-files-sort-directories t
          ;; ido-use-virtual-buffers t
          helm-semantic-fuzzy-match t
          helm-M-x-fuzzy-match t
          helm-imenu-fuzzy-match t
          helm-lisp-fuzzy-completion t
          ;; helm-apropos-fuzzy-match t
          helm-buffer-skip-remote-checking t
          helm-locate-fuzzy-match t
          helm-display-header-line nil)

    (add-to-list 'helm-sources-using-default-as-input 'helm-source-man-pages)

    (global-set-key (kbd "M-x") 'helm-M-x)
    (global-set-key (kbd "M-y") 'helm-show-kill-ring)
    (global-set-key (kbd "C-x b") 'helm-buffers-list)
    (global-set-key (kbd "C-x C-f") 'helm-find-files)
    (global-set-key (kbd "C-c r") 'helm-recentf)
    (global-set-key (kbd "C-h SPC") 'helm-all-mark-rings)
    (global-set-key (kbd "C-c h o") 'helm-occur)
    (global-set-key (kbd "C-c h o") 'helm-occur)

    (global-set-key (kbd "C-c h w") 'helm-wikipedia-suggest)
    (global-set-key (kbd "C-c h g") 'helm-google-suggest)

    (global-set-key (kbd "C-c h x") 'helm-register)
    ;; (global-set-key (kbd "C-x r j") 'jump-to-register)

    (define-key 'help-command (kbd "C-f") 'helm-apropos)
    (define-key 'help-command (kbd "r") 'helm-info-emacs)
    (define-key 'help-command (kbd "C-l") 'helm-locate-library)

    ;; use helm to list eshell history
    (add-hook 'eshell-mode-hook
              #'(lambda ()
                  (define-key eshell-mode-map (kbd "M-l")  'helm-eshell-history)))

;;; Save current position to mark ring
    (add-hook 'helm-goto-line-before-hook 'helm-save-current-pos-to-mark-ring)

    ;; show minibuffer history with Helm
    (define-key minibuffer-local-map (kbd "M-p") 'helm-minibuffer-history)
    (define-key minibuffer-local-map (kbd "M-n") 'helm-minibuffer-history)

    (define-key global-map [remap find-tag] 'helm-etags-select)

    (define-key global-map [remap list-buffers] 'helm-buffers-list)

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; PACKAGE: helm-swoop                ;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;; Locate the helm-swoop folder to your path
    (use-package helm-swoop
      :bind (("C-c h o" . helm-swoop)
             ("C-c s" . helm-multi-swoop-all))
      :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
      (setq helm-swoop-split-with-multiple-windows t)

      ;; Split direcion. 'split-window-vertically or 'split-window-horizontally
      (setq helm-swoop-split-direction 'split-window-vertically)

      ;; If nil, you can slightly boost invoke speed in exchange for text color
      (setq helm-swoop-speed-or-color t))

    (helm-mode 1)

    (use-package helm-projectile
      :init
      (helm-projectile-on)
      (setq projectile-completion-system 'helm)
      (setq projectile-indexing-method 'alien))))

helm-gtags

;; this variables must be set before load helm-gtags
;; you can change to any prefix key of your choice
(setq helm-gtags-prefix-key "\C-cg")

(use-package helm-gtags
  :init
  (progn
    (setq helm-gtags-ignore-case t
          helm-gtags-auto-update t
          helm-gtags-use-input-at-cursor t
          helm-gtags-pulse-at-cursor t
          helm-gtags-prefix-key "\C-cg"
          helm-gtags-suggested-key-mapping t)

    ;; Enable helm-gtags-mode in Dired so you can jump to any tag
    ;; when navigate project tree with Dired
    (add-hook 'dired-mode-hook 'helm-gtags-mode)

    ;; Enable helm-gtags-mode in Eshell for the same reason as above
    (add-hook 'eshell-mode-hook 'helm-gtags-mode)

    ;; Enable helm-gtags-mode in languages that GNU Global supports
    (add-hook 'c-mode-hook 'helm-gtags-mode)
    (add-hook 'c++-mode-hook 'helm-gtags-mode)
    (add-hook 'java-mode-hook 'helm-gtags-mode)
    (add-hook 'asm-mode-hook 'helm-gtags-mode)

    ;; key bindings
    (with-eval-after-load 'helm-gtags
      (define-key helm-gtags-mode-map (kbd "C-c g a") 'helm-gtags-tags-in-this-function)
      (define-key helm-gtags-mode-map (kbd "C-j") 'helm-gtags-select)
      (define-key helm-gtags-mode-map (kbd "M-.") 'helm-gtags-dwim)
      (define-key helm-gtags-mode-map (kbd "M-,") 'helm-gtags-pop-stack)
      (define-key helm-gtags-mode-map (kbd "C-c <") 'helm-gtags-previous-history)
      (define-key helm-gtags-mode-map (kbd "C-c >") 'helm-gtags-next-history))))

highlight-indent-guides

(use-package highlight-indent-guides)
(setq highlight-indent-guides-method 'character)
(add-hook 'prog-mode-hook 'highlight-indent-guides-mode)
(add-hook 'yaml-mode-hook 'highlight-indent-guides-mode)
(setq highlight-indent-guides-character ?\|)
;; customize colors
(setq highlight-indent-guides-auto-enabled nil)

(set-face-background 'highlight-indent-guides-odd-face "darkgray")
(set-face-background 'highlight-indent-guides-even-face "dimgray")
(set-face-foreground 'highlight-indent-guides-character-face "dimgray")

iedit

(use-package iedit
  :bind (("C-;" . iedit-mode))
  :init
  (setq iedit-toggle-key-default nil))

magit

(use-package magit
  :commands magit-status magit-blame
  :init
  (defadvice magit-status (around magit-fullscreen activate)
    (window-configuration-to-register :magit-fullscreen)
    ad-do-it
    (delete-other-windows))
  :config
  (setq vc-follow-symlinks nil
        magit-push-always-verify nil
        magit-restore-window-configuration t)
  :bind ("C-x g" . magit-status))

Display line changes in gutter based on git history. Enable it everywhere.

(use-package diff-hl
  :config
  (require 'diff-hl)
  (diff-hl-flydiff-mode))

TimeMachine lets us step through the history of a file as recorded in git.

(use-package git-timemachine
  :ensure t)

multiple-cursors

(use-package multiple-cursors
  :config
  (require 'multiple-cursors)
  (global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines)
  (global-set-key (kbd "C->") 'mc/mark-next-like-this)
  (global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
  (global-set-key (kbd "C-c C-<") 'mc/mark-all-like-this)
  )

org-mode

;; Code-Block shortcuts
(setq
 org-structure-template-alist
 '(
   ("s" "#+BEGIN_SRC shell\n?\n#+END_SRC" "<src lang=\"shell\">\n?\n</src>")
   ("sq" "#+BEGIN_SRC sql\n?\n#+END_SRC" "<src lang=\"sql\">\n?\n</src>")
   ("e" "#+BEGIN_EXAMPLE\n?\n#+END_EXAMPLE" "<example>\n?\n</example>")
   ("q" "#+BEGIN_QUOTE\n?\n#+END_QUOTE" "<quote>\n?\n</quote>")
   ("v" "#+BEGIN_VERSE\n?\n#+END_VERSE" "<verse>\n?\n</verse>")
   ("c" "#+BEGIN_SRC cpp\n?\n#+END_SRC" "<src lang=\"cpp\">\n?\n</src>")
   ("L" "#+latex: " "<literal style=\"latex\">?</literal>")
   ("h" "#+begin_html\n?\n#+end_html" "<literal style=\"html\">\n?\n</literal>")
   ("H" "#+html: " "<literal style=\"html\">?</literal>")
   ("a" "#+begin_ascii\n?\n#+end_ascii")
   ("A" "#+ascii: ")
   ("i" "#+index: ?" "#+index: ?")
   ("I" "#+include %file ?" "<include file=%file markup=\"?\">")
   ("l" "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC" "<src lang=\"emacs-lisp\">\n?\n</src>")
   ("py" "#+BEGIN_SRC python\n?\n#+END_SRC" "<src lang=\"python\">\n?\n</src>")
   ("ph" "#+BEGIN_SRC php\n?\n#+END_SRC" "<src lang=\"php\">\n?\n</src>")
   )
 )

org-babel execute functions

(org-babel-do-load-languages
 'org-babel-load-languages
 '((python . t)
   (shell  . t)
   (js     . t)
   (go     . t)))

(setq org-confirm-babel-evaluate nil)

origami

(use-package origami)
(require 'origami)

projectile

  (use-package projectile
    :init
    (projectile-global-mode)
    (setq projectile-enable-caching t))

(define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map)

try

(use-package try)

undo-tree

(use-package undo-tree
  :ensure t
  :diminish undo-tree-mode
  :init
  (global-undo-tree-mode 1)
  :config
  (defalias 'redo 'undo-tree-redo)
  :bind (("C-z"   . undo)
         ("C-S-z" . redo)))

volatile highlights

(use-package volatile-highlights
  :init
  (volatile-highlights-mode t))

which key

(use-package which-key
  :config
  (require 'which-key)
  (which-key-mode))

whitespace mode

(use-package whitespace
  :bind ("C-c w" . whitespace-mode)
  :init
  (setq whitespace-line-column nil
        whitespace-display-mappings '((space-mark 32 [183] [46])
                                      (newline-mark 10 [9166 10])
                                      (tab-mark 9 [9654 9] [92 9])))
  :config
  (set-face-attribute 'whitespace-space       nil :foreground "#666666" :background nil)
  (set-face-attribute 'whitespace-newline     nil :foreground "#666666" :background nil)
  (set-face-attribute 'whitespace-indentation nil :foreground "#666666" :background nil)
  :diminish whitespace-mode)

ws-butler

(use-package ws-butler
  :init
  (add-hook 'prog-mode-hook 'ws-butler-mode)
  (add-hook 'text-mode 'ws-butler-mode)
  (add-hook 'fundamental-mode 'ws-butler-mode))

yasnippets

Type the shortcut and press TAB to complete, or M-/ to autosuggest a snippet.

(use-package yasnippet
    :ensure t
    :diminish yas-minor-mode
    :config
    (add-to-list 'yas-snippet-dirs "~/.emacs.d/yasnippet-snippets")
    (add-to-list 'yas-snippet-dirs "~/.emacs.d/snippets")
    (yas-global-mode)
    (global-set-key (kbd "M-/") 'company-yasnippet))

zygospore

(use-package zygospore
  :bind (("C-x 1" . zygospore-toggle-delete-other-windows)
         ("RET" .   newline-and-indent)))

Programming

General

When programming I like my editor to try to help me with keeping parentheses balanced.

(use-package smartparens
  :ensure t
  :diminish smartparens-mode
  :config
  (add-hook 'prog-mode-hook 'smartparens-mode))

Highlight parens etc. for improved readability.

(use-package rainbow-delimiters
  :ensure t
  :config
  (add-hook 'prog-mode-hook 'rainbow-delimiters-mode))

Highlight strings which represent colours. I only want this in programming modes, and I don’t want colour names to be highlighted (x-colors).

(use-package rainbow-mode
  :ensure t
  :config
  (setq rainbow-x-colors nil)
  (add-hook 'prog-mode-hook 'rainbow-mode))

Keep things indented correctly for me.

(use-package aggressive-indent
      :ensure t)

Expand parentheses for me.

(add-hook 'prog-mode-hook 'electric-pair-mode)

Smart dash guesses _ vs - depending on context.

(use-package smart-dash
  :ensure t
  :config
  (add-hook 'python-mode-hook 'smart-dash-mode))

show unncessary whitespace that can mess up your diff

(add-hook 'prog-mode-hook
          (lambda () (interactive)
            (setq show-trailing-whitespace 1)))

Compilation

(global-set-key (kbd "<f5>") (lambda ()
                               (interactive)
                               (setq-local compilation-read-command nil)
                               (call-interactively 'compile)))

GDB

;; setup GDB
(setq
 ;; use gdb-many-windows by default
 gdb-many-windows t

 ;; Non-nil means display source file containing the main routine at startup
 gdb-show-main t
 )

Python

  1. file navigation between multiple projects
  2. contexual documentation
  3. inline help for complex function calls
(setq python-shell-interpreter "ipython3"
      python-shell-interpreter-args "--pprint")

;; Switch to the interpreter after executing code
(setq py-shell-switch-buffers-on-execute-p t)
(setq py-switch-buffers-on-execute-p t)

;; don't split windows
(setq py-split-windows-on-execute-p nil)

;; try to automagically figure out indentation
(setq py-smart-indentation t)

(use-package elpy)
(elpy-enable)

Go

Install This Tools before working with Emacs

A lot of the config is based on gocode, godef, goimports and gotags packages that you should install separately.

go get golang.org/x/tools/cmd/… go get -u -v github.com/rogpeppe/godef go get -u -v golang.org/x/tools/cmd/gorename go get -u -v github.com/jstemmer/gotags go get -u -v github.com/davecgh/go-spew/spew go get -u -v github.com/motemen/gore go get -u -v github.com/golang/example/hello go get -u -v github.com/tleyden/checkers-bot-minimax go get -u -v golang.org/x/tour/gotour go get -u -v github.com/nsf/gocode go get -u -v github.com/alecthomas/gometalinter gometalinter –install go get -u github.com/rogpeppe/godef go get github.com/matryer/moq go get -u github.com/dougm/goflymake go get -u golang.org/x/lint/golint gocode set package-lookup-mode gb

go-mode

(use-package go-mode)
(require 'go-mode)

go-guru

 (use-package go-guru)
 (require 'go-guru)

 ; Go guru needs a scope to look at, this function sets it to the current package.
 (defun jc/go-guru-set-current-package-as-main ()
	"GoGuru requires the scope to be set to a go package which
	  contains a main, this function will make the current package the
	  active go guru scope, assuming it contains a main"
	(interactive)
	(let* ((filename (buffer-file-name))
		   (gopath-src-path (concat (file-name-as-directory (go-guess-gopath)) "src"))
		   (relative-package-path (directory-file-name (file-name-directory (file-relative-name filename gopath-src-path)))))
	  (setq go-guru-scope relative-package-path)))

go-mode-hook

(defun my-go-mode-hook()
  (add-hook 'before-save-hook 'gofmt-before-save) ; Call GoFmt before saving
  (setq gofmt-command "goimports")                ; gofmt uses invokes goimports
  (if (not (string-match "go" compile-command))   ; Customize compile command to run go build
      (set (make-local-variable 'compile-command)
           "go build -v && go test -v && go vet && go run main.go"))

  ;; tab settings
  (setq tab-width 8)
  (setq indent-tabs-mode 1)
  ;; guru settings
  (go-guru-hl-identifier-mode)                    ; highlight identifiers

  ;; Key bindings specific to go-mode
  (local-set-key (kbd "M-.") 'godef-jump)         ; Go to definition
  (local-set-key (kbd "M-*") 'pop-tag-mark)       ; Return from whence you came
  (local-set-key (kbd "M-p") 'compile)            ; Invoke compiler
  (local-set-key (kbd "M-P") 'recompile)          ; Redo most recent compile cmd
  (local-set-key (kbd "M-]") 'next-error)         ; Go to next error (or msg)
  (local-set-key (kbd "M-[") 'previous-error)     ; Go to previous error or msg

                                        ; Misc go stuff
  (auto-complete-mode 1)                         ; Enable auto-complete mode


                                        ;set-guru scope
  ; (jc/go-guru-set-current-package-as-main)
  )

(add-hook 'go-mode-hook 'my-go-mode-hook)

company

(use-package company-go)
(add-hook 'go-mode-hook (lambda ()
   (set (make-local-variable 'company-backends) '(company-go))
   (company-mode)))

customize the emacs compile command to run go build

flymake-go

install it in bash

go-snippets

(use-package go-snippets)

go-projectile

(use-package go-projectile)
(require 'go-projectile)

(eval-after-load 'go-mode
  '(progn
     (go-projectile-set-gopath)
     (go-projectile-tools-add-path)
     ))

ELDoc

(use-package go-eldoc
  :diminish eldoc-mode
  :config (add-hook 'go-mode-hook 'go-eldoc-setup))

Go StackTracer

(use-package go-stacktracer)

Go Add Tags

(use-package go-add-tags)

Go Direx

(use-package go-direx)

Go Test

(use-package gotest)

Integrate moq Quick custom function to integrate with the moq tool to generate quick mocks

(defun moq ()
  (interactive)
  (let ((interface (word-at-point))
        (test-file (concat (downcase (word-at-point)) "_test.go")))
    (shell-command
     (concat "moq -out " test-file " . " interface))
    (find-file test-file)))

See Test Coverage Faster

(defun go-coverage-here ()
  (interactive)
  (shell-command "go test . -coverprofile=cover.out")
  (go-coverage "cover.out")
  (rotate:even-horizontal))

golint

(use-package golint)
(add-to-list 'load-path (concat (getenv "GOPATH")  "/src/github.com/golang/lint/misc/emacs"))
(require 'golint)

go-scratch

(use-package go-scratch)

godoctor

(use-package godoctor
    :ensure t)

EmacsLisp

Tools

Eshell

;; (setenv "ESHELL" (expand-file-name "~/.eshell"))

set correct path

(setenv "PATH"
        (concat
         "/usr/local/bin:/usr/local/sbin:"
         (getenv "PATH")))
(use-package eshell
  :init
  (setq ;; eshell-buffer-shorthand t ...  Can't see Bug#19391
        eshell-scroll-to-bottom-on-input 'all
        eshell-error-if-no-glob t
        eshell-hist-ignoredups t
        eshell-save-history-on-exit t
        eshell-prefer-lisp-functions nil
        eshell-destroy-buffer-when-process-dies t))
(use-package eshell
  :init
  (add-hook 'eshell-mode-hook
            (lambda ()
              (add-to-list 'eshell-visual-commands "ssh")
              (add-to-list 'eshell-visual-commands "tail")
              (add-to-list 'eshell-visual-commands "top"))))
(add-hook 'eshell-mode-hook (lambda ()
    (eshell/alias "e" "find-file $1")
    (eshell/alias "ff" "find-file $1")
    (eshell/alias "emacs" "find-file $1")
    (eshell/alias "ee" "find-file-other-window $1")

    (eshell/alias "gd" "magit-diff-unstaged")
    (eshell/alias "gds" "magit-diff-staged")
    (eshell/alias "d" "dired $1")

    ;; The 'ls' executable requires the Gnu version on the Mac
    (let ((ls (if (file-exists-p "/usr/local/bin/gls")
                  "/usr/local/bin/gls"
                "/bin/ls")))
      (eshell/alias "ls" (concat ls " -AlohG --color=always")))))

clear

(defun eshell/clear ()
  "Clear the eshell buffer."
  (let ((inhibit-read-only t))
    (erase-buffer)
    (eshell-send-input)))

shell here

(defun eshell-here ()
  "Opens up a new shell in the directory associated with the
current buffer's file. The eshell is renamed to match that
directory to make multiple eshell windows easier."
  (interactive)
  (let* ((parent (if (buffer-file-name)
                     (file-name-directory (buffer-file-name))
                   default-directory))
         (height (/ (window-total-height) 3))
         (name   (car (last (split-string parent "/" t)))))
    (split-window-vertically (- height))
    (other-window 1)
    (eshell "new")
    (rename-buffer (concat "*eshell: " name "*"))

    (insert (concat "ls"))
    (eshell-send-input)))

(bind-key "C-`" 'eshell-here)

Markdown

sudo apt-get install libglib2.0-dev
cd ~/src
export TEMP_NAME=multimarkdown_dir
git clone --recursive git://github.com/fletcher/peg-multimarkdown.git $TEMP_NAME
cd ./$TEMP_NAME
make
sudo ln -sf ~/src/$TEMP_NAME/multimarkdown /usr/local/bin/multimarkdown
(use-package markdown-mode
  :ensure t
  :commands (markdown-mode gfm-mode)
  :mode (("README\\.md\\'" . gfm-mode)
         ("\\.md\\'" . markdown-mode)
         ("\\.markdown\\'" . markdown-mode))
  :init (setq markdown-command "multimarkdown"))

YAML

Docker

(use-package dockerfile-mode)
(require 'dockerfile-mode)
(add-to-list 'auto-mode-alist '("Dockerfile\\'" . dockerfile-mode))
(use-package docker-compose-mode)
(use-package docker-tramp)
(use-package eshell-bookmark)

User Specific Emacs Settings

;; Settings for currently logged in user
(setq user-settings-dir
      (concat user-emacs-directory "users/" user-login-name))
(add-to-list 'load-path user-settings-dir)

;; Conclude init by setting up specifics for the current user
(when (file-exists-p user-settings-dir)
  (mapc 'load (directory-files user-settings-dir nil "^[^#].*el$")))

Customized Functions

(defun prelude-move-beginning-of-line (arg)
  "Move point back to indentation of beginning of line.
Move point to the first non-whitespace character on this line.
If point is already there, move to the beginning of the line.
Effectively toggle between the first non-whitespace character and
the beginning of the line.
If ARG is not nil or 1, move forward ARG - 1 lines first. If
point reaches the beginning or end of the buffer, stop there."
  (interactive "^p")
  (setq arg (or arg 1))

  ;; Move lines first
  (when (/= arg 1)
    (let ((line-move-visual nil))
      (forward-line (1- arg))))

  (let ((orig-point (point)))
    (back-to-indentation)
    (when (= orig-point (point))
      (move-beginning-of-line 1))))

(global-set-key (kbd "C-a") 'prelude-move-beginning-of-line)

(defadvice kill-ring-save (before slick-copy activate compile)
  "When called interactively with no active region, copy a single
line instead."
  (interactive
   (if mark-active (list (region-beginning) (region-end))
     (message "Copied line")
     (list (line-beginning-position)
           (line-beginning-position 2)))))

(defadvice kill-region (before slick-cut activate compile)
  "When called interactively with no active region, kill a single
  line instead."
  (interactive
   (if mark-active (list (region-beginning) (region-end))
     (list (line-beginning-position)
           (line-beginning-position 2)))))

;; kill a line, including whitespace characters until next non-whiepsace character
;; of next line
(defadvice kill-line (before check-position activate)
  (if (member major-mode
              '(emacs-lisp-mode scheme-mode lisp-mode
                                c-mode c++-mode objc-mode
                                latex-mode plain-tex-mode))
      (if (and (eolp) (not (bolp)))
          (progn (forward-char 1)
                 (just-one-space 0)
                 (backward-char 1)))))

;; taken from prelude-editor.el
;; automatically indenting yanked text if in programming-modes
(defvar yank-indent-modes
  '(LaTeX-mode TeX-mode)
  "Modes in which to indent regions that are yanked (or yank-popped).
Only modes that don't derive from `prog-mode' should be listed here.")

(defvar yank-indent-blacklisted-modes
  '(python-mode slim-mode haml-mode)
  "Modes for which auto-indenting is suppressed.")

(defvar yank-advised-indent-threshold 1000
  "Threshold (# chars) over which indentation does not automatically occur.")

(defun yank-advised-indent-function (beg end)
  "Do indentation, as long as the region isn't too large."
  (if (<= (- end beg) yank-advised-indent-threshold)
      (indent-region beg end nil)))

(defadvice yank (after yank-indent activate)
  "If current mode is one of 'yank-indent-modes,
indent yanked text (with prefix arg don't indent)."
  (if (and (not (ad-get-arg 0))
           (not (member major-mode yank-indent-blacklisted-modes))
           (or (derived-mode-p 'prog-mode)
               (member major-mode yank-indent-modes)))
      (let ((transient-mark-mode nil))
        (yank-advised-indent-function (region-beginning) (region-end)))))

(defadvice yank-pop (after yank-pop-indent activate)
  "If current mode is one of `yank-indent-modes',
indent yanked text (with prefix arg don't indent)."
  (when (and (not (ad-get-arg 0))
             (not (member major-mode yank-indent-blacklisted-modes))
             (or (derived-mode-p 'prog-mode)
                 (member major-mode yank-indent-modes)))
    (let ((transient-mark-mode nil))
      (yank-advised-indent-function (region-beginning) (region-end)))))

;; prelude-core.el
(defun indent-buffer ()
  "Indent the currently visited buffer."
  (interactive)
  (indent-region (point-min) (point-max)))

;; prelude-editing.el
(defcustom prelude-indent-sensitive-modes
  '(coffee-mode python-mode slim-mode haml-mode yaml-mode)
  "Modes for which auto-indenting is suppressed."
  :type 'list)

(defun indent-region-or-buffer ()
  "Indent a region if selected, otherwise the whole buffer."
  (interactive)
  (unless (member major-mode prelude-indent-sensitive-modes)
    (save-excursion
      (if (region-active-p)
          (progn
            (indent-region (region-beginning) (region-end))
            (message "Indented selected region."))
        (progn
          (indent-buffer)
          (message "Indented buffer.")))
      (whitespace-cleanup))))

(global-set-key (kbd "C-c i") 'indent-region-or-buffer)

;; add duplicate line function from Prelude
;; taken from prelude-core.el
(defun prelude-get-positions-of-line-or-region ()
  "Return positions (beg . end) of the current line
or region."
  (let (beg end)
    (if (and mark-active (> (point) (mark)))
        (exchange-point-and-mark))
    (setq beg (line-beginning-position))
    (if mark-active
        (exchange-point-and-mark))
    (setq end (line-end-position))
    (cons beg end)))

;; smart openline
(defun prelude-smart-open-line (arg)
  "Insert an empty line after the current line.
Position the cursor at its beginning, according to the current mode.
With a prefix ARG open line above the current line."
  (interactive "P")
  (if arg
      (prelude-smart-open-line-above)
    (progn
      (move-end-of-line nil)
      (newline-and-indent))))

(defun prelude-smart-open-line-above ()
  "Insert an empty line above the current line.
Position the cursor at it's beginning, according to the current mode."
  (interactive)
  (move-beginning-of-line nil)
  (newline-and-indent)
  (forward-line -1)
  (indent-according-to-mode))

(global-set-key (kbd "M-o") 'prelude-smart-open-line)
(global-set-key (kbd "M-o") 'open-line)

Move lines up/down

(defun move-line-up ()
  "Move up the current line."
  (interactive)
  (transpose-lines 1)
  (forward-line -2)
  (indent-according-to-mode))

(defun move-line-down ()
  "Move down the current line."
  (interactive)
  (forward-line 1)
  (transpose-lines 1)
  (forward-line -1)
  (indent-according-to-mode))

(global-set-key [(control shift up)]  'move-line-up)
(global-set-key [(control shift down)]  'move-line-down)

Releases

No releases published

Packages

No packages published