Skip to content

tsunagatteru/phantasm-emacs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

phantasm-emacs

~/.emacs.d/

./yukari.png

Table of Contents

Introduction

My personal emacs config, based on Witchmacs and Yukimacs.

Quick install

git clone https://github.com/tsunagatteru/phantasm-emacs ~/.emacs.d

Dependencies

  • clang as backend for C and C++ autocompletion
  • llvm to install irony server
  • mit-scheme for geiser to work
  • libvterm for vterm
  • pyright python lsp

QoL section

Minor quality-of-life modifications for a more pleasant Emacs experience

Enable line numbers

(add-hook 'prog-mode-hook 'display-line-numbers-mode)
(add-hook 'text-mode-hook 'display-line-numbers-mode)

Show parent parentheses

(show-paren-mode 1)

Disable the default startup screen

(setq inhibit-startup-message t)

Disable most gui elements

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

Enable copypasting outside of Emacs

(setq x-select-enable-clipboard t)

Disable automatic creation of backup files

(setq make-backup-files nil)
(setq auto-save-default nil)

Enable conservative scrolling

(setq scroll-conservatively 100)

Disable ring-bell

(setq ring-bell-function 'ignore)

Indentation

(setq-default tab-width 4)
(setq-default standard-indent 4)
(setq c-basic-offset tab-width)
(setq-default electric-indent-inhibit t)
(setq-default indent-tabs-mode t)
(setq backward-delete-char-untabify-method 'nil)

Enable prettify symbols mode

(global-prettify-symbols-mode t)

Enable bracket pair-matching

(setq electric-pair-pairs '(
                            (?\{ . ?\})
                            (?\( . ?\))
                            (?\[ . ?\])
                            (?\" . ?\")
                            ))
(electric-pair-mode t)

Creating a new window switches your cursor to it

(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)

Transform yes-or-no questions into y-or-n

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

Highlight current line

(global-hl-line-mode t)

Defer loading most packages for quicker startup times

(setq use-package-always-defer t)

Fill spaces

(setq frame-resize-pixelwise t)

Org mode

Everything org mode related

;; Source block expansion
(require 'org-tempo)
(add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp"))
Typing the below + TABExpands to …
<a’#+BEGIN_EXPORT ascii’ … ‘#+END_EXPORT
<c’#+BEGIN_CENTER’ … ‘#+END_CENTER’
<C’#+BEGIN_COMMENT’ … ‘#+END_COMMENT’
<e’#+BEGIN_EXAMPLE’ … ‘#+END_EXAMPLE’
<E’#+BEGIN_EXPORT’ … ‘#+END_EXPORT’
<h’#+BEGIN_EXPORT html’ … ‘#+END_EXPORT’
<l’#+BEGIN_EXPORT latex’ … ‘#+END_EXPORT’
<q’#+BEGIN_QUOTE’ … ‘#+END_QUOTE’
<s’#+BEGIN_SRC’ … ‘#+END_SRC’
<v’#+BEGIN_VERSE’ … ‘#+END_VERSE’
<el’#+BEGIN_SRC emacs-lisp’ … ‘#+END_SRC’
(use-package org
      :config
      (add-hook 'org-mode-hook 'org-indent-mode)
      (add-hook 'org-mode-hook
                #'(lambda ()
                   (visual-line-mode 1))))

(setq org-todo-keywords
        '((sequence
           "TODO(t)"
           "WAIT(w)"
           "PROCES(p)"
           "|"
           "DONE(d)"
           "CANCELLED(c)" )))

(use-package toc-org
  :after (org-mode markdown-mode)
  :hook
  (org-mode-hook . toc-org-mode)
  (markdown-mode-hook . toc-org-mode))

  (use-package org-indent
      :ensure nil
      :diminish org-indent-mode)

  (use-package htmlize)

  (use-package evil-org
     :ensure t
     :after org
     :config
     (require 'evil-org-agenda)
     (evil-org-agenda-set-keys))
  (add-hook `org-mode-hook `evil-org-mode)

Eshell

Prompt

(setq eshell-prompt-regexp "^[^αλ\n]*[αλ] ")
(setq eshell-prompt-function
      (lambda nil
        (concat
         (if (string= (eshell/pwd) (getenv "HOME"))
             (propertize "~" 'face `(:foreground "#99CCFF"))
           (replace-regexp-in-string
            (getenv "HOME")
            (propertize "~" 'face `(:foreground "#99CCFF"))
            (propertize (eshell/pwd) 'face `(:foreground "#99CCFF"))))
         (if (= (user-uid) 0)
             (propertize " α " 'face `(:foreground "#FF6666"))
           (propertize " λ " 'face `(:foreground "#A6E22E"))))))

(setq eshell-highlight-prompt nil)

Aliases

(defalias 'open 'find-file-other-window)
(defalias 'clean 'eshell/clear-scrollback)

Custom functions

Open files as root

(defun eshell/sudo-open (filename)
  "Open a file as root in Eshell."
  (let ((qual-filename (if (string-match "^/" filename)
                           filename
                         (concat (expand-file-name (eshell/pwd)) "/" filename))))
    (switch-to-buffer
     (find-file-noselect
      (concat "/sudo::" qual-filename)))))

Super - Control - RET to open eshell

(defun eshell-other-window ()
  "Create or visit an eshell buffer."
  (interactive)
  (if (not (get-buffer "*eshell*"))
      (progn
        (split-window-sensibly (selected-window))
        (other-window 1)
        (eshell))
    (switch-to-buffer-other-window "*eshell*")))

(global-set-key (kbd "<s-C-return>") 'eshell-other-window)

Visiting the configuration

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

Reloading the configuration

(defun config-reload ()
  "Reloads ~/.emacs.d/config.org at runtine"
  (interactive)
  (org-babel-load-file (expand-file-name "~/.emacs.d/config.org")))
(global-set-key (kbd "C-c r") 'config-reload)

vterm

A fully-fledged terminal inside Emacs.

(use-package vterm
  :defer t
  :config
  (setq vterm-always-compile-module t)
  (setq vterm-shell "/usr/bin/zsh"))

(use-package multi-vterm
  :after vterm
  :defer t)

Use-package section

auto-package-update

Automatically updates and removes old packages

(use-package auto-package-update
  :defer nil
  :config
  (setq auto-package-update-delete-old-versions t)
  (setq auto-package-update-hide-results t)
  (auto-package-update-maybe))

diminish

Hides minor modes to prevent cluttering your mode line

(use-package diminish)

spaceline

Spaceline, to use it`s theme

(use-package spaceline)

powerline

Thing at the bottom that shows current mode and other stuff

(use-package powerline
  :init
  (spaceline-spacemacs-theme)
  :hook
  ('after-init-hook) . 'powerline-reset)

dashboard

The frontend of Emacs

(use-package dashboard
  :defer nil
  :preface
  (defun update-config ()
    "Update to the latest version."
    (interactive)
    (let ((dir (expand-file-name user-emacs-directory)))
      (if (file-exists-p dir)
          (progn
            (message "Updating!")
            (cd dir)
            (shell-command "git pull")
            (message "Update finished. Switch to the messages buffer to see changes and then restart Emacs"))
        (message "\"%s\" doesn't exist." dir))))

  (defun create-scratch-buffer ()
    "Create a scratch buffer"
    (interactive)
    (switch-to-buffer (get-buffer-create "*scratch*"))
    (lisp-interaction-mode))
  :config
  (dashboard-setup-startup-hook)
  (setq initial-buffer-choice (lambda () (get-buffer-create "*dashboard*")))
  (setq dashboard-items '((recents . 5)))
  (setq dashboard-center-content t)
  (setq dashboard-banner-logo-title "\t ")
  (setq dashboard-startup-banner "~/.emacs.d/yukari.png")
  (setq dashboard-show-shortcuts nil)
  (setq dashboard-set-init-info t)
  (setq dashboard-init-info (format "%d packages loaded in %s"
                                    (length package-activated-list) (emacs-init-time)))
  (setq dashboard-set-footer nil)
  (setq dashboard-set-navigator t)
  (setq dashboard-navigator-buttons
        `(;; line1
          ((,nil
            "Github"
            "Open github page on your browser"
            (lambda (&rest _) (browse-url "https://github.com/tsunagatteru/phantasm-emacs"))
            'default)
           (nil
            "Update"
            "Get the latest update. Check out the github commits for changes!"
            (lambda (&rest _) (update-config))
            'default)
           )
          ;; line 2
          ((,nil
            "Open scratch buffer"
            "Switch to the scratch buffer"
            (lambda (&rest _) (create-scratch-buffer))
            'default)
           (nil
            "Open config.org"
            "Open configuration file for easy editing"
            (lambda (&rest _) (find-file "~/.emacs.d/config.org"))
            'default)))))

which-key

Command completeion

(use-package which-key
  :diminish which-key-mode
  :init
  (which-key-mode))

swiper

Minibuffer for C-s search

(use-package swiper
  :bind ("C-s" . 'swiper))

evil

Vim keybindings

(use-package evil
  :defer nil
  :init
  (setq evil-want-keybinding nil)
  (setq evil-want-C-u-scroll t)
  :config
  (evil-mode 1))

beacon

Highlights the cursor position when switching to a new window or buffer

(use-package beacon
  :diminish beacon-mode
  :init
  (beacon-mode 1))

switch-window

C-x o window switching keys

(use-package switch-window
  :config
  (setq switch-window-input-style 'minibuffer)
  (setq switch-window-increase 4)
  (setq switch-window-threshold 2)
  (setq switch-window-shortcut-style 'qwerty)
  (setq switch-window-qwerty-shortcuts
        '("a" "s" "d" "f" "j" "k" "l"))
  :bind
  ([remap other-window] . switch-window))

async

Utilize asynchronous processes whenever possible

(use-package async
  :init
  (dired-async-mode 1))

page-break-lines

(use-package page-break-lines
  :diminish (page-break-lines-mode visual-line-mode))

undo-tree

(use-package undo-tree
  :diminish undo-tree-mode)

treemacs

Side-bar file and project explorer

(use-package treemacs
  :defer t
  :init
  (with-eval-after-load 'winum
    (define-key winum-keymap (kbd "M-0") #'treemacs-select-window))
  :config
  (progn
    (setq treemacs-collapse-dirs                 (if (executable-find "python3") 3 0)
          treemacs-deferred-git-apply-delay      0.5
          treemacs-display-in-side-window        t
          treemacs-eldoc-display                 t
          treemacs-file-event-delay              5000
          treemacs-file-follow-delay             0.2
          treemacs-follow-after-init             t
          treemacs-git-command-pipe              ""
          treemacs-goto-tag-strategy             'refetch-index
          treemacs-indentation                   2
          treemacs-indentation-string            " "
          treemacs-is-never-other-window         nil
          treemacs-max-git-entries               5000
          treemacs-missing-project-action        'ask
          treemacs-no-png-images                 nil
          treemacs-no-delete-other-windows       t
          treemacs-project-follow-cleanup        nil
          treemacs-persist-file                  (expand-file-name ".cache/treemacs-persist" user-emacs-directory)
          treemacs-recenter-distance             0.1
          treemacs-recenter-after-file-follow    nil
          treemacs-recenter-after-tag-follow     nil
          treemacs-recenter-after-project-jump   'always
          treemacs-recenter-after-project-expand 'on-distance
          treemacs-show-cursor                   nil
          treemacs-show-hidden-files             t
          treemacs-silent-filewatch              nil
          treemacs-silent-refresh                nil
          treemacs-sorting                       'alphabetic-desc
          treemacs-space-between-root-nodes      t
          treemacs-tag-follow-cleanup            t
          treemacs-tag-follow-delay              1.5
          treemacs-width                         30)
    (treemacs-resize-icons 11)

    (treemacs-follow-mode t)
    (treemacs-filewatch-mode t)
    (treemacs-fringe-indicator-mode t)
    (pcase (cons (not (null (executable-find "git")))
                 (not (null (executable-find "python3"))))
      (`(t . t)
       (treemacs-git-mode 'deferred))
      (`(t . _)
       (treemacs-git-mode 'simple))))
  :bind
  (:map global-map
        ("M-0"       . treemacs-select-window)
        ("C-x t 1"   . treemacs-delete-other-windows)
        ("C-x t t"   . treemacs)
        ("C-x t B"   . treemacs-bookmark)
        ("C-x t C-t" . treemacs-find-file)
        ("C-x t M-t" . treemacs-find-tag)))

(use-package treemacs-evil
  :after treemacs evil
  :ensure t)

(use-package treemacs-icons-dired
  :after treemacs dired
  :ensure t
  :config (treemacs-icons-dired-mode))

ido and ido-vertical

Better buffer switching and killing

(use-package ido
  :init
  (ido-mode 1)
  :config
  (setq ido-enable-flex-matching nil)
  (setq ido-create-new-buffer 'always)
  (setq ido-everywhere t))

(use-package ido-vertical-mode
  :init
  (ido-vertical-mode 1))
(setq ido-vertical-define-keys 'C-n-C-p-up-and-down)

eldoc

(use-package eldoc
  :diminish eldoc-mode)

abbrev

 (use-package abbrev
   :ensure nil
	:diminish abbrev-mode)

ranger

File manager

(use-package ranger
  :init
  (ranger-override-dired-mode t)
  (setq ranger-cleanup-on-disable t)
  (setq ranger-show-hidden t)
  (setq ranger-preview-file t)
  (setq ranger-show-literal nil)
  (setq ranger-dont-show-binary t))

Programming

projectile

Project management.

(use-package projectile
  :config
  (projectile-mode t)
  (define-key projectile-mode-map (kbd "C-x p") 'projectile-command-map)
  ;(setq projectile-track-known-projects-automatically nil)
  (setq projectile-enable-caching t)
  (setq projectile-require-project-root t)
  (setq projectile-dynamic-mode-line nil))

yasnippet

Useful snippets.

(use-package yasnippet
  :config
    ;;(use-package yasnippet-snippets)
    ;;(use-package auto-yasnippet)
  (yas-reload-all)
  (yas-global-mode))

(global-set-key (kbd "C-c y") 'yas-insert-snippet)

flycheck

Syntax checking.

(use-package flycheck
  :hook (after-init . global-flycheck-mode)
  :custom
  (flycheck-check-syntax-automatically '(save mode-enabled)))

eldoc

Display documentation (e.g. arguments of a function).

(use-package eldoc
  :hook (after-init . global-eldoc-mode))

LSP

Language server. Will provide us with IDE-like features.

(use-package lsp-mode
  :commands lsp
  :custom
  (lsp-auto-guess-root t)
  (lsp-log-io t)
  (read-process-output-max (* 1024 1024)) 
  (lsp-idle-delay 0.5)
  (lsp-prefer-flymake nil))

;; Enhance UI
(use-package lsp-ui
  :after (lsp-mode)
  :hook (lsp-mode . lsp-ui-mode)
  :custom
  (lsp-ui-doc-enable nil)
  (lsp-ui-doc-header t)
  ;(lsp-ui-doc-delay 2.0)
  (lsp-ui-doc-include-signature t)
  (lsp-ui-flycheck-enable t)
  (lsp-ui-peek-always-show t)
  (lsp-ui-sideline-show-code-actions t)
  (lsp-ui-sideline-delay 0.05))

;(use-package dap-mode
;  :after lsp-mode
;  :config
;  (dap-mode t)
;  (dap-ui-mode t))

(use-package lsp-treemacs
  :after (lsp-mode)
  :commands lsp-treemacs
  :config
  (lsp-treemacs-sync-mode 1))

(setq lsp-lens-enable nil)
;(setq lsp-enable-file-watchers nil)

company

Provides completion.

 (use-package company
   :after lsp-mode
   :bind
   (:map company-active-map
         ("C-n". company-select-next)
         ("C-p". company-select-previous)
         ("M-<". company-select-first)
         ("M->". company-select-last)
         ("<tab>" . company-complete-selection))
 (:map lsp-mode-map
         ("<tab>" . company-indent-or-complete-common))
   :config
   (setq company-dabbrev-other-buffers t
         company-dabbrev-code-other-buffers t)
   :custom
   (company-minimum-prefix-length 1)
   (company-idle-delay 0.3)
   :hook ((text-mode . company-mode)
          (prog-mode . company-mode)
          (org-mode . company-mode)
          (company-mode . yas-minor-mode)
          (lsp-mode . company-mode)))

 (use-package company-box
   :hook (company-mode . company-box-mode))

 (use-package company-prescient
   :after (selectrum company)
   :config
   (company-prescient-mode 1)
   (prescient-persist-mode))

(add-hook 'after-init-hook 'global-company-mode)

Sqlite

(use-package sqlite3)

C & C++

(use-package ccls
  :config
  (setq ccls-executable "ccls")
  (setq lsp-prefer-flymake nil)
  (setq-default flycheck-disabled-checkers '(c/c++-clang c/c++-cppcheck c/c++-gcc))
  (setq ccls-sem-highlight-method 'overlay)
  :hook ((c-mode c++-mode) .
         (lambda () (require 'ccls) (lsp) (yas-minor-mode))))

(setq-default c-basic-offset 4)

CMake

(use-package cmake-mode)

Python

(use-package lsp-pyright
:hook (python-mode . (lambda () (require 'lsp-pyright) (lsp)))
:init (when (executable-find "python3")
        (setq lsp-pyright-python-executable-cmd "python3")))
(use-package pyvenv)

Lisp

(add-hook 'emacs-lisp-mode-hook 'eldoc-mode)
(add-hook 'emacs-lisp-mode-hook 'yas-minor-mode)

(use-package slime
  :config
  (setq inferior-lisp-program "/usr/bin/sbcl") ;; install SBCL from your repos
  (setq slime-contribs '(slime-fancy)))

(use-package helpful
  :custom
  (counsel-describe-function-function #'helpful-callable)
  (counsel-describe-variable-function #'helpful-variable)
  :bind
  ([remap describe-function] . counsel-describe-function)
  ([remap describe-command] . helpful-command)
  ([remap describe-variable] . counsel-describe-variable)
  ([remap describe-key] . helpful-key))

(use-package geiser-mit)

Go

(use-package go-mode
  :hook (go-mode . lsp-deferred))

;; Set up before-save hooks to format buffer and add/delete imports.
;; Make sure you don't have other gofmt/goimports hooks enabled.
(defun lsp-go-install-save-hooks ()
  (add-hook 'before-save-hook #'lsp-format-buffer t t)
  (add-hook 'before-save-hook #'lsp-organize-imports t t))
(add-hook 'go-mode-hook #'lsp-go-install-save-hooks)

JSON

(use-package json-mode
  :mode (("\\.json\\'" . json-mode)))

Markdown

(use-package markdown-mode
  :mode (("README\\.md\\'" . gfm-mode)
         ("\\.md\\'" . markdown-mode)
         ("\\.markdown\\'" . markdown-mode))
  :init (setq markdown-command "multimarkdown"))

LaTeX

(use-package auctex
  :hook
  (TeX-mode . TeX-PDF-mode)
  (TeX-mode . company-mode)
  (LaTeX-mode . (lambda ()
                  (push (list 'output-pdf "Zathura")
                            TeX-view-program-selection)))
  :init
  (setq reftex-plug-into-AUCTeX t)
  (setq TeX-parse-self t)
  (setq-default TeX-master nil)
  (setq TeX-open-quote  "<<")
  (setq TeX-close-quote ">>")
  (setq TeX-electric-sub-and-superscript t)
  (setq font-latex-fontify-script nil)
  (setq TeX-show-compilation nil)
  (setq reftex-label-alist '(AMSTeX)))

(use-package company-auctex
  :init
  (company-auctex-init))

(use-package company-reftex
  :init
  (add-to-list 'company-backends 'company-reftex-citations)
  (add-to-list 'company-backends 'company-reftex-labels))

Git integration

(use-package magit
  :config
  (setq magit-push-always-verify nil)
  (setq git-commit-summary-max-length 50)
  :bind
  ("M-g" . magit-status))

(use-package treemacs-magit
  :after treemacs magit)

(use-package ghub
  :demand t
  :after magit)

Web-mode

(use-package web-mode)

Python-venv

(use-package pyvenv)

C#

(use-package csharp-mode)

Devops

Yaml

(use-package yaml-mode
  :commands yaml-mode)

Terraform

(use-package terraform-mode)

Docker

(use-package dockerfile-mode
  :mode (("Dockerfile.*\\'" . dockerfile-mode)))

Systemd

(use-package systemd)

Powershell

(use-package powershell)

Nginx

(use-package nginx-mode)

Jenkins

(use-package jenkinsfile-mode
  :mode (("Jenkinsfile.*\\'" . jenkinsfile-mode)))

About

My emacs configuration files

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •