💾 Archived View for tilde.club › ~sulaco › emacs_config.gmi captured on 2022-04-28 at 17:27:34. Gemini links have been rewritten to link to archived content
View Raw
More Information
⬅️ Previous capture (2021-12-03)
-=-=-=-=-=-=-
#+OPTIONS: ^:nil html-postamble:nil author:nil
#+STARTUP: content
#+TITLE: Emacs config
This is an raw, abdriged version of my emacs config written in
org-mode as described here:
https://cestlaz.github.io/posts/using-emacs-10-org-init/
My init.el looks like this:
#+BEGIN_QUOTE
(require 'package)
(setq package-enable-at-startup nil)
(add-to-list 'package-archives
'("melpa" . "https://melpa.org/packages/"))
(package-initialize)
;; Bootstrap `use-package'
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(org-babel-load-file (expand-file-name "~/.emacs.d/myinit.org"))
;; emacs can clutter this file. Don't load it.
(setq custom-file (make-temp-file "emacs-custom"))
#+END_QUOTE
#+BEGIN_SRC emacs-lisp :results none
(menu-bar-mode 0)
(tool-bar-mode 0)
(scroll-bar-mode 0)
(global-hl-line-mode t)
(column-number-mode t)
(show-paren-mode t)
(delete-selection-mode t)
(setq inhibit-splash-screen t)
(setq sentence-end-double-space nil)
#+END_SRC
#+BEGIN_SRC emacs-lisp :results none
(use-package ivy
:ensure t
:diminish (ivy-mode . "")
:init
(ivy-mode t)
(savehist-mode 1)
:config (setq ivy-use-virtual-buffers t
ivy-count-format "%d/%d ")
:bind
(("M-x" . counsel-M-x)
("C-s" . swiper-isearch)
("C-x l" . counsel-locate)
("M-y" . counsel-yank-pop)))
(use-package counsel
:ensure t)
#+END_SRC
#+BEGIN_SRC emacs-lisp :results none
(use-package doom-modeline
:ensure t
:init (doom-modeline-mode 1)
:config (setq doom-modeline-icon t))
#+END_SRC
#+BEGIN_SRC emacs-lisp :results none
(use-package nyan-mode
:ensure t
:init (nyan-mode 1)
:config (setq nyan-bar-length 40))
#+END_SRC
#+BEGIN_SRC emacs-lisp :results none
(setq display-time-24hr-format t
display-time-default-load-average nil
display-time-mail-file "~/RMAIL")
(display-time-mode 1)
#+END_SRC
- * Reduce nagging/annoyances
#+BEGIN_SRC emacs-lisp :results none
;; answer with y/n
(defalias 'yes-or-no-p 'y-or-n-p)
;; don't confirm new async shell buffer
(setq async-shell-command-buffer 'new-buffer)
;; enable features
(put 'list-timers 'disabled nil)
(put 'narrow-to-region 'disabled nil)
;; auto-hide async shell buffers
(add-to-list 'display-buffer-alist
(cons "\\*Async Shell Command\\*.*"
(cons #'display-buffer-no-window nil)))
#+END_SRC
#+BEGIN_SRC emacs-lisp :results none
(tab-bar-mode t)
(defhydra hydra-tab-control ()
"Tab controls"
("c" tab-bar-new-tab "create" :exit t)
("f" find-file "find" :exit t)
("k" tab-bar-close-tab "kill" :exit t)
("n" tab-bar-switch-to-next-tab "next")
("b" tab-bar-switch-to-prev-tab "previous")
("j" tab-switcher "jump" :exit t)
("q" nil "quit"))
(global-set-key (kbd "<f2>") 'hydra-tab-control/body)
#+END_SRC
#+BEGIN_SRC emacs-lisp :results none
(setq custom-safe-themes t)
(load-theme 'dracula)
#+END_SRC
#+BEGIN_SRC emacs-lisp :results none
(defun toggle-transparency ()
(interactive)
(let ((alpha (frame-parameter nil 'alpha)))
(set-frame-parameter
nil 'alpha
(if (eql (cond ((numberp alpha) alpha)
((numberp (cdr alpha)) (cdr alpha))
;; Also handle undocumented (<active> <inactive>) form.
((numberp (cadr alpha)) (cadr alpha)))
100)
'(95 . 65)
'(100 . 100)))))
#+END_SRC
- User defined functions
- * Open file with xdg-open
#+BEGIN_SRC emacs-lisp :results none
(defun sulaco/xdg-open ()
"Open file on point or marked files with xdg-open"
(interactive)
(let* ((file-list (dired-get-marked-files))
(do-it-p
(if (> (length file-list) 1)
(y-or-n-p "Open more than 1 file? ")
t)))
(when do-it-p
(mapc
(lambda (file-path)
(let ((process-connection-type nil))
(start-process "" nil "xdg-open" file-path))) file-list))))
#+END_SRC
- * Home directory shortcut
#+BEGIN_SRC emacs-lisp :results none
(defun sulaco/go-home ()
"Open dired buffer in home directory"
(interactive)
(dired "~/")
(revert-buffer))
(global-set-key (kbd "C-.") 'sulaco/go-home)
#+END_SRC
#+BEGIN_SRC emacs-lisp :results none
(defun sulaco/copy-line ()
"Copy current line."
(interactive)
(kill-ring-save
(line-beginning-position)
(line-end-position))
; (beginning-of-line)
(message "current line copied"))
(global-set-key (kbd "M-SPC") 'sulaco/copy-line)
#+END_SRC
#+BEGIN_SRC emacs-lisp :results none
(defun sulaco/move-line-up ()
"Move up the current line."
(interactive)
(transpose-lines 1)
(forward-line -2))
(defun sulaco/move-line-down ()
"Move down the current line."
(interactive)
(forward-line 1)
(transpose-lines 1)
(forward-line -1))
(global-set-key [(meta shift up)] 'sulaco/move-line-up)
(global-set-key [(meta shift down)] 'sulaco/move-line-down)
#+END_SRC
#+BEGIN_SRC emacs-lisp :results none
(defun sulaco/buffer-list ()
"open and focus buffer list"
(interactive)
(bs-show 0)) ; files only, [a] to toggle
(global-set-key (kbd "C-x C-b") 'sulaco/buffer-list)
#+END_SRC
- * Download youtube video from *elfeed-entry*
#+BEGIN_SRC emacs-lisp :results none
(defun sulaco/ytdl ()
"Download URL with youtube-dl"
(interactive)
(beginning-of-buffer)
(forward-line 2)
(search-forward "http")
(shell-command
(format "cd ~/ && youtube-dl '%s' &"
(thing-at-point 'url)))
(kill-buffer "*elfeed-entry*")
(message "Download started..."))
#+END_SRC
#+BEGIN_SRC emacs-lisp :results none
(defun sulaco/url-search ()
(interactive)
(progn
(browse-url
(concat
"https://duckduckgo.com/?q="
(url-hexify-string
(read-from-minibuffer "search term: "))))
(shell-command "i3-msg 'workspace number 2'")))
#+END_SRC
#+BEGIN_SRC emacs-lisp :results none
(defun sulaco/toggle-eshell ()
"Switch to eshell. If already visiting eshell buffer return to
previous buffer"
(interactive)
(if (string= (buffer-name) "*eshell*")
(switch-to-prev-buffer)
(eshell)))
(global-set-key (kbd "<f12>") 'sulaco/toggle-eshell)
(add-hook 'eshell-mode-hook
(lambda ()
(local-set-key
(kbd "C-r")
(lambda ()
(interactive)
(insert
(ivy-read "Eshell history: "
(delete-dups
(ring-elements eshell-history-ring))))))))
#+END_SRC
Translate Germanic umlauts and other special characters to pure ASCII.
#+BEGIN_SRC emacs-lisp :results none
(defun sulaco/gopher-translate-special ()
(interactive)
(let ((case-fold-search nil)
(trans-list
(list '("ä" . "ae")
'("ö" . "oe")
'("ü" . "ue")
'("Ä" . "Ae")
'("Ö" . "Oe")
'("Ü" . "Ue")
'("ß" . "ss")
'("„" . "\"")
'("“" . "\""))))
(mapc (lambda (x)
(goto-char (point-min))
(while (search-forward (car x) nil t)
(replace-match (cdr x) t)))
trans-list)))
#+END_SRC
Justify paragraphs (for exported plain text).
#+BEGIN_SRC emacs-lisp :results none
(defun sulaco/gopher-justify ()
(interactive)
(beginning-of-buffer)
(forward-line 4) ;; skip title
(while (not (eobp))
(progn
(when (re-search-forward "^[[:blank:]]+[[:alnum:]]" nil t nil)
(fill-paragraph 1 nil))
(forward-paragraph 1))))
#+END_SRC
Keep version controlled backups in a separate folder.
#+BEGIN_SRC emacs-lisp :results none
(setq backup-directory-alist '(("." . "~/.emacs.d/backup"))
backup-by-copying t ; Don't de-link hard links
version-control t ; Use version numbers on backups
delete-old-versions t ; Automatically delete excess backups:
kept-new-versions 10 ; how many of the newest versions to keep
kept-old-versions 5) ; and how many of the old
#+END_SRC
Save auto-save files in the temp directory.
#+BEGIN_SRC emacs-lisp :results none
(setq auto-save-file-name-transforms
`((".*" ,temporary-file-directory t)))
#+END_SRC
#+BEGIN_SRC emacs-lisp :results none
(use-package dired
:ensure nil
:init
(setq dired-listing-switches "-hlL --group-directories-first"
dired-dwim-target t)
(add-hook 'dired-mode-hook
(lambda ()
(toggle-truncate-lines 1)
(defalias 'dired-mouse-find-file-other-window
'dired-mouse-find-file)))
:bind (:map dired-mode-map
("e" . #'sulaco/xdg-open)))
#+END_SRC
| key | function |
|---------+------------------------------|
| v | view file read only |
| m | mark |
| t | toggle marks |
| U | unmark all |
| d | mark for deletion |
| x | delete flagged |
| Z | compress/uncompress |
| w | copy filename |
| 0w | copy filepath |
| i | insert directory |
| C | copy file/marked |
| R | rename/move file/marked |
| C-x C-q | editable dired mode |
| C-u s | change ls switches |
| ! | echo * -> echo foo bar baz |
| ! | echo foo; echo bar; echo baz |
| %m | mark regexp |
| k | delete line |
#+BEGIN_SRC emacs-lisp :results none
(use-package elfeed
:ensure t
:config
(setq-default elfeed-search-filter
"#50")
(setq elfeed-feeds
(quote
(FEEDS GO HERE)))
:bind (:map elfeed-show-mode-map
("y" . #'sulaco/ytdl)))
#+END_SRC
#+BEGIN_SRC emacs-lisp :results none
(setq org-src-tab-acts-natively t)
(setq org-confirm-babel-evaluate nil)
#+END_SRC
| key | function |
|-------+------------------------|
| C-c ' | edit code block |
| C-c ; | toggle comment heading |
- Programming
- * Auto-complete
#+BEGIN_SRC emacs-lisp :results none
(use-package auto-complete
:ensure t)
#+END_SRC
- M-x hs-minor-mode
- M-x hs-hide-all
- M-x hs-show-all
- C-c @ C-c toggle fold