The SSH host key has changed on 8 April, 2022 to this one: SHA256:573uTBSeh74kvOo0HJXi5ijdzRm8me27suzNEDlGyrQ
My .emacs.d directory
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 KiB

Add some directories to load-path

My own (version controlled) lisp directory

(add-to-list 'load-path (expand-file-name
                         (convert-standard-filename "lisp/")
(add-to-list 'load-path (expand-file-name
                         (convert-standard-filename "lisp/nyan-prompt")

The local site-lisp

…if it exists.

(let ((site-lisp-dir "/usr/local/share/emacs/site-lisp"))
  (when (file-directory-p site-lisp-dir)
    (dolist (elt (directory-files site-lisp-dir))
      (unless (or (string= elt ".") (string= elt ".."))
        (add-to-list 'load-path (expand-file-name elt site-lisp-dir))))))

Load some prerequisites

Load xdg-paths

(load "xdg-paths")

Load the tango dark theme

(load-theme 'tango-dark t)

Emacs configuration

Set up the package archives

(require 'package)
(add-to-list 'package-archives
             '("gnu" . ""))
(add-to-list 'package-archives
             '("melpa-stable" . "") t)
(add-to-list 'package-archives
             '("melpa" . "") t)
(add-to-list 'package-archives
             '("org" . "") t)

Configure use-package and preload bind-key

(unless (package-installed-p 'use-package)
  (package-install 'use-package))

(require 'use-package)

(customize-set-variable 'use-package-always-ensure t)
(customize-set-variable 'use-package-verbose nil)

(use-package bind-key)

Install and configure Quelpa

(unless (package-installed-p 'quelpa)
    (url-insert-file-contents "")

And quelpa-use-package, too!

   :fetcher git
   :url ""))
(require 'quelpa-use-package)

Set up the really basic things

(use-package emacs
  :ensure nil
  (user-full-name "Gergely Polonkai")
  (user-mail-address "")
  (kill-read-only-ok t)
  (use-dialog-box nil))

Set up my personal keymap

I set it up early so i can use it in use-package calls immediately.

(defvar gpolonkai/pers-map (make-sparse-keymap)
  "My own, personal, keymap!")
(define-prefix-command 'gpolonkai/pers-map)
(define-key ctl-x-map "t" 'gpolonkai/pers-map)
(define-key global-map (kbd "C-t") 'gpolonkai/pers-map)

I really don’t want to type more than i really must…

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

Set UTF-8 as the default encoding

Just to make sure, although most Linux DEs do this for me.

(set-language-environment "UTF-8")
(set-default-coding-systems 'utf-8)

Set Org’s main directory

Since a lot of packages use it as their base (org-projectile, org-caldav, etc.), i need it as early as possible.

(setq org-directory (expand-file-name "NextCloud/orgmode" user-documents-directory))

Custom commands and functions

Utility functions

Check if something is nil or a list of strings

(defun nil-or-list-of-strings-p (var)
  "Return t if VAR is either nil or a list holding only strings."
  (or (null var)
      (not (null (delq nil
            (mapcar (lambda (x) (and (stringp x) x)) var))))))

Get the number at point

(defun get-number-at-point ()
  (skip-chars-backward "0123456789.-")
  (or (looking-at "[0123456789.-]+")
      (error "No number at point"))
  (string-to-number (match-string 0)))

Round number at point to the given decimals

(defun round-number-at-point-to-decimals (decimal-count)
  (interactive "NDecimal count: ")
  (let ((mult (expt 10 decimal-count)))
    (replace-match (number-to-string

Make a backup filename under user-emacs-cache-directory

Taken from Xah’s site.

(defun xah/backup-file-name (fpath)
    "Return a new file path for FPATH under `user-emacs-cache-directory'"
    (let* ((backup-root-dir (expand-file-name "backup" user-emacs-cache-directory))
           (file-path (replace-regexp-in-string "[A-Za-z]:" "" fpath))
           (backup-file-path (replace-regexp-in-string "//" "/" (concat backup-root-dir file-path "~"))))
      (make-directory (file-name-directory backup-file-path) (file-name-directory backup-file-path))

Run a function on a region

(defun func-region (start end func)
  "Run a function over the region between START and END in current buffer."
    (let ((text (delete-and-extract-region start end)))
      (insert (funcall func text)))))

Check if we are running under Termux

We need to do things differently, if so.

(defun termux-p ()
  "Check if Emacs is running under Termux."
   (regexp-quote "/com.termux/")
   (expand-file-name "~")))

Misc text manipulation functions

Delete the current line

(defun gpolonkai/delete-current-line ()
  "Kill the whole line on which point is."

  (kill-line 1))

Duplicate current line

(defun gpolonkai/duplicate-line()
  "Duplicate line at point."


    (move-beginning-of-line 1)
    (open-line 1)
    (forward-line 1)

Toggle case of character at point

Based on Xah’s toggle letter case defun version 2015-12-22

(defun toggle-char-case (arg-move-point)
  "Toggle the case of the char after point.

If prefix argument ARG-MOVE-POINT is non-nil, move point after the char."
  (interactive "P")
  (let ((case-fold-search nil))
     ((looking-at "[[:lower:]]") (upcase-region (point) (1+ (point))))
     ((looking-at "[[:upper:]]") (downcase-region (point) (1+ (point)))))
     (arg-move-point (right-char)))))

Open a new line below

Copied from

(defun open-line-below ()
  "Open a new line below point."



Open a new line above

(defun open-line-above ()
  "Open a new line above point."


  (forward-line -1)

TODO Kill or copy the whole line

Got from Xah’s site (TODO is for adding a link here.)

(defun æ-kill-or-copy-whole-line (kill)
  "Kill or copy the whole line point is on.

If KILL is non-nil, the line gets killed.  Otherwise, it gets just
copied to the kill ring."
  (interactive "P")

  (if kill
    (let ((beginning (progn (beginning-of-line) (point)))
          (end (progn (end-of-line) (point))))
      (copy-region-as-kill beginning end))))

Enclose region in a specific character

(defun gpolonkai/enclose-region (character &optional start end)
  "Enclose region between CHARACTER.

If region is empty and neither START nor END is set, simply inserts CHARACTER
two times and moves point between them.

If character is present in `insert-pair-alist', this function will enclose
region in the corresponding pair.  In this case, CHARACTER must be the opening
member of the pair."

  (interactive "cWhat character? \nr")

  (let ((open character)
        (close character)
        (pair (assq character insert-pair-alist)))
    (if pair
        (if (nth 2 pair)
            (setq open (nth 1 pair) close (nth 2 pair))
          (setq open (nth 0 pair) close (nth 1 pair))))
    (unless (and open close)
      (setq open character
            close character))
    (unless (use-region-p)
      (setq start (point)
            end (point)))
      (goto-char end)
      (insert-char close)

      (goto-char start)
      (insert-char open))
    (unless (use-region-p)

Convert camelCase to snake_case

(defun camel-to-snake-case (arg)
  "Convert a camelCase word to snake_case.

If the prefix argument ARG is non-nil, convert the text to uppercase."
  (interactive "p")
    (let ((start (region-beginning))
          (end (region-end))
          (case-fold-search nil)
          (had-initial-underscore nil))
      (goto-char start)
      (when (looking-at "_") (setq had-initial-underscore t))
      (while (re-search-forward "\\([A-Z]\\)" end t)
        (replace-match "_\\1")
        (setq end (1+ end)))
      (if arg
          (upcase-region start end)
        (downcase-region start end))
      (goto-char start)
      (unless had-initial-underscore (delete-char 1)))))

Insert two spaces after specific characters

(defun org-space-key (&optional arg)
  "Insert two spaces after a period.

ARG will be passed down verbatim to `self-insert-command'"
  (interactive "p")

  (when (looking-back "[.!?…]" nil)
    (call-interactively 'self-insert-command arg))
  (call-interactively 'self-insert-command arg))

Fill or unfill a paragraph

(defun sachachua/fill-or-unfill-paragraph (&optional unfill region)
  "Fill (or unfill, if UNFILL is non-nil) paragraph (or REGION)."
  (interactive (progn
                 (list (if current-prefix-arg 'unfill) t)))
  (let ((fill-column (if unfill (point-max) fill-column)))
    (fill-paragraph nil region)))

Swap occurences of strings

(defun so/query-swap-strings (from-string
                              &optional delimited start end)
  "Swap occurrences of FROM-STRING and TO-STRING.

DELIMITED, START, and END are passed down verbatim to `perform-replace'."
   (let ((common
           (concat "Query swap"
                   (if current-prefix-arg
                       (if (eq current-prefix-arg '-) " backward" " word")
                   (if (use-region-p) " in region" ""))
     (list (nth 0 common) (nth 1 common) (nth 2 common)
           (if (use-region-p) (region-beginning))
           (if (use-region-p) (region-end)))))
   (concat "\\(" (regexp-quote from-string) "\\)\\|" (regexp-quote to-string))
   `(replace-eval-replacement replace-quote
                              (if (match-string 1)
   t t delimited nil nil start end))

Insert the current file’s name at point

(defun insert-current-file-name-at-point (&optional full-path)
  "Insert the current filename at point.
With prefix argument, use full path."
  (interactive "P")
  (let* ((buffer
      (if (minibufferp)
     (filename (buffer-file-name buffer)))
    (if filename
    (insert (if full-path filename (file-name-nondirectory filename)))
      (error (format "Buffer %s is not visiting a file" (buffer-name buffer))))))


Move to different beginnings of the current line

Inspired by Bozhidar Batsov's solution.

(defun gpolonkai/move-to-beginning-of-line ()
  "Move to different beginnings of the line.

These are, in order:

- beginning of the visual line if `visual-line-mode' is active,
- the first non-whitespace (indentation),
- the actual beginning of the line.

This function will jump between the first character and the
indentation if used multiple times."
  (let ((last-pos (point)))
    (when visual-line-mode
    (when (= (point) last-pos)
    (when (= (point) last-pos)
    (when (and (eq major-mode 'org-mode)
               (= (point) last-pos))
    (when (= (point) last-pos)

Move to the different ends of the current line

(defun gpolonkai/move-to-end-of-line ()
  "Move to the end of the line.

If `visual-line-mode' is active, jump to the end of the visual
line first.  Then jump to the actual end of the line."
  (let ((last-pos (point)))
    (when visual-line-mode
    (when (= (point) last-pos)
    (when (and (eq major-mode 'org-mode)
               (= (point) last-pos))

Move to the next occurence of a character within the same line

(defun goto-next-char (chr)
  (interactive "c")
  (let ((substr (char-to-string chr))
        (end (save-excursion (end-of-line) (point))))
    (when (search-forward substr end t)

File manipulation

Rename the current file

(defun rename-current-buffer-file ()
  "Renames current buffer and file it is visiting."

  (let ((name (buffer-name))
        (filename (buffer-file-name)))
    (if (not (and filename (file-exists-p filename)))
        (error "Buffer '%s' is not visiting a file!" name)
      (let ((new-name (read-file-name "New name: " filename)))
        (if (get-buffer new-name)
            (error "A buffer named '%s' already exists!" new-name)
          (rename-file filename new-name 1)
          (rename-buffer new-name)
          (set-visited-file-name new-name)
          ; TODO: this is suspicious for me…
          (set-buffer-modified-p nil)
          (message "File '%s' successfully renamed to '%s'"
                   name (file-name-nondirectory new-name)))))))

Delete the current file

(defun delete-current-buffer-file ()
  "Remove file connected to current buffer and kill the buffer."

  (let ((filename (buffer-file-name))
        (name (buffer-name))
        (buffer (current-buffer)))
    (if (not (and filename (file-exists-p filename)))
        (kill-buffer buffer)
      (when (yes-or-no-p "Are you sure you want to remove this file? ")
        (delete-file filename)
        (kill-buffer buffer)
        (message "File '%s' successfully removed" filename)))))

Allow reopening the previously closed file

(defvar gpolonkai/last-killed-buffer-file-name
  "The last killed buffer.

Used by `gpolonkai/save-killed-buffer-filename' and `gpolonkai/undo-buffer-kill'.")

(defun gpolonkai/save-killed-buffer-filename ()
  "Save the filename of the killed buffer in `gpolonkai/last-killed-buffer-file-name'."
  (let ((filename (buffer-file-name)))
   (unless filename
    (setq gpolonkai/last-killed-buffer-file-name (buffer-file-name)))))

(add-hook 'kill-buffer-hook 'gpolonkai/save-killed-buffer-filename)

(defun gpolonkai/undo-buffer-kill ()
  "Undo killing the last buffer.

Esentially it visits the file again."
  (if gpolonkai/last-killed-buffer-file-name
        (find-file gpolonkai/last-killed-buffer-file-name)
        (setq gpolonkai/last-killed-buffer-file-name nil))
    (message "The buffer last killed didn’t visit a file.")))

Open this file as another user

(defun open-this-file-as-other-user (user)
  "Edit current file as USER, using `tramp' and `sudo'.

If the current buffer is not visiting a file, prompt for a file
  (interactive "sEdit as user (default: root): ")
  (when (string= "" user)
    (setq user "root"))
  (let* ((filename (or buffer-file-name
                       (read-file-name (format "Find file (as %s): "
         (tramp-path (concat (format "/sudo:%s@localhost:" user) filename)))
    (if buffer-file-name
        (find-alternate-file tramp-path)
      (find-file tramp-path))))

Open my own init.el

(defun gpolonkai/visit-init-file ()
  "Open the init file."
  (find-file-other-window (expand-file-name "" user-emacs-directory)))

Open my Org-mode index file

(defun gpolonkai/visit-org-index ()
  "Visit the root of Org-mode notes."
  (find-file-other-window (expand-file-name "" org-directory)))

Frame manipulation

Hidden modeline mode

To temporarily hide the mode line.

(defvar hidden-mode-line-mode nil)
(defvar hide-mode-line nil)

(define-minor-mode hidden-mode-line-mode
  "Minor mode to hide the mode-line in the current buffer."
  :init-value nil
  :global nil
  :variable hidden-mode-line-mode
  :group 'editing-basics
  (if hidden-mode-line-mode
      (setq hide-mode-line mode-line-format
            mode-line-format nil)
    (setq mode-line-format hide-mode-line
          hide-mode-line nil))
  (when (and (called-interactively-p 'interactive)
     0 nil 'message
     (concat "Hidden Mode Line Mode enabled.  "
             "Use M-x hidden-mode-line-mode to make mode-line appear."))))

Window manipulation

Transpose windows

(defun transpose-windows (arg)
  "Transpose the buffers shown in two windows."
  (interactive "p")
  (let ((selector (if (>= arg 0) 'next-window 'previous-window)))
    (while (/= arg 0)
      (let ((this-win (window-buffer))
            (next-win (window-buffer (funcall selector))))
        (set-window-buffer (selected-window) next-win)
        (set-window-buffer (funcall selector) this-win)
        (select-window (funcall selector)))
      (setq arg (if (plusp arg) (1- arg) (1+ arg))))))

Toggle window split between horizontal and vertical

(defun toggle-window-split ()
  (if (= (count-windows) 2)
      (let* ((this-win-buffer (window-buffer))
             (next-win-buffer (window-buffer (next-window)))
             (this-win-edges (window-edges (selected-window)))
             (next-win-edges (window-edges (next-window)))
             (this-win-2nd (not (and (<= (car this-win-edges)
                                         (car next-win-edges))
                                     (<= (cadr this-win-edges)
                                         (cadr next-win-edges)))))
              (if (= (car this-win-edges)
                     (car (window-edges (next-window))))
        (let ((first-win (selected-window)))
          (funcall splitter)
          (if this-win-2nd (other-window 1))
          (set-window-buffer (selected-window) this-win-buffer)
          (set-window-buffer (next-window) next-win-buffer)
          (select-window first-win)
          (if this-win-2nd (other-window 1))))
    (error "This works only for two windows!")))

Scroll up or down in a specific window

(defun gpolonkai/scroll-window-up (window)
  "Scroll WINDOW up as `scroll-up-command' would."
    (select-window window)

(defun gpolonkai/scroll-window-down (window)
  "Scroll WINDOW down as `scroll-down-command' would."
    (select-window window)

Bury a window

(defun gpolonkai/bury-window (window)
  "Quit WINDOW without killing it."
  (quit-window nil window))

Copy the prototype of the current function

(defun gpolonkai/copy-func-prototype ()
  "Copy the current function's prototype to the kill ring."


    (let ((protocopy-begin (point)))
      (let ((protocopy-end (point)))
        (kill-ring-save protocopy-begin protocopy-end)))))

Check if we are inside a string

(defun gpolonkai/prog-in-string-p ()
  "Return t if point is inside a string."
  (nth 3 (syntax-ppss)))

Check if we are inside a comment

(defun gpolonkai/prog-in-comment-p ()
  "Return t if point is inside a comment."
  (nth 4 (syntax-ppss)))

Add code references to Org documents

(defun ha/org-capture-fileref-snippet (f type headers func-name)
  (let* ((code-snippet
          (buffer-substring-no-properties (mark) (- (point) 1)))
         (file-name   (buffer-file-name))
         (file-base   (file-name-nondirectory file-name))
         (line-number (line-number-at-pos (region-beginning)))
         (initial-txt (if (null func-name)
                          (format "From [[file:%s::%s][%s]]:"
                                  file-name line-number file-base)
                        (format "From ~%s~ (in [[file:%s::%s][%s]]):"
                                func-name file-name line-number
    (format "

   #+BEGIN_%s %s
   #+END_%s" initial-txt type headers code-snippet type)))

(defun ha/org-capture-clip-snippet (f)
  "Given a file, F, this captures the currently selected text
within an Org EXAMPLE block and a backlink to the file."
  (with-current-buffer (find-buffer-visiting f)
    (ha/org-capture-fileref-snippet f "EXAMPLE" "" nil)))

(defun ha/org-capture-code-snippet (f)
  "Given a file, F, this captures the currently selected text
within an Org SRC block with a language based on the current mode
and a backlink to the function and the file."
  (with-current-buffer (find-buffer-visiting f)
    (let ((org-src-mode (replace-regexp-in-string "-mode" "" (format "%s" major-mode)))
          (func-name (which-function)))
      (ha/org-capture-fileref-snippet f "SRC" org-src-mode func-name))))

Add a docstring to the current thing

…be it a function, class, or a module

(defun gpolonkai/python-add-docstring ()
  "Add a Python docstring to the current thing.

If point is inside a function, add docstring to that.  If point
is in a class, add docstring to that.  If neither, add docstring
to the beginning of the file."
    (if (not (looking-at-p "\\(def\\|class\\) "))
          (goto-char (point-min))
          (while (gpolonkai/prog-in-comment-p)
      (search-forward ":")
      (while (or (gpolonkai/prog-in-string-p)
        (search-forward ":")))
    (if (eq 1 (count-lines 1 (point)))
    (insert "\"\"\"")
    (let ((point-pos (point)))
      (insert "\"\"\"\n")
      (goto-char point-pos))))

Font-lock variables in f-strings

(with-eval-after-load "python"
  (setq python-font-lock-keywords
        (append python-font-lock-keywords
                '(;; this is the full string.
                  ;; group 1 is the quote type and a closing quote is matched
                  ;; group 2 is the string part
                   ;; these are the {keywords}
                    ;; Pre-match form
                    (progn (goto-char (match-beginning 0)) (match-end 0))
                    ;; Post-match form
                    (goto-char (match-end 0))
                    ;; face for this match
                    (0 font-lock-variable-name-face t)))))))

Mark a string as translatable

(defun jinja-mark-translatable (begin end)
  (interactive (if (use-region-p)
                   (list (region-beginning) (region-end))
                 (list (point-min) (point-max))))
    (goto-char end)
    (insert "{% endtrans %}")
    (goto-char begin)
    (insert "{% trans %}")))

URL-ify and de-URL-ify region

These functions URL-encode/decode a text. Might be helpful when embedding/extracting data to/from HTML.

(defun hex-region (start end)
  "urlencode the region between START and END in current buffer."
  (interactive "r")
  (func-region start end #'url-hexify-string))

(defun unhex-region (start end)
  "de-urlencode the region between START and END in current buffer."
  (interactive "r")
  (func-region start end #'url-unhex-string))

Automatically zone out after 60 seconds

(defun gpolonkai/zone-enable ()
  "Enable zoning out."
  (zone-when-idle 60)
  (message "I will zone out after idling for 60 seconds."))

Utility functions for editing Zim wiki files

(defun zim-timestamp ()
    (insert (format-time-string "%Y-%m-%dT%H:%M:%S%z"))
    (forward-char -2)
    (insert ":")

(defun insert-zim-timestamp ()
  (insert (zim-timestamp)))

(defun insert-zim-header ()
    (goto-char (point-min))
     (concat "Content-Type: text/x-zim-wiki\n"
             "Wiki-Format: zim 0.4\n"
             "Creation-Date: " (zim-timestamp) "\n\n"))))

Utility functions for EDiff

EDiff and Org-mode files don’t play nice together…

(defun f-ediff-org-showhide (buf command &rest cmdargs)
  "If buffer BUF exists and in `org-mode', execute COMMAND with CMDARGS."
  (when buf
    (when (eq (buffer-local-value 'major-mode (get-buffer buf)) 'org-mode)
        (set-buffer buf)
        (apply command cmdargs)))))

(defun f-ediff-org-unfold-tree-element ()
  "Unfold tree at diff location."
  (f-ediff-org-showhide ediff-buffer-A 'org-reveal)
  (f-ediff-org-showhide ediff-buffer-B 'org-reveal)
  (f-ediff-org-showhide ediff-buffer-C 'org-reveal))

(defun f-ediff-org-fold-tree ()
  "Fold tree back to top level."
  (f-ediff-org-showhide ediff-buffer-A 'hide-sublevels 1)
  (f-ediff-org-showhide ediff-buffer-B 'hide-sublevels 1)
  (f-ediff-org-showhide ediff-buffer-C 'hide-sublevels 1))

Leave isearch at the other end of the matched string

(defun isearch-exit-other-end ()
  "Exit isearch, at the opposite end of the string."

  (goto-char isearch-other-end))

Mark the current match after leaving isearch

(defun isearch-exit-mark-match ()
  "Exit isearch and mark the current match."
  (push-mark isearch-other-end)

Turn the cursor to purple if Yasnippet’s TAB function would fire

Taken from Sacha Chua’s config.

;; TODO: 'cursor-color is sometimes nil, but why?
(setq default-cursor-color (or (frame-parameter nil 'cursor-color) "#ffd85c"))
(setq yasnippet-can-fire-cursor-color "purple")

;; It will test whether it can expand, if yes, cursor color -> purple.
(defun yasnippet-can-fire-p (&optional field)
  "Check if the word before point can be expanded with yasnippet.

TODO: What is FIELD for?"
  (setq yas--condition-cache-timestamp (current-time))
  (let (templates-and-pos)
    (unless (and yas-expand-only-for-last-commands
                 (not (member last-command yas-expand-only-for-last-commands)))
      (setq templates-and-pos (if field
                                    (narrow-to-region (yas--field-start field)
                                                      (yas--field-end field))
    (and templates-and-pos (first templates-and-pos))))

(defun sachachua/change-cursor-color-when-can-expand (&optional field)
  "Change cursor color if the text before point can be expanded with yasnippet.

TODO: What is FIELD for?"
  (when (eq last-command 'self-insert-command)
    (set-cursor-color (if (sachachua/can-expand)

(defun sachachua/can-expand ()
  "Return t if right after an expandable thing."
  (or (abbrev--before-point) (yasnippet-can-fire-p)))

Org mode stuff

Filter out tasks from the Org agenda if they have a specific priority

The whole idea comes from here, which i use almost verbatim. This is also the reason it has the air- prefix.

(defun air-org-skip-subtree-if-priority (priority)
  "Skip an agenda subtree if it has a priority of PRIORITY.

PRIORITY may be one of the characters ?A, ?B, or ?C."
  (let ((subtree-end (save-excursion (org-end-of-subtree t)))
        (pri-value (* 1000 (- org-lowest-priority priority)))
        (pri-current (org-get-priority (thing-at-point 'line t))))
    (if (= pri-value pri-current)

Filter out habits from the Org agenda

(defun air-org-skip-subtree-if-habit ()
  "Skip an agenda entry if it has a STYLE property equal to \"habit\"."
  (let ((subtree-end (save-excursion (org-end-of-subtree t))))
    (if (string= (org-entry-get nil "STYLE") "habit")

Filter out entries from the Org agenda with a specific state

(defun gpolonkai/org-skip-subtree-if-state (state)
  "Skip an agenda entry if its state is STATE."
  (let ((subtree-end (save-excursion (org-end-of-subtree t))))
    (if (string= (org-get-todo-state) state)

Wrapper around org-agenda to open my own custom list

(defun gpolonkai/org-agenda-list (&optional arg)
  (interactive "P")
  (org-agenda arg "c"))

Insert the current timestamp

(defun gpolonkai/org-insert-current-timestamp (&optional arg)
  "Insert the current timestamp"
  (interactive "P")
  (org-time-stamp '(16) arg))

Insert a heading with CREATED set to the current time

This emulates how Orgzly work with my current settings.

(defun gpolonkai/org-insert-heading-created (&optional arg)
  (interactive "p")
  (let* ((org-insert-heading-respect-content t)
         (format-string (concat "[" (substring (cdr org-time-stamp-formats) 1 -1) "]"))
         (timestamp (format-time-string format-string (current-time))))
    (if (> arg 1)
        (org-insert-subheading '(4))
    (org-set-property "CREATED" timestamp)))

UI preferences

Tweak window chrome

Turn off the scroll bar (that’s why Nyan-cat is here), the toolbar (I don’t really use it), and the menu bar (I rarely use it, and in those rare occasions I can simply turn it on.)

Also, maximise the frame.

(tool-bar-mode 0)
(menu-bar-mode 0)
(when window-system
  (scroll-bar-mode -1))

(set-frame-parameter nil 'fullscreen 'maximized)

Set the default font and configure font resizing

Before this can be used, make sure the Symbola font is installed.

(defun gpolonkai/set-font-size (frame)
  (when (display-graphic-p frame)
    (set-face-attribute 'default frame :font "Hack-12")
    (set-frame-font "Hack-12" t (list frame))))

(defun --set-emoji-font (frame)
  "Adjust the font setting of FRAME so Emacs can display Emoji properly."
  (when (display-graphic-p frame)
    (set-fontset-font t 'symbol
                      (font-spec :family "Symbola")
                      frame 'prepend)
    (set-fontset-font t 'unicode
                      "Noto Emoji"
                      nil 'append)))

(add-hook 'after-make-frame-functions 'gpolonkai/set-font-size)
(add-hook 'after-make-frame-functions '--set-emoji-font)

(gpolonkai/set-font-size nil)
(--set-emoji-font nil)

Set up global minor modes provided by Emacs

Pretty lambdas

Because we can.

(global-prettify-symbols-mode t)

And set up all the pretty symbols.

(setq prettify-symbols-alist
      '(("lambda" . 955)    ; λ
        ("function" . 402)  ; ƒ
        ("->" . 8594)       ; →
        ("=>" . 8658)       ; ⇒
        ("map" . 8614)      ; ↦
        ("not" . 172)))     ; ¬

…and some pairs to complete

TODO Maybe add-to-list is a better way to do it


(setq insert-pair-alist '(
                          (40 41)      ; ()
                          (91 93)      ; []
                          (123 125)    ; {}
                          (60 62)      ; <>
                          (34 34)      ; ""
                          (39 39)      ; ''
                          (96 39)      ; `'
                          (8220 8221)  ; “”
                          (8222 8221)  ; „”
                          (8216 8217)  ; ‘’
                          (8249 8250)  ; ‹›
                          (8250 8249)  ; ›‹
                          (171 187)    ; «»
                          (187 171)))  ; »«

Finally, set the frame title to the current file name

(setq frame-title-format '((:eval (concat system-name
                                          ": "
                                          (if (buffer-file-name)
                                              (abbreviate-file-name (buffer-file-name))

Treat soft line breaks as hard ones in textual modes

(add-hook 'text-mode-hook (lambda () (visual-line-mode t)))

Enable disabled commands

Because i’m a rock star like that.

(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)
(put 'erase-buffer 'disabled nil)
(put 'narrow-to-region 'disabled nil)
(put 'narrow-to-page 'disabled nil)
(put 'set-goal-column 'disabled nil)
(put 'scroll-left 'disabled nil)
(put 'dired-find-alternate-file 'disabled nil)
(put 'Info-edit 'disabled nil)
(put 'list-timers 'disabled nil)

Packages installed from Quelpa

For some strange reason having this at the end of my configuration can cause unexpected results.

Matrix client

(use-package matrix-client
  :after quelpa-use-package
  :ensure nil
  :quelpa (matrix-client :fetcher github :repo "alphapapa/matrix-client.el"
                         :files (:defaults "logo.png" "")))


(use-package plz
  :ensure nil
  :quelpa (plz :fetcher github :repo "alphapapa/plz.el"))

(use-package ement
  :ensure nil
  :quelpa (ement :fetcher github :repo "alphapapa/ement.el")
  (ement-save-token t))

Load some built-in libraries


(use-package thingatpt
  :ensure nil)


(use-package calendar
  :ensure nil
  (setq calendar-week-start-day 1
        calendar-latitude 47.4
        calendar-longitude 19.0
        calendar-location-name "Budapest, Hungary"
        calendar-time-zone 60
        calendar-standard-time-zone-name "CET"
        calendar-daylight-time-zone-name "CEST"))

Add the SysAdmin day to the calendar

Because I’m a sysadmin, too.

(add-to-list 'holiday-other-holidays '(holiday-float 7 5 -1 "SysAdmin Day") t)
(add-to-list 'holiday-other-holidays '(holiday-fixed 10 21 "Reptile Awareness Day") t)


(use-package nxml-mode
  :ensure nil
  (nxml-attribute-indent 4)
  (nxml-child-indent 4)
  (nxml-outline-child-indent 4))


(use-package recentf
  :ensure nil
  (run-at-time nil (* 5 60) 'recentf-save-list)
  (add-to-list 'recentf-exclude (expand-file-name "elpa" user-emacs-directory)))


(use-package files
  :ensure nil
  (make-backup-file-name-function 'xah/backup-file-name))


whitespace-mode is turned on by default, and can be toggled with F10.

(defun prevent-whitespace-mode-for-some ()
  "Prevent whitespace-mode from running in some modes."
   (not (derived-mode-p 'magit-mode))
   (not (derived-mode-p 'org-mode))))

(use-package whitespace
  (add-function :before-while whitespace-enable-predicate 'prevent-whitespace-mode-for-some)
  (global-whitespace-mode 1)
  (whitespace-line-column 100)
  (([f10] . whitespace-mode)
   ([(shift f10)] . global-whitespace-mode)
   :map gpolonkai/pers-map
   ("w" . whitespace-cleanup)))


This is a function to delete a character, or close eshell if there’s nothing to delete. Taken from here.

(defun eshell-C-d ()
  "Either call `delete-char' interactively or quit."

  (condition-case err
      (call-interactively #'delete-char)
    (error (if (and (eq (car err) 'end-of-buffer)
                    (looking-back eshell-prompt-regexp nil))
             (signal (car err) (cdr err))))))

Function to bind it locally to C-d.

(defun gpolonkai/eshell-set-c-d-locally ()
  (local-set-key (kbd "C-d") #'eshell-C-d))

Now set up eshell.

(use-package eshell
  (:map gpolonkai/pers-map
   ("e" . eshell))
  (eshell-mode . gpolonkai/eshell-set-c-d-locally))


;; Save place
(use-package saveplace
  (save-place-mode 1)
  (save-place-file (expand-file-name ".places" user-emacs-directory)))


(use-package ediff
  (ediff-merge-split-window-function 'split-window-horizontally)
  (ediff-split-window-function 'split-window-vertically)
  (ediff-window-setup-function 'ediff-setup-windows-plain))

Automatically revert changed files

…unless they are modified, of course.

(use-package autorevert
  (global-auto-revert-mode 1))


For in-Emacs browsing needs.

(use-package eww
  (eww-search-prefix ""))

Electric indent mode

(use-package electric
  ;; This seems to be the default, but let’s make sure…
  (electric-indent-mode 1))

Save history

(use-package savehist
  (savehist-mode 1))

Web jump

(use-package webjump
  (:map gpolonkai/pers-map
   ("j" . webjump)))

Which function am i in?

(defun gpolonkai/activate-which-func-mode ()
  (if (fboundp 'which-function-mode)
(use-package which-func
  (setq which-func-unknown "∅")
  (prog-mode . gpolonkai/activate-which-func-mode))

Fortune cookies

The cookies are from the Hungarian version an ancient MS-DOS based program called TAGLINE.

(use-package cookie1
  :demand t
  (cookie-file (expand-file-name "fortune-cookies.txt" user-emacs-directory))
  (:map gpolonkai/pers-map
   ("k" . cookie)))

Browse URL functionality in Termux

(when (termux-p)
  (use-package browse-url
    :ensure nil
    (advice-add 'browse-url-default-browser :override
                (lambda (url &rest args)
                   (concat "am start -a android.intent.action.VIEW --user 0 -d "

Dired customisation

(use-package dired
  :ensure nil
  (dired-dwim-target t)
  (wdired-create-parent-directories t)
  (wdired-allow-to-change-permissions t)
  (:map dired-mode-map
   ("RET" . dired-find-alternate-file)
   ("^" . (lambda () (interactive) (find-alternate-file "..")))
   ("W" . wdired-change-to-wdired-mode)))

Actionable URLs

(use-package goto-addr
  :hook ((compilation-mode . goto-address-mode)
         (prog-mode . goto-address-prog-mode)
         (eshell-mode . goto-address-mode)
         (shell-mode . goto-address-mode))
  (:map goto-address-highlight-keymap
   ("<RET>" . goto-address-at-point)
   ("M-<RET>" . newline))
  :commands (goto-address-prog-mode goto-address-mode))

Do things at midnight

By default, it closes a bunch of unused buffers. I might add some more things there later.

(use-package midnight
  :ensure nil
  (setq clean-buffer-list-kill-never-buffer-names '("*scratch*"
  (midnight-mode t))

Show line numbers

I don’t usually like to see them, but there are occasions when they can be useful.

(use-package display-line-numbers
  (:map gpolonkai/pers-map
   ("C-n" . display-line-numbers-mode)))

Check for spelling errors

(use-package ispell
  (ispell-dictionary "en_GB")
  (ispell-program-name "/usr/bin/aspell")
  (mail-send . ispell-message)
  (message-send . ispell-message))

Speed bar

(use-package speedbar)

use-package packages

Make sure we have the latest ELPA GPG keys

(use-package gnu-elpa-keyring-update)

Automatically upgrade packages every week

(use-package auto-package-update
  (auto-package-update-interval 7)
  (auto-package-update-delete-old-versions t)
  ;; Let’s do this in after-init-hook, as use-package invocations may modify
  ;; the list of installed packages
  (after-init . auto-package-update-maybe))


Nyan-cat style position marker

(use-package nyan-mode
  (nyan-mode t)
  (nyan-bar-length 20)
  (nyan-animate-nyancat t)
  (nyan-wavy-trail t))

Nyan prompt in EShell

(use-package nyan-prompt
  (eshell-load . nyan-prompt-enable))

Zone out with Nyancat

Unfortunately, this works only in a graphical mode.

(use-package zone-nyan
  (setq zone-programs (vconcat zone-programs [zone-nyan]))
  (zone-nyan-hide-progress t))

De-light some minor modes

(use-package delight)

Eye candy

Moody mode-line

(use-package moody
  (set-face-attribute 'mode-line nil :box nil :foreground "#7e7486")
  (set-face-attribute 'mode-line-inactive nil :box nil)
  (moody-mode-line-height 18))


(use-package minions
  (minions-mode 1))

Spinner, e.g. to display running background tasks

(use-package spinner)


Highlight point. Sometimes it’s not easy to see.

(use-package beacon
  (beacon-mode 1)
  (:map gpolonkai/pers-map
   ("b" . beacon-blink)))

Display the status of the last command in the fringe of EShell

(use-package eshell-fringe-status
  (eshell-mode . eshell-fringe-status-mode))

Extras for the EShell prompt

(use-package eshell-prompt-extras
  (with-eval-after-load "esh-opt"
    (autoload 'epe-theme-lambda "eshell-prompt-extras"))
  (eshell-highlight-prompt nil)
  (eshell-prompt-function 'epe-theme-lambda))

Show form feeds as a horizontal line

(use-package form-feed
  (emacs-lisp-mode . form-feed-mode)
  (compilation-mode . form-feed-mode)
  (help-mode . form-feed-mode))

Highlight the current line

(use-package hl-line
  (when window-system

GNU Globals

(defun gpolonkai/cond-enable-ggtags-mode ()
  (when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
    (ggtags-mode t)))

(use-package ggtags
  (c-mode-common . gpolonkai/cond-enable-ggtags-mode))

Multiple cursors

Because one is never enough.

(defun gpolonkai/no-blink-matching-paren ()
  (customize-set-variable 'blink-matching-paren nil))

(defun gpolonkai/blink-matching-paren ()
  (customize-set-variable 'blink-matching-paren t))

(use-package multiple-cursors
  (defvar gpolonkai/mc-prefix-map (make-sparse-keymap)
    "Prefix keymap for multiple-cursors")
  (define-prefix-command 'gpolonkai/mc-prefix-map)
  (define-key global-map (kbd "C-c m") 'gpolonkai/mc-prefix-map)
  (multiple-cursors-mode-enabled . gpolonkai/no-blink-matching-paren)
  (multiple-cursors-mode-disabled . gpolonkai/blink-matching-paren)
  (:map gpolonkai/mc-prefix-map
   ("t" . mc/mark-all-like-this)
   ("m" . mc/mark-all-like-this-dwim)
   ("l" . mc/edit-lines)
   ("e" . mc/edit-ends-of-lines)
   ("a" . mc/edit-beginnings-of-lines)
   ("n" . mc/mark-next-like-this)
   ("p" . mc/mark-previous-like-this)
   ("s" . mc/mark-sgml-tag-pair)
   ("d" . mc/mark-all-like-this-in-defun)
   ("M-<mouse-1>" . mc/add-cursor-on-click)))

Incremental search for multiple cursors

(use-package phi-search)

(use-package phi-search-mc

Some extras

(use-package mc-extras
  (:map mc/keymap
   ("C-c m =" . mc/compare-chars)))

Add extra cursors via ace-jump

(use-package ace-mc
  (:map gpolonkai/mc-prefix-map
   ("SPC" . ace-mc-add-multiple-cursors)
   ("C-SPC" . ace-mc-add-single-cursor)))


(use-package magit
  (magit-auto-revert-mode nil)
  (magit-last-seen-setup-instructions "1.4.0")
  (:map ctl-x-map
   ("g" . magit-status))
  (git-commit-mode . turn-on-flyspell))

Make Magit work with Git forges

(use-package forge)


(use-package zone
  (zone-when-idle 60)
  (:map gpolonkai/pers-map
   ("zi" . gpolonkai/zone-enable)
   ("zq" . zone-leave-me-alone)))


(use-package origami
  (define-prefix-command 'origami-mode-map)
  (define-key ctl-x-map (kbd "z") 'origami-mode-map)
  (:map origami-mode-map
   ("o" . origami-open-node)
   ("O" . origami-open-node-recursively)
   ("c" . origami-close-node)
   ("C" . origami-close-node-recursively)
   ("a" . origami-toggle-node)
   ("A" . origami-recursively-toggle-node)
   ("R" . origami-open-all-nodes)
   ("M" . origami-close-all-nodes)
   ("v" . origami-show-only-node)
   ("k" . origami-previous-fold)
   ("j" . origami-forward-fold)
   ("x" . origami-reset)))

Smart parens

(use-package smartparens
  (show-smartparens-global-mode t)
  (prog-mode . turn-on-smartparens-strict-mode)
  (markdown-mode . turn-on-smartparens-strict-mode)
  (([f9] . smartparens-strict-mode)
   ("C-c s u" . sp-unwrap-sexp)
   ("C-c s k" . sp-kill-sexp)))


(use-package projectile
  :delight '(:eval (concat " [" projectile-project-name "]"))
  :pin melpa-stable
  (projectile-mode t)
  (:map projectile-mode-map
   ("C-c p" . projectile-command-map)))

Repository-based ToDo management with Org mode

(use-package org-projectile
  :after (:all projectile org)
  :defer t
  (:map projectile-command-map
   ("n" . org-projectile-project-todo-completing-read))
  (org-projectile-projects-file (expand-file-name "" org-directory))
  (push (org-projectile-project-todo-entry) org-capture-templates))

Text object manipulation

From the package description:

Text objects are textual patterns like a line, a top level definition, a word, a sentence or any other unit of text. When objed-mode is enabled, certain editing commands (configurable) will activate objed and enable its modal editing features.

(use-package objed
  :demand t
  (:map global-map
   ("M-SPC" . objed-activate)))

Ace window

Besides its standard functionality, I also make add key bindings for burying or scrolling another window.

(use-package ace-window
  (aw-background nil)
  (aw-dispatch-always t)
  (add-to-list 'aw-dispatch-alist
               '(?s gpolonkai/scroll-window-up " Scroll window up")
  (add-to-list 'aw-dispatch-alist
               '(?S gpolonkai/scroll-window-down " Scroll window down")
  (add-to-list 'aw-dispatch-alist
               '(?q gpolonkai/bury-window " Bury (quit) window")
  (:map ctl-x-map
   ("o" . ace-window)))

Golden ratio

(use-package golden-ratio
  (add-to-list 'golden-ratio-extra-commands 'ace-window)
  (golden-ratio-mode t))


(use-package avy
  (("M-g c" . avy-goto-char)
   ("M-g C" . avy-goto-char-2)
   ("M-g f" . avy-goto-line)
   ("M-g w" . avy-goto-word-1)
   ("M-g e" . avy-goto-word-0)))

Focus mode

It is similar to narrow mode, except the narrowing part; it dims everything outside of the current context.

(use-package focus
  (([f8] . focus-mode)))

Command logging mode

For occasional screen casting recordings.

(use-package command-log-mode)


For controlling tmux from within Emacs.

(use-package emamux)

Use StackExchange sites in an Emacs window

(use-package sx
  (:map gpolonkai/pers-map
   ("qi" . sx-inbox)
   ("qs" . sx-search)))

Goto last change

(use-package goto-last-change
  (("M-g /" . goto-last-change)))

Rainbow mode

To highlight colours based on their name or hex code.

(use-package rainbow-mode
  (css-mode . rainbow-mode)
  (scss-mode . rainbow-mode)
  (sass-mode . rainbow-mode))


Toggle other windows for maximum focus. When focus is no longer needed, they can be toggled back. C-x 1 is conveniently bound to it.

(use-package zygospore
  (:map ctl-x-map
   ("1" . zygospore-toggle-delete-other-windows)))

Kanban board

(use-package kanban)

Highlight dired buffer by file size, modified time, git status

(use-package dired-k
  (:map dired-mode-map
   ("K" . dired-k)))

Show number of matches in the mode line while searching

(use-package anzu
  (global-anzu-mode 1))

Gradually expand region

(use-package expand-region
  (:map gpolonkai/pers-map
   ("x" . er/expand-region)))

Read and Edit MediaWiki pages in an Emacs window

(use-package mediawiki
  (add-to-list 'mediawiki-site-alist
                 (password-store-get-field "" "username")
                 (password-store-get "" "password"))))

An Emacs Dashboard

(use-package dashboard
  (add-to-list 'dashboard-items '(projects . 5) t)

Hungarian holidays in the Calendar

(use-package hungarian-holidays


For all your spell-checking needs.

(use-package flyspell
  (prog-mode . flyspell-prog-mode)
  (text-mode . flyspell-mode))

Delete all the whitespace

(use-package hungry-delete

Send alerts to a notification system

(use-package alert
  (setq alert-default-style
        (if (termux-p)
              ;; TODO Remove this as soon as my PR gets merged
              (unless (fboundp 'alert-termux-notify)
                (defcustom alert-termux-command (executable-find "termux-notification")
                  "Path to the termux-notification command.
This is found in the termux-api package, and it requires the Termux
API addon app to be installed."
                  :type 'file
                  :group 'alert)

                (defun alert-termux-notify (info)
                  "Send INFO using termux-notification.
Handles :TITLE and :MESSAGE keywords from the
INFO plist."
                  (if alert-termux-command
                      (let ((args (nconc
                                   (when (plist-get info :title)
                                     (list "-t" (alert-encode-string (plist-get info :title))))
                                   (list "-c" (alert-encode-string (plist-get info :message))))))
                        (apply #'call-process alert-termux-command nil
                               (list (get-buffer-create " *termux-notification output*") t)
                               nil args))
                    (alert-message-notify info)))

                (alert-define-style 'termux :title "Notify using termux"
                                    :notifier #'alert-termux-notify))

Replace the GUI popup menu with something more efficient

(use-package ace-popup-menu
  ;; Unfortunately, avy-menu (used by this package) is not compatible with minions.  I just
  ;; disable it for now.
  (ace-popup-menu-mode 1))

I’m an achiever!

(use-package achievements
  (achievements-mode 1)
  (:map gpolonkai/pers-map
   ("C-a" . achievements-list-achievements)))


Because even secretaries need a secretary today.

(use-package secretaria
  ;; use this for getting a reminder every 30 minutes of those tasks
  ;; scheduled for today and which have no time of day defined.
  (after-init . secretaria-unknown-time-always-remind-me))

The Silver Searcher

(use-package ag
  :after projectile
  (:map projectile-mode-map
   ("C-c p C-a" . ag-project)))

A fancier narrow-mode

(use-package fancy-narrow

Undo tree

(use-package undo-tree)

All the icons!

Should the fonts be missing, run (all-the-icons-install-fonts). It’s not run automatically, as it requires connecting to a website and download a pretty large font file.

(use-package all-the-icons)

NeoTree, if Dired is not an option

(defun gpolonkai/neo-set-theme ()
  (customize-set-variable 'neo-theme (if (display-graphic-p) 'icons 'arrow)))

(use-package neotree
  (([f5] . neotree-toggle))
  (neo-enter . gpolonkai/neo-set-theme))

Waka-waka (AKA ActivityWatch)

(use-package activity-watch-mode

Jump to character, word, line

(use-package ace-jump-mode
  (:map gpolonkai/pers-map
   ("SPC" . ace-jump-mode)))

Command frequency meter

(use-package keyfreq
  (keyfreq-file (expand-file-name "keyfreq" user-emacs-directory))
  (keyfreq-file-lock (expand-file-name "keyfreq.lock" user-emacs-directory))
  (keyfreq-mode 1)
  (keyfreq-autosave-mode 1)
  (:map gpolonkai/pers-map
   ("C-f" . keyfreq-show)))


EditorConfig is a nice tool to unify, well, configuration of different editors.

(use-package editorconfig
  (editorconfig-mode t))

occur-like folding in the current buffer

(defun gpolonkai/toggle-loccur ()
  "Toggle `loccur-mode'.

If `loccur-mode' is not active, starts it (which, in turn, will ask for the
pattern to look for).  If it is active, it will disable it."
  (if loccur-mode
      (loccur-mode nil)
    (call-interactively 'loccur)))

(use-package loccur
  (:map gpolonkai/pers-map
   ("C-o" . gpolonkai/toggle-loccur)))

Help merging pacsave and pacnew files

(use-package pacfiles-mode
  :commands pacfiles)

Mailing with mu4e

Due to my programming (and maybe a bit of OCD) needs, i set trailing whitespace to have a red background so it stands out a lot. However, many emails contain a lot of trailing whitespace which makes them really hard to read in Emacs.

The below snippet creates a trailing whitespace face specific to mu4e view buffers. The accompanying function will be added to mu4e-view-mode-hook.

(copy-face 'trailing-whitespace 'trailing-whitespace-mu4e)
(set-face-attribute 'trailing-whitespace-mu4e nil :background 'unspecified)

(defun gpolonkai/mu4e-trailing-whitespace-fix ()
  (set (make-local-variable 'face-remapping-alist)
       '((trailing-whitespace trailing-whitespace-mu4e))))
(use-package mu4e
  :after ivy
  :ensure nil
  (require 'org-mu4e)
  (setq mu4e-contexts
        `( ,(make-mu4e-context
             :name ""
             :enter-func (lambda () (mu4e-message "Entering Context"))
             :leave-func (lambda () (mu4e-message "Leaving Context"))
             :match-func (lambda (msg)
                           (when msg
                              :to "")))
             :vars '((user-mail-address . "")
                     (mu4e-sent-folder . "/Polonkai/[Gmail].Sendur p&APM-stur")
                     (mu4e-drafts-folder . "/Polonkai/[Gmail].Dr&APY-g")
                     (mu4e-trash-folder . "/Polonkai/[Gmail].Rusl")
                     (mu4e-refile-folder . "/Polonkai/[Gmail].Dr&APY-g")
                     (message-sendmail-extra-arguments . ("--account=polonkai"))))
             :name ""
             :enter-func (lambda () (mu4e-message "Entering Context"))
             :leave-func (lambda () (mu4e-message "Leaving Context"))
             :match-func (lambda (msg)
                           (when msg
                               :to "")
                               :to "")
                               :to ""))))
             :vars '((user-mail-address . "")
                     (mu4e-sent-folder . "/GT2/[Gmail].Sent Mail")
                     (mu4e-drafts-folder . "/GT2/[Gmail].Drafts")
                     (mu4e-trash-folder . "/GT2/[Gmail].Trash")
                     (mu4e-refile-folder . "/GT2/[Gmail].Drafts")
                     (message-sendmail-extra-arguments . ("--account=gt2"))))
             :name "Private"
             :enter-func (lambda () (mu4e-message "Entering Private Context"))
             :leave-func (lambda () (mu4e-message "Leaving Private Context"))
             :match-func (lambda (msg)
                           (when msg
                             (string-match-p "^/Private" (mu4e-message-field msg :maildir))))
             :vars '((user-mail-address . "")
                     (mu4e-sent-folder . "/Private/Sent")
                     (mu4e-drafts-folder . "/Private/Drafts")
                     (mu4e-trash-folder . "/Private/Trash")
                     (mu4e-refile-folder . "/Private/Drafts")
                     (message-sendmail-extra-arguments . ("--account=private" "--read-envelope-from")))))
        org-mu4e-link-query-in-headers-mode nil)
  (mu4e-completing-read-function 'ivy-completing-read)
  (mu4e-context-policy 'pick-first)
  (mu4e-confirm-quit nil)
  (mail-user-agent 'sendmail-user-agent)
  (mu4e-view-mode . gpolonkai/mu4e-trailing-whitespace-fix)
  (:map gpolonkai/pers-map
   ("m m" . mu4e)
   ("m i" . mu4e~headers-jump-to-maildir)
   ("m c" . mu4e-compose-new)
   ("m s" . mu4e-headers-search)))

Maildir extension so i see a summary of mailboxes

(use-package mu4e-maildirs-extension
  (mu4e-maildirs-extension-custom-list '("INBOX")))

Also, some sendmail hacking

(use-package sendmail
  (sendmail-program "/usr/bin/msmtp")
  (message-sendmail-f-is-evil t)
  (message-sendmail-extra-arguments '("--read-envelope-from"))
  (send-mail-function 'sendmail-send-it)
  (message-send-mail-function 'message-send-mail-with-sendmail))

ViM’s ci functionality

(use-package ciel
  (:map global-map
   ("C-c i" . ciel-ci)
   ("C-c o" . ciel-co)))

Access files in Docker containers using TRAMP

(use-package docker-tramp)

Transient for creating beautiful command menus

(use-package transient)

Speed bar in the same frame

(use-package sr-speedbar
  :after speedbar)

Speedbar for projectile

(use-package projectile-speedbar
  :after (:all projectile sr-speedbar)
  (:map projectile-mode-map
   ("C-c p B" . projectile-speedbar-toggle)))

Kubernetes dashboard

(use-package kubernetes
  :commands (kubernetes-overview))

A Gopher client

Gopher is the next generation text protocol. Despite its age (40-ish, as of writing), it still beats the Web in a lot of aspects.

(use-package elpher)

Tidal, for improvising music

(use-package tidal)

Paradox, for better package management

I don’t always use the package menu, but when i do, i want to do it in style…

(use-package paradox
  (paradox-lines-per-entry 2)
  (paradox-automatically-star t)
  (paradox-github-token (nth 1 (auth-source-user-and-password "" "gergelypolonkai^paradox")))
  (:map gpolonkai/pers-map
   ("C-p" . paradox-list-packages)))

Help editing Ansible files

(use-package ansible)

Edit browser textareas in Emacs

(use-package edit-server
  :ensure t
  :commands edit-server-start
  :init (if after-init-time
          (add-hook 'after-init-hook
                    #'(lambda() (edit-server-start))))
  :config (setq edit-server-new-frame-alist
                '((name . "Edit with Emacs FRAME")
                  (top . 200)
                  (left . 200)
                  (width . 80)
                  (height . 25)
                  (minibuffer . t)
                  (menu-bar-lines . t)
                  (window-system . x))))

Dired related packages

Collapse directories that only contain one file somewhere deep

(use-package dired-collapse)

Show directory sizes

(use-package dired-du)

Show Git version information

(use-package dired-git-info
  (:map dired-mode-map
   (")" . dired-git-info-mode)))

Show/hide dot (hidden) files

(use-package dired-hide-dotfiles
  (:map dired-mode-map
   ("." . dired-hide-dotfiles-mode)))

Rainbow to the stars…

(use-package dired-rainbow
  (dired-rainbow-define-chmod executable-unix "Green" "-.*x.*"))

Make programming a bit easier

Electric case

Insert snake_case and camelCase without using the Shift key. It is automatically enabled in C mode.

(use-package electric-case
  (c-mode . electric-case-c-init))

Electric operator

Automatically add spaces around operators.

(use-package electric-operator
  ;; Apply electric-operator-mode to vala-mode, too
  (apply #'electric-operator-add-rules-for-mode 'vala-mode
         (electric-operator-get-rules-for-mode 'prog-mode))
  (c-mode-common . electric-operator-mode)
  (python-mode . electric-operator-mode))


(use-package yasnippet
  (yas-global-mode 1)
  (post-command . sachachua/change-cursor-color-when-can-expand))

Extra snippets for Vala

(use-package vala-snippets

Miscellanous extra snippets

(use-package yasnippet-snippets

Colourful delimiters

(use-package rainbow-delimiters
  (prog-mode . rainbow-delimiters-mode))

Colourful identifiers

(use-package rainbow-identifiers)

REST Client

(use-package restclient)

REST Client power for Org-mode!

(use-package ob-restclient
  :after org
  (org-babel-do-load-languages 'org-babel-load-languages
                               '((restclient . t))))

Highlight current symbol

A big help during refactoring.

(use-package auto-highlight-symbol
  (global-auto-highlight-symbol-mode t))

Make ReallyLongCamelCaseWords more readable

(use-package glasses
  :delight " 👓"
  (prog-mode . glasses-mode))

GObject boilerplate generator

(use-package gobgen)

Highlight TODO, FIXME, and XXX

(use-package hl-todo)
(defvar gpolonkai/bug-reference-url-bug-string "issues"
  "String to insert in a `bug-reference-url-format' for bug references.")

(put 'gpolonkai/bug-reference-url-bug-string 'safe-local-variable 'stringp)

(defvar gpolonkai/bug-reference-url-patch-string "merge_requests"
  "String to insert in a `bug-reference-url-format' for patch references.")

(defvar-local bug-reference-host ""
  "The hostname to use in `bug-reference-url-format'.")

(defvar-local bug-reference-group "gamesystems"
  "The group name or username to use in `bug-reference-url-format'.")

(defvar-local bug-reference-repository "game-app"
  "The repository name to use in `bug-reference-url-format'.")

(put 'gpolonkai/bug-reference-url-patch-string 'safe-local-variable 'stringp)

(defun gpolonkai/bug-reference-url ()
  "Return a GitLab issue or Merge Request URL.
Intended as a value for `bug-referecne-url-format'."
  (format "https://%s/%s/%s/%s/%s"
          (if (string-suffix-p "!" (match-string-no-properties 1))
          (match-string-no-properties 2))

(use-package bug-reference
  (bug-reference-bug-regexp (rx (group (in ?! ?#))
                                (group (+ digit))))
  (bug-reference-url-format #'my-gitlab-url)
  (text-mode . bug-reference-mode)
  (prog-mode . bug-reference-prog-mode))

Highlight indentation

(use-package highlight-indentation
  (python-mode . highlight-indentation-mode))

Python related setup and use-package calls

Because, well, that’s my job now. Of course it gets a dedicated section.

Set up pretty symbols for Python

Because they are fancy.

  • not: ¬
  • in: ∈
  • def: ƒ

Maybe add ∉ for not in later, if possible.

(add-hook 'python-mode-hook
          (lambda ()
            (add-to-list 'prettify-symbols-alist
                         '("not" . 172))
            (add-to-list 'prettify-symbols-alist
                         '("in" . 8712))
            (add-to-list 'prettify-symbols-alist
                         '("def" . 402))))

Pyre-based LSP

(use-package lsp-pyre
  (python-mode . lsp))


Because it’s also great.

(use-package poetry
  (remove-hook 'post-command-hook 'poetry-track-virtualenv)
  (poetry-tracking-mode . (lambda () (remove-hook 'post-command-hook 'poetry-track-virtualenv)))
  (python-mode . poetry-track-virtualenv)
  (projectile-after-switch-project-hook . poetry-track-virtualenv))

Automatically insert Sphinx-style docstrings

(use-package sphinx-doc
  (python-mode . sphinx-doc-mode))

C mode

Because that’s still my favourite language.

Set up my own C style

(defconst my-c-style
  '((c-tab-always-indent        . t)
    (c-comment-only-line-offset . 4)
    (c-hanging-braces-alist     . ((substatement-open after)
    (c-hanging-colons-alist     . ((member-init-intro before)
                                   (case-label after)
                                   (label after)
                                   (access-label after)))
    (c-cleanup-list             . (scope-operator
    (c-offsets-alist             . ((arglist-close . +)
                                    (arglist-intro . +)
                                    (substatement-open . 0)
                                    (case-label . 4)
                                    (block-open . 0)
                                    (knr-argdecl-intro . -)
                                    (comment-intro . 0)
                                    (member-init-intro . ++)))
    (c-echo-syntactic-information-p . t))
  "My C Programming Style.")
(c-add-style "PERSONAL" my-c-style)

Some common initialisation for C mode

(add-hook 'c-mode-common-hook
          (lambda ()
            (local-set-key (kbd "C-c o") 'ff-find-other-file)
            (c-set-style "PERSONAL")
            (customize-set-variable 'c-basic-offset 4)
            (customize-set-variable 'tab-width 4)
            (customize-set-variable 'indent-tabs-mode nil)
            (c-toggle-auto-newline 1)))
(add-hook 'c-initialization-hook
          (lambda ()
            (define-key c-mode-base-map (kbd "C-m") 'c-context-line-break)))

Set indentation levels to the same as the tab width

(defvaralias 'c-basic-offset 'tab-width)
(defvaralias 'cperl-indent-level 'tab-width)

Web development

Web mode

(use-package web-mode
  :mode "\\.html?\\'"
  (web-mode-enable-auto-indentation nil)
  (web-mode-enable-engine-detection t))

Emmet mode

(use-package emmet-mode
  (emmet-self-closing-tag-style "")
  (web-mode . emmet-mode)
  (css-mode . emmet-mode))

Query HTML tags by CSS selectors

(use-package enlive)


(use-package flycheck
  (flycheck-python-pylint-executable "python3"))

FlyCheck for pkg-config files

(use-package flycheck-pkg-config)

Org mode

This is a big one; I use a lot of customisation here.

(use-package org
  (require 'xdg-paths)
  (defface org-checkbox-todo-text
    '((t (:inherit org-todo)))
    "Face for the text part of an unchecked org-mode checkbox.")
  (defface org-checkbox-done-text
    '((t (:inherit org-done)))
    "Face for the text part of a checked org-mode checkbox.")
   `(("^[ \t]*\\(?:[-+*]\\|[0-9]+[).]\\)[ \t]+\\(\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\[\\(?: \\|\\([0-9]+\\)/\\2\\)\\][^\n]*\n\\)" 1 'org-checkbox-todo-text prepend))
   `(("^[ \t]*\\(?:[-+*]\\|[0-9]+[).]\\)[ \t]+\\(\\(?:\\[@\\(?:start:\\)?[0-9]+\\][ \t]*\\)?\\[\\(?:X\\|\\([0-9]+\\)/\\2\\)\\][^\n]*\n\\)" 12 'org-checkbox-done-text prepend))
  (setq-default org-default-notes-file (expand-file-name "" org-directory)
                org-agenda-files `(,org-directory)
                org-time-stamp-formats '("<%Y-%m-%d>" . "<%Y-%m-%d %H:%M>")
                org-todo-keywords '((sequence "TODO(t)"
                org-todo-keyword-faces '(("SOMEDAY" . (:foreground "goldenrod"))
                                         ("CANCELED" . (:foreground "#228b22" :strike-through t)))
                '((unicode (on . "<span class=\"task-done\">☑</span>")
                           (off . "<span class=\"task-todo\">☐</span>")
                           (trans . "<span class=\"task-in-progress\">▣</span>"))))
  ;; Load the markdown exporter
  (require 'ox-md)
  ;; Handle org-protocol:// links
  (require 'org-protocol)
  ;; Make it possible to encrypt headings
  (require 'org-crypt)
  ;; Make it possible to use inline tasks
  (require 'org-inlinetask)
  ;; Make it possible to use structure templates with < X TAB
  (require 'org-tempo)

  (org-log-into-drawer t)
  (org-ellipsis "…#")
  (org-startup-folded 'content)
  (org-log-done 'time)
  (org-src-preserve-indentation t)
  (org-tags-column 0)
  (org-startup-indented t)
  (org-special-ctrl-a/e t)
  (org-return-follows-link t)
  (org-src-fontify-natively t)
  (org-goto-interface 'outline-path-completion)
  (org-goto-max-level 10)
  (org-html-checkbox-type 'unicode)
  (org-src-window-setup 'current-window)
  (org-pretty-entities t)
  (org-pretty-entities-include-sub-superscripts t)
  (org-use-speed-commands t)
  (org-hide-leading-stars t)
  (org-enforce-todo-dependencies t)
  (org-enforce-todo-checkbox-dependencies t)
  (org-catch-invisible-edits 'show)
  (org-log-reschedule 'time)
  (org-log-redeadline 'note)
  (org-refile-use-outline-path 'file)
  (org-outline-path-complete-in-steps nil)
  (org-refile-allow-creating-parent-nodes 'confirm)
  (org-crypt-key "B0740C4C")
  (org-speed-commands-user '(("m" . org-mark-subtree)))
  (org-refile-targets '((org-agenda-files :maxlevel . 3)))
  (org-agenda-custom-commands '(("c" "Simple agenda view"
                                 ((tags "PRIORITY=\"A\""
                                        ((org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
                                         (org-agenda-overriding-header "High priority unfinished tasks")))
                                  (agenda "")
                                  (alltodo ""
                                             '(or (air-org-skip-subtree-if-habit)
                                                  (air-org-skip-subtree-if-priority ?A)
                                                  (gpolonkai/org-skip-subtree-if-state "SOMEDAY")
                                                  (org-agenda-skip-if nil '(scheduled deadline))))
                                            (org-agenda-overriding-header "ALL normal priority tasks"))))
                                 ((org-agenda-compact-blocks t)))))
  (org-log-note-clock-out t)
  (org-capture-templates '(("L" "Org-protocol capture" entry
                             (lambda ()
                               (expand-file-name "" org-directory))
                            "** %:description\n:PROPERTIES:\n:SOURCE: %:link\n:END:\n\n%:initial"
                            :empty-lines 1)
                           ("R" "Region to Current Clocked Task" plain
                            :immediate-finish t
                            :empty-lines 1)
                           ("K" "Kill-ring to Current Clocked Task" plain
                            :immediate-finish t
                            :empty-lines 1)
                           ("c" "Item to current Clocked Task" item
                            :empty-lines 1)
                           ("g" "GT2 note" entry
                             (lambda ()
                               (expand-file-name "" org-directory))
                            "** %^{Title}\n:PROPERTIES:\n:CREATED: %T\n:END:\n\n%a\n\n%i%?")
                           ("p" "Blog post" entry
                             (lambda ()
                               (expand-file-name "" org-directory)))
                            "* %^{Title}  :blog:\n:PROPERTIES:\n:CREATED:  %T\n:END:\n\n%i%?")))
  (org-read-date-force-compatible-dates nil)
  (org-agenda-prefix-format '((agenda . " %i %-12:c%?-12t% s")
                              (todo . " %i %-12:c %(concat \"[ \"(org-format-outline-path (org-get-outline-path)) \" ]\") ")
                              (tags . " %i %-12:c %(concat \"[ \"(org-format-outline-path (org-get-outline-path)) \" ]\") ")
                              (timeline . "  % s")
                              (search . " %i %-12:c")))
  (org-agenda-dim-blocked-tasks t)
  (ediff-select . f-ediff-org-unfold-tree-element)
  (ediff-unselect . f-ediff-org-fold-tree)
  (:map gpolonkai/pers-map
   ("a" . gpolonkai/org-agenda-list)
   ("C" . org-capture)
   ("l" . org-store-link)
   :map org-mode-map
   ("SPC" . org-space-key)
   ("C-c l" . org-toggle-link-display)
   ("C-a" . gpolonkai/move-to-beginning-of-line)
   ("C-e" . gpolonkai/move-to-end-of-line)
   ("C-c h" . outline-previous-heading)
   ("C-c ;" . org-toggle-timestamp-type)))

Show a random ToDo every hour

(use-package org-random-todo
  ;; Don’t bug me too often…
  (setq org-random-todo-how-often 3600)
  (org-random-todo-skip-keywords '("SOMEDAY"))
  (:map gpolonkai/pers-map
   ("r" . org-random-todo)))

Load CalDAV entries from NextCloud

(use-package org-caldav
  :after org
   org-caldav-url ""
   org-caldav-calendar-id "org"
   org-caldav-inbox (expand-file-name "" org-directory)
   org-caldav-files nil))

Improved list management

(use-package org-autolist
  (org-mode . org-autolist-mode))

Write messages with Org-mode

(use-package org-msg
  :after mu4e
  :defer t
  (org-msg-supported-mua '((sendmail-user-agent . "mu4e")))
  (org-msg-options "html-postamble:nil H:5 num:nil ^:{} toc:nil")
  (org-msg-startup "hidestars indent inlineimages")
  (org-msg-greeting-fmt "\nHello,\n\n")
  (org-msg-greeting-fmt-mailto nil)
  (org-msg-signature "\n\nBest,\n\n,#+begin_signature\n-- *Gergely Polonkai* \\\\\n,#+end_signature"))

Sticky headers so i always know where i am

(use-package org-sticky-header
  (org-sticky-header-full-path 'full)
  (org-mode . org-sticky-header-mode))

Custom bullets

(use-package org-bullets
  (org-bullets-face-name 'org-bullet-face)
  (org-bullets-bullet-list '("✙" "♱" "♰" "☥" "✞" "✟" "✝" "†" "✠" "✚" "✜" "✛" "✢" "✣" "✤" "✥"))
  (org-mode . org-bullets-mode))

Edit diagrams with mermaid

(use-package ob-mermaid
  (ob-mermaid-cli-path "/home/polesz/.local/node/bin/mmdc"))

Allow exporting to ReSTructured text

(use-package ox-rst
  :after org)

Export currently clocked in task for Waybar

(use-package org-clock-waybar
  :ensure nil
  :quelpa (org-clock-waybar
           :fetcher git
           :url "")

Git & Co.

Git status on the fringe

In graphical modes we use git-gutter-fringe, and git-gutter otherwise.

;; Git gutter
;; If we are in text-only mode, there is no fringe.
(let ((gitgutter-package
       (if (display-graphic-p)
  (eval `(use-package ,gitgutter-package
    (global-git-gutter-mode t)
    (:map gpolonkai/pers-map
     ("gg" . git-gutter:update-all-windows)
     ("gn" . git-gutter:next-hunk)
     ("gp" . git-gutter:previous-hunk)))))

Git messenger

AKA blame current line.

(use-package git-messenger
  (:map gpolonkai/pers-map
   ("gm" . git-messenger:popup-message)))

Git time machine

See previous versions of the current file.

(use-package git-timemachine
  (([f6] . git-timemachine-toggle)))

Company & Co.

(use-package company
  :delight " 🏢"
  (company-idle-delay nil)
  (company-dabbrev-downcase nil)
  (setq company-frontends '(company-pseudo-tooltip-frontend
  (put 'company-clang-arguments 'safe-local-variable #'nil-or-list-of-strings-p)

Company completion based on local C headers

(use-package company-c-headers)

Company mode in the shell

(use-package company-shell)

REST Client completion via Company

(use-package company-restclient)

Insert Emoji with Company

(use-package company-emoji
  (--set-emoji-font nil)
  (add-to-list 'company-backends 'company-emoji))

Web mode (web-mode and emmet-mode, too) backend for Company

(use-package company-web
  (require 'company-web-html))

Ivy & Co.

Ivy & Counsel

(use-package ivy
  (ivy-mode 1)
  (ivy-use-virtual-buffers t)
  (ivy-count-format "(%d/%d) ")
  (ivy-use-selectable-prompt t))
(use-package counsel
  (:map company-mode-map
   ("C-c j" . counsel-company)
   :map company-active-map
    ("C-c j" . counsel-company)))

GNU Globals with Counsel

(defun gpolonkai/enable-counsel-gtags-mode ()
  (counsel-gtags-mode t))

(use-package counsel-gtags
  (counsel-gtags-auto-update t)
  (counsel-gtags-path-style 'relative)
  (c-mode . gpolonkai/enable-counsel-gtags-mode)
  (:map counsel-gtags-mode-map
   ("M-t" . counsel-gtags-find-definition)
   ("M-r" . counsel-gtags-find-reference)
   ("M-s" . counsel-gtags-find-symbol)
   ("C-c <" . counsel-gtags-go-backward)
   ("C-c >" . counsel-gtags-go-forward)))

Ag with Counsel

(use-package counsel-ag-popup
  (:map gpolonkai/pers-map
   ("s" . counsel-ag-popup)))

Projectile with Counsel

(use-package counsel-projectile
  (projectile-completion-system 'ivy)

FlySpell with Ace

(use-package ace-flyspell
  (:map flyspell-mode-map
   ("C-M-i" . ace-flyspell-correct-word)))

C Yasnippets with Ivy

(use-package ivy-yasnippet
  (("C-c y" . ivy-yasnippet)))

PyDoc with Counsel

(use-package counsel-pydoc)

BibTex with Ivy

First, set up bibtex-completion:

(use-package bibtex-completion
  (bibtex-completion-bibliography (expand-file-name "references.bib" org-directory))
  (bibtex-completion-library-path (expand-file-name "bibtex-pdfs" org-directory))
  (bibtex-completion-pdf-open-function 'org-open-file)
  (bibtex-completion-notes-path (expand-file-name
                                 (convert-standard-filename "bibliography/ivy-bibtex-notes")
(use-package ivy-bibtex
  :after bibtex-completion)

Access passwords in pass using Ivy

(use-package ivy-pass)

Mode specific use-package calls


(use-package js2-mode
  :pin melpa-stable
  :mode "\\.js\\'")

Jinja templates

(use-package jinja2-mode
  :mode "\\.j2\\'")


(use-package typescript-mode
  :mode "\\.ts\\'")


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


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


(use-package yaml-mode
  :mode (("\\.yml\\'" . yaml-mode)
         ("\\.yaml\\'" . yaml-mode))
  (add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode)))


(use-package markdown-mode
  :mode (("\\.md\\'" . markdown-mode)
         ("\\.markdown\\'" . markdown-mode)))


(use-package less-css-mode
  :mode "\\.less\\'")


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


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


(use-package dockerfile-mode)


(use-package po-mode
  :ensure nil
  :mode "\\.po\\'")


(use-package csharp-mode
  :mode "\\.cs\\'")

Gherkin (BDD) feature files

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


Before using this, make sure the latest PlantUML JAR file is downloaded into the downloads directory. It is available from here.

(use-package plantuml-mode
  (setq plantuml-jar-path
         ;; Make sure we have a download location even if XDG is not working
          ((xdg-user-dir "DOWNLOAD")
           (expand-file-name "plantuml.jar" (xdg-user-dir "DOWNLOAD")))
  (defvaralias 'org-plantuml-jar-path 'plantuml-jar-path)
   '((plantuml . t))))

For editing CSV files

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

The Go programming language

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

Meson build system

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


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


(use-package gitlab-ci-mode
  :mode "\\.gitlab-ci.yml\\'")
(use-package gitlab-ci-mode-flycheck
  :after flycheck gitlab-ci-mode


(use-package arduino-mode
  :mode "\\.ino\\'")

Vue templates

(use-package vue-html-mode
  :mode "\\.vue\\'")

Pony is awesome!

(use-package ponylang-mode
  :mode "\\.pony\\'")


(use-package rust-mode
  :mode "\\.rs\\'")
(use-package cargo)
(use-package flycheck-rust)

Fish shell

(use-package fish-mode
  (fish-mode . (lambda () (add-hook 'before-save-hook 'fish_indent-before-save))))


(use-package clojure-mode)

Flutter specific things

(use-package lsp-mode)

(use-package lsp-dart
  (dart-mode . lsp))

(use-package lsp-ui)

(use-package hover)

Bats, for testing shell scripts

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


(use-package terraform-mode
  :mode "\\.tf\\'")


Gnu Go

(use-package gnugo)

Last, but not least, key bindings!

TODO My own, personal, Magit-popup! experimental

With the new Transient package it will be easier. I just don’t know how to use it yet.

(define-transient-command gpolonkai/clock-menu ()
  [("I" "Clock in to last clocked task" org-clock-in-last)
   ("g" "Go to the currently clocked task" org-clock-goto)
   ("i" "Clock in here" org-clock-in)
   ("o" "Clock out" org-clock-out)])

(define-transient-command gpolonkai/special-files-menu ()
  [("i" "My Emacs init file" gpolonkai/visit-init-file)
   ("o" "My main Org file" gpolonkai/visit-org-index)])

(define-transient-command gpolonkai/git-menu ()
  [("g" "Update Git gutter everywhere" git-gutter:update-all-windows)
   ("m" "Show the origin of this line" git-messenger:popup-message)
   ("n" "Next hunk" git-gutter:next-hunk)
   ("p" "Previous hunk" git-gutter:previous-hunk)])

(define-transient-command gpolonkai/mail-menu ()
  [("c" "Compose mail" mu4e-compose-new)
   ("i" "Jump to folder" mu4e~headers-jump-to-maildir)
   ("m" "Mu4e main screen" mu4e)
   ("s" "Mu4e search" mu4e-headers-search)])

(define-transient-command gpolonkai/sx-menu ()
  [("i" "Inbox" sx-inbox)
   ("s" "Search" sx-search)])

(define-transient-command gpolonkai/zone-menu ()
  [("i" "Enable zone on idle" gpolonkai/zone-enable)
   ("q" "Disable zone on idle" zone-leave-me-alone)])

(define-transient-command gpolonkai/python-menu ()
  [("p" "Poetry" poetry)])

(define-transient-command gpolonkai/menu ()
  [("a" "My agenda" gpolonkai/org-agenda-list)
   ("b" "Where has my cursor gone?" beacon-blink)
   ("C" "Capture" org-capture)
   ("c" "Clocking…" gpolonkai/clock-menu)
   ("M-C" "Clean up old buffers" clean-buffer-list)
   ("e" "EShell" eshell)
   ("g" "Git…" gpolonkai/git-menu)
   ("h" "Hide mode-line" hidden-mode-line-mode)
   ("l" "Store Org link" org-store-link)
   ("m" "Mail…" gpolonkai/mail-menu)
   ("o" "Special files…" gpolonkai/special-files-menu)
   ("p" "Python…" gpolonkai/python-menu)
   ("q" "Stack Exchange…" gpolonkai/sx-menu)
   ("r" "Show a random TODO" org-random-todo)
   ("u" "Open URL" browse-url-at-point)
   ("w" "Clean up whitespace problems" whitespace-cleanup)
   ("x" "Expand region" er/expand-region)
   ("z" "Zone…" gpolonkai/zone-menu)])

The actual key bindings

(defun gpolonkai/isearch-regexp (prefix)
  "Call `isearch-forward-regex'.  If PREFIX is non-nil, call `isearch-backward-regex' instead."
  (interactive "P")
   (if prefix
 :map global-map
 ("M-(" . gpolonkai/enclose-region)
 ("<C-return>" . open-line-below)
 ("<C-S-return>" . open-line-above)
 ("M-t" . nil) ;; Remove the old keybinding
 ("M-t c" . transpose-chars)
 ("M-t w" . transpose-words)
 ("M-t l" . transpose-lines)
 ("M-t e" . transpose-sexps)
 ("M-t s" . transpose-sentences)
 ("M-t p" . transpose-paragraphs)
 ("M-t W" . transpose-windows)
 ("C-a" . gpolonkai/move-to-beginning-of-line)
 ("C-e" . gpolonkai/move-to-end-of-line)
 ("M-q" . sachachua/fill-or-unfill-paragraph)
 ("C-c r" . round-number-at-point-to-decimals)
 ("C-s" . swiper)
 ("C-r" . gpolonkai/isearch-regexp)
 ("C-M-s" . isearch-forward)
 ("C-M-r" . isearch-backward)
 ("C-~" . toggle-char-case)
 ("C-z" .  nil)
 ("M-g SPC" . goto-next-char)
 :map ctl-x-map
 ("C-y" . gpolonkai/duplicate-line)
 ("_" . maximize-window)
 ("C-r" . rename-current-buffer-file)
 ("C-d" . delete-current-buffer-file)
 ("|" . toggle-window-split)
 ("k" . kill-this-buffer)
 ("M-k" . gpolonkai/undo-buffer-kill)
 ("C-b" . bury-buffer)
 ("/" . repeat)
 ("C-f" . counsel-find-file)
 ("b" . counsel-switch-buffer)
 :map isearch-mode-map
 ("<C-return>" . isearch-exit-other-end)
 ("<S-return>" . isearch-exit-mark-match)
 :map gpolonkai/pers-map
 ("C-t" . gpolonkai/menu)
 ("h" . hidden-mode-line-mode)
 ("C-i e" . "")
 ("C-i w" . "")
 ("o i" . gpolonkai/visit-init-file)
 ("o o" . gpolonkai/visit-org-index)
 ("u" . browse-url-at-point)
 ("M-C" . clean-buffer-list)
 ("C-c" . calc)
 ("c i" . org-clock-in)
 ("c I" . org-clock-in-last)
 ("c o" . org-clock-out)
 ("c g" . org-clock-goto)
 ("M-o" . insert-current-file-name-at-point))

TODO These fail to work using bind-keys, but why?

(define-key 'help-command (kbd "C-l") 'find-library)
(define-key 'help-command (kbd "C-f") 'find-function)
(define-key 'help-command (kbd "C-k") 'find-function-on-key)
(define-key 'help-command (kbd "C-v") 'find-variable)

And finally, server mode

Sometimes i start an emacsclient process, like for editing a commit message or something similar. As my startup time is pretty long, waiting for everything to complete is undesirable.

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