Skip to content

Latest commit

 

History

History
544 lines (472 loc) · 21 KB

my-stock-changes.org

File metadata and controls

544 lines (472 loc) · 21 KB

My emacs configuration in org-mode

About this file

<<babel-init>>

Ressources used to create this org-mode powered init file:

Information about tangling:

Starting up

Here’s how we start:

;; This sets up the load path so that we can override it
(package-initialize)
;; Override the packages with the git version of Org and other packages
(add-to-list 'load-path "~/.emacs.d/elpa/org-plus-contrib-20170731/")
(setq package-enable-at-startup nil)
(setq custom-file "~/.emacs.d/custom-settings.el")
;;(load custom-file t)

Emacs bootstrap

Add package sources

This block adds the melpa and org repository if they aren’t added already. This way this command is stateless which helps for debugging.

      ;; (unless (assoc-default "melpa" package-archives)
      ;;   (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)
      ;;   ; (package-refresh-contents)
      ;; )
      ;; (unless (assoc-default "org" package-archives)
      ;;   ; added for org-plus-contrib package
      ;;   (add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
      ;; 	; (package-refresh-contents)
      ;; )
(custom-set-variables
  '(package-archives
   '(("melpa" . "http://melpa.org/packages/")
     ("elpa" . "http://elpa.gnu.org/packages/"))))

Use M-x package-refresh-contents to reload the list of packages after adding these for the first time.

Problems with melpa packages:

  • yasnippet doesnt unpack from melpa
  • usepackage is only available on melpa
  • smartparens crashes when not installed from melpa

Add my elisp directory and use-package

Sometimes I load files outside the package system. As long as they’re in a directory in my load-path, Emacs can find them.

I create the elpa directory if it doesnt exist since emacs will otherwise complain while loading the packages.

(unless (file-exists-p "~/.emacs.d/elpa")
  (make-directory "~/.emacs.d/elpa"))
(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)
(use-package auto-compile
  :config (auto-compile-on-load-mode))
(setq load-prefer-newer t)

Emacs vanilla setting corrections

Config in here is independant of specific packages, so it basically is for improving vanilla emacs.

Libraries

Dash is “A modern list library for Emacs” and is required by everything. To avoid / fix errors I load it explicitly and early.

(use-package dash)

Tab Line Mode

A very handy mode, which will display VS-Code like tabs at the top of the buffer. It has been enabled by default in recent emacs versions.

I find the default theming of the tabs almost unusable. Luckily, somebody else already looked into the customziation (kuduz amitp!):

(require 'tab-line)
(set-face-attribute 'tab-line nil ;; background behind tabs
      :background "gray20"
      :foreground "gray60" :distant-foreground "gray50"
      :family "Fira Sans Condensed" :height 1.1 :box nil)
(set-face-attribute 'tab-line-tab nil ;; active tab in another window
      :inherit 'tab-line
      :foreground "gray70" :background "gray90" :box nil)
(set-face-attribute 'tab-line-tab-current nil ;; active tab in current window
      :background "gray10" :foreground "white" :box nil)
(set-face-attribute 'tab-line-tab-inactive nil ;; inactive tab
      :background "gray60" :foreground "black" :box nil)
(set-face-attribute 'tab-line-highlight nil ;; mouseover
      :background "DarkOrange1" :foreground "White")

Coding style

(setq prefer-coding-system 'utf-8-unix)
(setq coding-system-for-read 'utf-8-unix)
(setq coding-system-for-write 'utf-8-unix)
;; Disable tabs
(setq-default indent-tabs-mode nil)
(setq tab-width 4)

Line intendation, Linewrap and Word wrap

(setq-default fill-column 98)
(setq hscroll-step 1)
(auto-fill-mode 1) ;; the mode responsible for adding line-endings after fill-column is reached
(add-hook 'text-mode-hook 'turn-on-auto-fill) ;; turn on auto-fill-mode automatically
;; Toggle for auto-fill-mode
(global-set-key (kbd "C-c q") 'auto-fill-mode)
(setq auto-hscroll-mode nil) ;; i sometimes toggle this manually for source-blocks with long lines
;; to still be able to just paste them in the current buffer. More info on this, specifically
;; regarding programming: https://www.emacswiki.org/emacs/AutoFillMode

Conveniences

Emacs Startup changes

(setq inhibit-default-init t)
(setq inhibit-startup-screen t)
(setq transient-mark-mode 1)
(global-tab-line-mode t)

Take the short answer, y/n is yes/no

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

Start the emacs server such that i can open new files conveniently using the explorer

(require 'server)
(unless (server-running-p)
  (server-start))
;; remove the annoying prompt that occurs when killing such a file
(remove-hook 'kill-buffer-query-functions 'server-kill-buffer-query-function)
;; For my windows-PC this is necessary in addition:
;; C:\Program Files (x86)\emacs\bin\emacsclientw.exe --alternate-editor="C:\Program Files (x86)\emacs\bin\runemacs.exe" "%1"
;; This previous line should be included in the standard
;; REG_SZ key at HKEY_CLASSES_ROOT/*/shell/Open with Emacs/command

Overwrite selected text

(delete-selection-mode t)

Dired

(setq dired-listing-switches "-alh")

No splash screen please … jeez

(setq inhibit-startup-message t)

Backups: This is one of the things people usually want to change right away. By default, Emacs saves backup files in the current directory. These are the files ending in ~ that are cluttering up your directory lists. The following code stashes them all in ~/.emacs.d/backups, where I can find them with C-x C-f (find-file) if I really need to.

(setq backup-directory-alist '(("." . "~/.emacs.d/backups")))

Default to better frame titles

(setq frame-title-format
(concat  "%b - emacs@" (system-name)))

Default to unified diffs

(setq diff-switches "-u")

Transparency settings

(set-frame-parameter (selected-frame) 'alpha '(93 93)) ;; affects the current window
(add-to-list 'default-frame-alist '(alpha 93 93)) ;; affects newly opened windows

Customize the interface to be more slim

(tooltip-mode 0)
(tool-bar-mode 0)
(menu-bar-mode 1)
(scroll-bar-mode 0)

Stop cursor from blinking

(blink-cursor-mode 0)
(if (fboundp 'blink-cursor-mode)
    (blink-cursor-mode 0))

Remove alarm (bell) on scroll

(setq ring-bell-function 'ignore)

;; Intuitive Buffer-changing
(global-set-key [(control next)] 'next-buffer)
(global-set-key [(control prior)] 'previous-buffer)

Improve the scrolling to make emacs feel more like an editor Problems:

  • Cant install this on my work pc
  • I cant scroll all the way up using C-v
(require 'sublimity)
(require 'sublimity-scroll)
(sublimity-mode 1)

Highlight the current line (mostly useful for going through logs)

;; Highlight current line (slows down C-n and C-p immensly)
;; (global-hl-line-mode 1)
;; (set-face-background 'hl-line "#cc0033") ;; crimson

Highlight matching parenthesis

;; Show matching parenthesis without delay
(setq show-paren-delay 0)
;; Activate the mode
(show-paren-mode t)

Keep the buffer history as one would expect

;; Save minibuffer history
(savehist-mode 1)
;; Delete duplicates in minibuffer history
(setq history-delete-duplicates t)
(setq savehist-save-minibuffer-history 1)
(setq history-length t)
(setq savehist-additional-variables '(kill-ring search-ring regexp-search-ring last-kbd-macro kmacro-ring shell-command-history))

Clean up unnecessary spaces on save and show them while they are still there.

(add-hook 'before-save-hook 'delete-trailing-whitespace)
(toggle-indicate-empty-lines t)
(setq show-trailing-whitespace t)

Fonts

Font Menu for Windows

Adds a convenient UI to select the font (only available on windows).

;; "Select an Emacs font from a list of known good fonts and fontsets.
(defun mouse-set-font (&rest fonts)
  ;;If `w32-use-w32-font-dialog' is non-nil (the default), use the Windows
  ;;font dialog to display the list of possible fonts.  Otherwise use a
  ;;pop-up menu (like Emacs does on other platforms) initialized with
  ;;the fonts in `w32-fixed-font-alist'.
  ;;If `w32-list-proportional-fonts' is non-nil, add proportional fonts
  ;;to the list in the font selection dialog (the fonts listed by the
  ;;pop-up menu are unaffected by `w32-list-proportional-fonts')."
  (interactive
   (if w32-use-w32-font-dialog
       (let ((chosen-font (w32-select-font (selected-frame)
     				      w32-list-proportional-fonts)))
         (and chosen-font (list chosen-font)))
     (x-popup-menu
      last-nonmenu-event
      ;; Append list of fontsets currently defined.
      ;; Conditional on new-fontset so bootstrapping works on non-GUI compiles
      (if (fboundp 'new-fontset)
          (append w32-fixed-font-alist (list (generate-fontset-menu)))))))
  (if fonts
      (let (font)
        (while fonts
          (condition-case nil
              (progn
                (setq font (car fonts))
     	   (set-default-font font)
                (setq fonts nil))
            (error (setq fonts (cdr fonts)))))
        (if (null font)
            (error "Font not found")))))

Font settings for Linux

Installation instructions: https://askubuntu.com/questions/193072/how-to-use-the-adobe-source-code-pro-font

(setq myfont "-ADBO-Source Code Pro-normal-normal-normal-*-18-*-*-*-m-0-iso10646-1")
(if (string-equal system-type "gnu/linux")
    (progn (set-frame-font "-ADBO-Source Code Pro-normal-normal-normal-*-18-*-*-*-m-0-iso10646-1" nil t) ;; current frame and future frames
           (add-to-list 'default-frame-alist '(font . "-ADBO-Source Code Pro-normal-normal-normal-*-18-*-*-*-m-0-iso10646-1" )) ;; default font for new frames
           (set-face-attribute 'default t :font "-ADBO-Source Code Pro-normal-normal-normal-*-18-*-*-*-m-0-iso10646-1" ) ;; default font for new frames
           )
  )

Font settings for Mac

How to install: https://github.com/belluzj/fantasque-sans

(if (string-equal system-type "darwin")
    (progn (set-frame-font "-*-Fantasque Sans Mono-normal-normal-normal-*-17-*-*-*-m-0-iso10646-1" nil t) ;; current frame and future frames
           (add-to-list 'default-frame-alist '(font . "-*-Fantasque Sans Mono-normal-normal-normal-*-17-*-*-*-m-0-iso10646-1" )) ;; default font for new frames
           (set-face-attribute 'default t :font "-*-Fantasque Sans Mono-normal-normal-normal-*-17-*-*-*-m-0-iso10646-1" ) ;; default font for new frames
           )
  )

Increase font setting globally

The default binding for increasing the font-size only increases it for the current frame. With this approch i can increase the font-size globally.

Taken from here: http://emacsninja.com/posts/making-emacs-more-presentable.html

(defun my-alter-frame-font-size (fn)
  (let* ((current-font-name (frame-parameter nil 'font))
         (decomposed-font-name (x-decompose-font-name current-font-name))
         (font-size (string-to-number (aref decomposed-font-name 5))))
    (aset decomposed-font-name 5 (int-to-string (funcall fn font-size)))
    (set-frame-font (x-compose-font-name decomposed-font-name))))

(defun my-inc-frame-font-size ()
  (interactive)
  (my-alter-frame-font-size '1+))

(defun my-dec-frame-font-size ()
  (interactive)
  (my-alter-frame-font-size '1-))

(global-set-key (kbd "C-+") 'my-inc-frame-font-size)
(global-set-key (kbd "C-=") 'my-inc-frame-font-size)
(global-set-key (kbd "C--") 'my-dec-frame-font-size)

Eshell

Introduce some eshell keybindings.

(add-hook 'eshell-mode-hook '(lambda ()
                               ;; Make the eshell behave like a normal shell
                               (local-set-key (kbd "C-p") 'eshell-previous-input)
                               (local-set-key (kbd "M-p") 'previous-line)
                               (local-set-key (kbd "C-n") 'eshell-next-input)
                               (local-set-key (kbd "M-n") 'next-line)
                               (setq pcomplete-cycle-completions nil)
                               ))
(global-set-key (kbd "C-c e") 'eshell)

Visual commands are commands which require a proper terminal (dont work well in eshell itself). Eshell will run them in a term buffer when you invoke them.

(setq eshell-visual-commands
      '("less" "tmux" "htop" "top" "bash" "zsh" "fish"))
(setq eshell-visual-subcommands
      '(("git" "log" "l" "diff" "show")))

Basic coloring (sadly doesnt work for aliases even with the –color flag).

(custom-set-faces
 '(eshell-ls-archive ((t (:foreground "gold1" :weight bold))))
 '(eshell-ls-backup ((t (:foreground "LemonChiffon1"))))
 '(eshell-ls-directory ((t (:foreground "brown1" :weight bold))))
 '(eshell-prompt ((t (:foreground "firebrick" :weight bold))))
 )

Attempts to make a good looking git-prompt in eshell. Breaks my windows emacs since it cant display the characters used for styling, therefor untangled.

(use-package eshell-git-prompt
  :ensure t
  :config
  (require 'powerline)
  (eshell-git-prompt-use-theme 'powerline))

Fancy eshell looks. (Taken from here: https://www.reddit.com/r/emacs/comments/6f0rkz/my_fancy_eshell_prompt/) Curretly untangled since the colors are too bright.

(setq eshell-prompt-function
      (lambda ()
        (concat
         (propertize "┌─[" 'face `(:foreground "green"))
         (propertize (user-login-name) 'face `(:foreground "red"))
         (propertize "@" 'face `(:foreground "green"))
         (propertize (system-name) 'face `(:foreground "dodger blue"))
         (propertize "]──[" 'face `(:foreground "green"))
         (propertize (format-time-string "%H:%M" (current-time)) 'face `(:foreground "yellow"))
         (propertize "]──[" 'face `(:foreground "green"))
         (propertize (concat (eshell/pwd)) 'face `(:foreground "white"))
         (propertize "]\n" 'face `(:foreground "green"))
         (propertize "└─>" 'face `(:foreground "green"))
         (propertize (if (= (user-uid) 0) " # " " $ ") 'face `(:foreground "green"))
         )))

Disable Secondary selection

Taken from here: https://www.reddit.com/r/emacs/comments/3c61zl/abolish_the_secondary_selection_quick_and_easy/

(global-set-key [remap mouse-drag-secondary] 'mouse-drag-region)
(global-set-key [remap mouse-set-secondary] 'mouse-set-region)
(global-set-key [remap mouse-start-secondary] 'mouse-set-point)
(global-set-key [remap mouse-yank-secondary] 'mouse-yank-primary)
(global-set-key [remap mouse-secondary-save-then-kill] 'mouse-save-then-kill)

Exclude async command from buffer popup

I currently need this for my function “fbr/open-file-dir”, so it smoothly opens a file browser in the background without disturbing my emacs session so much.

;; Buffers that I don't want popping up by default
(add-to-list 'display-buffer-alist
  '("\\*Async Shell Command\\*.*" display-buffer-no-window))

Open terminal in current directory

(defun fbr/open-terminal-in-working-dir ()
   "Open the directory of the current file in OS file browser."
   (interactive)
   (if (string-equal system-type "windows-nt")
    	  (shell-command (concat "explorer " (replace-regexp-in-string "/" "\\\\" (file-name-directory (buffer-file-name)))))

     )
   (if (string-equal system-type "gnu/linux")
    	  (async-shell-command (concat "gnome-terminal " (file-name-directory (buffer-file-name))))
     )
   (if (string-equal system-type "darwin")
    	  (async-shell-command (concat "open -a iTerm " (file-name-directory (buffer-file-name))))
     )
   )

Open current directory in nautilus / explorer

(defun fbr/open-file-dir ()
   "Open the directory of the current file in OS file browser."
   (interactive)
   (if (string-equal system-type "windows-nt")
    	  (shell-command (concat "explorer " (replace-regexp-in-string "/" "\\\\" (file-name-directory (buffer-file-name)))))

     )
   (if (string-equal system-type "gnu/linux")
    	  (async-shell-command (concat "nautilus " (file-name-directory (buffer-file-name))))
     )
   (if (string-equal system-type "darwin")
    	  (async-shell-command (concat "open -a Finder " (file-name-directory (buffer-file-name))))
     )
   )

Nerfing the kill command

(defun nerfed-kill ()
  (interactive)
  (if (use-region-p)
      (kill-region (region-beginning) (region-end))))

(global-set-key (kbd "C-w") 'nerfed-kill)

Keybindings

Took this idea from baron42bba’s config, together with “which-key” this gives me a launcher-like menu with an overview about all my custom key-bindings

(define-prefix-command 'fbr/launcher)
(define-key global-map "\C-xl" 'fbr/launcher)
(define-key fbr/launcher "o" 'fbr/open-file-dir)
(define-key fbr/launcher "t" 'fbr/open-terminal-in-working-dir)
(define-key fbr/launcher "T" 'fbr/tea-timer)
(define-key fbr/launcher "r" 'fbr/org-agenda-reduce-to-current-file)
(define-key fbr/launcher "y" 'fbr/reload-yasnippet)

From the “Mastering Emacs” book comes this customization. It replaces the “set font” function to introduce a quicker keystroke to access “other-window”.

(global-set-key (kbd "M-o") 'other-window)

Set the key modifiers on Mac to behave similarly to Linux or Windows.

(if (string-equal system-type "darwin")
    (setq mac-command-modifier 'meta
          mac-right-option-modifier 'none
          mac-option-modifier 'super)
  )

Set certain paths when on university pc

These settings are for the university PC

;; test tls connection on windows for successfull download of packages
;; makes sure this returns t in the echo area
(gnutls-available-p)
(setenv "PATH" (concat (getenv "PATH") ";H:\\Win7PoolData\\Desktop\\emacs\\bin"))
;; For Git
(add-to-list 'exec-path "H:/Win7PoolData/Desktop/PortableGit/mingw64/bin")
;; For Graphviz
(setenv "PATH" (concat (getenv "PATH") ";H:\\Win7PoolData\\Desktop\\GraphViz\\bin"))
(setq exec-path (append exec-path '("H:/Win7PoolData/Desktop/GraphViz/bin")))

.