💾 Archived View for minasmazar.srht.site › minemacs.gmi captured on 2023-01-29 at 02:28:44. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
This =org-mode= document is my Emacs configuration file. It uses the
function =org-babel-load-file= to be exported all emacs-lisp block
codes present here and evaluate them as a standard =.el= file.
This way you can have docs/notes/ideas along with your configuration file.
Copy paste this code block into your =init.el= file.
(add-to-list 'load-path "~/.emacs.d/manual-packages/")
(require 'package)
(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/") t)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t)
(package-initialize)
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(setq package-enable-at-startup nil)
(straight-use-package 'use-package)
(use-package org
:config
(org-babel-load-file (concat user-emacs-directory "minemacs.org")))
(setq custom-file (concat user-emacs-directory "custom.el"))
(setq backup-inhibited t
auto-save-default nil
make-backup-files nil
use-dialog-box nil
global-auto-revert-non-file-bufffers t
tab-always-indent 'complete
indent-tabs-mode nil
ring-bell-function 'ignore
visible-bell nil
initial-buffer-choice 'eshell
completion-auto-select t
bookmark-default-file "~/Dropbox/.emacs.bookmarks"
browse-url-handlers '(("github" . browse-url-chrome)
("youtube" . browse-url-firefox)
("." . eww-browse-url))
diary-file "~/Dropbox/org/diary"
calendar-mark-diary-entries-flag t
org-agenda-include-diary t
epa-pinentry-mode 'loopback
;; epg-gpg-program "/usr/local/bin/gpg2"
;;auth-sources '("./.emacs.d/.authinfo.gpg")
;;(push "/usr/local/bin" exec-path)
;;(push "~/.asdf/shims" exec-path)
;;(setenv "PATH" (string-join exec-path ":"))
;;(setenv "EDITOR" (or (getenv "EDITOR") "emacsclient"))
)
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(display-time-mode 1)
(show-paren-mode t)
(defmacro minemacs-package! (package &rest args)
"Wrapper around use-package"
`(use-package ,package ,@args :ensure t))
(defun minemacs-config-open ()
"Open init.el file"
(interactive)
(let ((file (concat user-emacs-directory "minemacs.org")))
(find-file file)))
(defcustom minemacs-module-dir "~/.emacs.d/modules/" "Minemacs modules base directory" :group 'minemacs)
(defun minemacs-module-load (module)
"Load module."
(interactive "s")
(let* ((module-el-file (concat minemacs-module-dir (format "%s.el" module)))
(el-exists (file-exists-p module-el-file)))
(if el-exists
(progn
(load module-el-file 'noerrors)
module-el-file))))
(defun minemacs-current-kill-edit (&optional ARG)
(interactive
(read-string "(EDIT) " (current-kill 0 t))))
On MacOS there are some problem on well syncing ENVs variables.
A solution is to install the *exec-path-from-shell* package
(minemacs-package! exec-path-from-shell
:config
(exec-path-from-shell-initialize))
(global-set-key (kbd "s-h") nil)
(global-set-key (kbd "s-o") nil)
(global-set-key (kbd "s-k") 'execute-extended-command)
;;(global-set-key (kbd "C-k") nil)
;;(global-set-key (kbd "C-k") 'execute-extended-command)
(minemacs-package! god-mode
:config
(god-mode)
(global-set-key (kbd "s-n") 'god-local-mode)
;;(global-set-key (kbd "C-l") nil)
;;(global-set-key (kbd "C-l") 'god-local-mode)
(define-key god-local-mode-map (kbd "i") 'god-local-mode)
(define-key god-local-mode-map (kbd "u") 'undo)
(define-key god-local-mode-map (kbd "U") 'undo-redo)
(define-key god-local-mode-map (kbd ".") 'repeat)
(define-key god-local-mode-map (kbd ">") 'end-of-buffer)
(define-key god-local-mode-map (kbd "<") 'beginning-of-buffer)
(define-key god-local-mode-map (kbd "[") #'backward-paragraph)
(define-key god-local-mode-map (kbd "]") #'forward-paragraph)
;; (add-to-list 'god-exempt-major-modes 'elfeed-search-mode)
;; (add-to-list 'god-exempt-major-modes 'elfeed-show-mode)
;; (add-to-list 'god-exempt-major-modes 'vterm-mode)
;; (add-to-list 'god-exempt-major-modes 'compilation-mode)
(defun minemacs-god-mode-enabled ()
(setq minemacs-god-mode-status 1)
(setq cursor-type 'box))
(defun minemacs-god-mode-disabled ()
(setq minemacs-god-mode-status nil)
(setq cursor-type 'bar))
(add-hook 'god-mode-enabled-hook 'minemacs-god-mode-enabled)
(add-hook 'god-mode-disabled-hook 'minemacs-god-mode-disabled)
(defun minemacs-mode-line-god-mode-indicator ()
(if minemacs-god-mode-status " *G* " "i "))
(add-to-list 'mode-line-format '(:eval (minemacs-mode-line-god-mode-indicator))))
Eshell as "Quake terminal"
(add-to-list 'display-buffer-alist '("\\*eshell\\*"
(display-buffer-in-side-window)
(window-height . 0.35)
(side . top)
(slot . -1)
(window-parameters . (
(mode-line-format . (" " "%b"))))))
(require 'eshell)
(add-hook 'shell-mode-hook '(lambda ()
(define-key shell-mode-map (kbd "C-j") 'comint-history-isearch-backward-regexp)))
Aliases in the eshell-aliases-file
alias ff find-file $1
alias ll ls -la $1
(minemacs-package! savehist
:init
(savehist-mode))
(setq completion-styles '(flex))
(minemacs-package! orderless
:custom
(completion-styles '(orderless)))
(define-key minibuffer-local-map (kbd "C-c") 'switch-to-completions)
(define-key minibuffer-local-map (kbd "C-n") 'switch-to-completions)
(require 'dired)
(setq dired-dwim-target t
dired-listing-switches "-alt")
(add-hook 'dired-mode-hook 'dired-hide-details-mode)
(minemacs-package! which-key
:config
(which-key-mode))
(global-set-key (kbd "<S-s-return>") 'point-to-register)
(global-set-key (kbd "<s-return>") 'jump-to-register)
(global-set-key (kbd "s-j") 'switch-to-buffer)
(global-set-key (kbd "s-N") 'dired-jump)
(global-set-key (kbd "s-i") 'imenu)
(global-set-key (kbd "s-H") 'minemacs-config-open)
(global-set-key (kbd "s-_") 'bookmark-set)
(global-set-key (kbd "s--") 'bookmark-jump)
(global-set-key (kbd "s-b") 'ibuffer)
(global-set-key (kbd "s-F") 'occur)
(global-set-key (kbd "s-r") 'repeat)
(global-set-key (kbd "s-e") 'dabbrev-expand)
(global-set-key (kbd "s-1") 'delete-other-windows)
(global-set-key (kbd "s-3") 'split-window-horizontally)
(global-set-key (kbd "s-2") 'split-window-vertically)
(global-set-key (kbd "s-0") 'delete-window)
(global-set-key (kbd "s-w") 'other-window)
(global-set-key (kbd "s-W") 'maximize-window)
(global-set-key (kbd "s-R") 'query-replace-regexp)
(global-set-key (kbd "s-p") 'project-switch-to-buffer)
(global-set-key (kbd "s-P") 'project-find-file)
(global-set-key (kbd "s-t") 'rgrep)
(global-set-key (kbd "s-[") 'previous-buffer)
(global-set-key (kbd "s-]") 'next-buffer)
(global-set-key (kbd "s-{") 'previous-window-any-frame)
(global-set-key (kbd "s-}") 'next-window-any-frame)
(global-set-key (kbd "s-)") 'kill-this-buffer)
(global-set-key (kbd "s-\\") 'other-frame)
(global-set-key (kbd "s-=") 'balance-windows)
(global-set-key (kbd "s-<backspace>") 'window-toggle-side-windows)
(define-key key-translation-map (kbd "s-m") (kbd "C-x"))
(define-key key-translation-map (kbd "s-M") (kbd "C-c"))
=find-file-at-point= -> =C-x C-f= which overrides standard find-file
(global-set-key (kbd "C-x C-f") 'find-file-at-point)
(define-key isearch-mode-map (kbd "C-p") 'isearch-repeat-backward)
(define-key isearch-mode-map (kbd "C-n") 'isearch-repeat-forward)
(define-key isearch-mode-map (kbd "<tab>") 'isearch-repeat-forward)
(define-key isearch-mode-map (kbd "<S-tab>") 'isearch-repeat-backward)
(global-set-key (kbd "C-j") nil)
(global-set-key (kbd "C-j") 'zap-up-to-char)
(minemacs-package! company
:config
(global-company-mode))
(minemacs-package! mct
:config
(mct-minibuffer-mode t))
(minemacs-package! hydra
:config
(defhydra hydra-kraken-emoji (:color blue)
"
Kraken: [_j_ 😂 ] [_i_nsert ⚜️]
"
("j" (lambda () (interactive) (insert "😂")))
("i" (lambda () (interactive) (emoji-insert)))
("s-o" nil "quit"))
(defhydra hydra-kraken-bookmarks (:color blue)
"
Kraken: [_j_ump] [_s_et] [_e_dit]
"
("j" bookmark-jump nil)
("s" bookmark-set nil)
("e" edit-bookmarks nil)
("q" nil "quit")
("s-o" nil "quit"))
(defhydra hydra-kraken (:color blue)
"
Kraken: [_h_ome] [_e_shell] [_v_term] [_b_ookmarks] [_m_inemacs.org] [emo_j_i]
"
("h" (lambda () (interactive) (find-file "~/Dropbox/home.org")) nil)
("e" (lambda () (interactive) (eshell t)) nil)
("j" hydra-kraken-emoji/body nil)
("w" eww nil)
("m" minemacs-config-open nil)
("v" vterm nil)
("b" hydra-kraken-bookmarks/body nil)
("q" nil "quit")
("s-o" nil "quit"))
(global-set-key (kbd "s-o") 'hydra-kraken/body))
Contextual engine: =C-,= enables a sort of "at point" feature.
(minemacs-package! embark
:bind*
("C-," . embark-act)
(:map embark-general-map
("C-w" . browse-url))
(:map embark-url-map
("c" . browse-url-chrome)
("f" . browse-url-firefox))
(:map embark-file-map
("p" . project-find-file)
("b" . project-switch-to-buffer)))
(minemacs-package! engine-mode
:config
(engine-mode)
(defengine github
"https://github.com/search?ref=simplesearch&q=%s"
:keybinding "h")
(defengine google
"http://www.google.com/search?ie=utf-8&oe=utf-8&q=%s"
:keybinding "g")
(defengine google-images
"http://www.google.com/images?hl=en&source=hp&biw=1440&bih=795&gbv=2&aq=f&aqi=&aql=&oq=&q=%s"
:keybinding "i")
(defengine google-maps
"http://maps.google.com/maps?q=%s"
:docstring "Mappin' it up."
:keybinding "m")
(defengine stack-overflow
"https://stackoverflow.com/search?q=%s"
:keybinding "o")
(defengine wikipedia
"http://www.wikipedia.org/search-redirect.php?language=en&go=Go&search=%s"
:keybinding "w"
:docstring "Searchin' the wikis.")
(defengine youtube
"http://www.youtube.com/results?aq=f&oq=&search_query=%s"
:keybinding "y")
)
#+begin_src emacs-lisp
(setq user-mail-address "<EMAIL_ADDRESS>"
user-full-name "<FULL NAME>"
user-login-name "<LOGIN_NAME_USUALLY_THE_SAME_AS_EMAIL_ADDRESS>"
mml-secure-openpgp-signers '("YOUR KEY ID")
auth-sources '("./.emacs.d/.authinfo.gpg")
gnus-startup-file "~/.emacs.d/.newsrc"
gnus-select-method '(nnimap "gmail"
(nnimap-address "imap.example.com") ; it could also be imap.googlemail.com if that's your server.
(nnimap-server-port "imaps")
(nnimap-stream ssl))
message-send-mail-function 'smtpmail-send-it
send-mail-function 'smtpmail-send-it
smtpmail-smtp-server "smtp.example.com"
smtpmail-smtp-service 587 ; or 465
smtpmail-stream-type 'starttls
gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")
#+end_src
You can use Emacs as your mail client. In order to configure ~mu4e~ I'm following [[https://gist.github.com/areina/3879626][this useful gist]] and also the instructions in [[https://hobo.house/2017/07/17/using-offlineimap-with-the-gmail-imap-api/][this useful article]].
In order to let ~offlineimap~ to read your authfile, you must save this snippet into your ~~/.offlineimap.py~
#+BEGIN_EXAMPLE python
#!/usr/bin/python
import re, os
def get_password_emacs(machine, login, port):
s = "machine %s login %s password ([^ ]*) port %s\n" % (machine, login, port)
p = re.compile(s)
authinfo = os.popen("gpg -q --no-tty -d ~/.authinfo.gpg").read()
return p.search(authinfo).group(1)
#+END_EXAMPLE
and take care to add this entry to your ~~/.offlineimaprc~
#+BEGIN_EXAMPLE python
pythonfile = ~/.offlineimap.py
#+END_EXAMPLE
A normal ~~/.authfile.gpg~ with some entries for IMAP/SMTP account should be like this.
#+begin_example
machine imap.gmail.com login your-email@example.com password your-strong-password port imaps
machine imap.gmail.com login your-email@example.com password your-strong-password port 587
machine smtp.gmail.com login your-email@example.com password your-strong-password port 465
#+end_example
This is an example of an ~~/.offlineimaprc~ config file for a Gmail email account with the inclusion of ~offlineimap.py~ defined above.
#+begin_example
[general]
accounts = Gmail
maxsyncaccounts = 1
pythonfile = ~/.offlineimap.py
[Account Gmail]
localrepository = Local
remoterepository = Remote
[Repository Local]
type = Maildir
localfolders = ~/Maildir
nametrans = lambda f: '[Gmail]/' + f if f in ['Drafts', 'Starred', 'Important', 'Spam', 'Trash', 'All Mail', 'Sent Mail'] else f
[Repository Remote]
type = Gmail
remoteuser = your-email@gmail.com
remotepasseval = get_password_emacs("imap.gmail.com", "your-email@gmail.com", "993")
realdelete = no
folderfilter = lambda foldername: foldername not in ['[Gmail]/Spam', '[Gmail]/All Mail', '[Gmail]/Starred', '[Gmail]/Important']
folderfilter = lambda foldername: foldername not in ['[Gmail]/Spam', '[Gmail]/All Mail', '[Gmail]/Starred', '[Gmail]/Important']
holdconnectionopen = true
keepalive = 60
sslcacertfile = /etc/ssl/certs/ca-certificates.crt
#+end_example
If you don't have a certificate you can generate via
#+begin_example sh
sudo mkcert -cert-file /etc/ssl/certs/ca-certificates.crt localhost
#+end_example
Useful resources could be found [[https://www.djcbsoftware.nl/code/mu/mu4e/Gmail-configuration.html][here]].
Here we can't simply ~(use-package mu4e)~. On MacOS, if you use ~brew~, you can inspect the package and look for ~mu4e.el~ by using
#+begin_example sh
brew ls --verbose mu | grep mu4e.el
#+end_example
and then soft link the directory into ~~/.emacs.d/mu4e/~.
#+begin_example sh
ln -s /opt/homebrew/Cellar/mu/1.8.11/share/emacs/site-lisp/mu/mu4e/ ~/.emacs.d/mu4e
#+end_example
Consider ~offlineimap~ could invoke indexing of ~mu~ (so setting
the ~mu-binary~ could results in multiple invocations). Also the
~-o~ flag ("invoke once") is required because otherwise it will
stay active in background. Also, if you use =offlineimap= as
daemon (w/o =-o= flag), you don't need to invoke it via =mu4e=, so
set the =mu4e-get-mail-command= to a literal ~true~.
#+begin_example emacs-lisp
(add-to-list 'load-path "~/.emacs.d/mu4e/")
(require 'mu4e)
(setq mu4e-update-interval (* 60 10)
mu4e-mu-binary "/usr/local/bin/mu" ; or /usr/bin/true
mu4e-get-mail-command "/usr/local/bin/offlineimap -o" ; or /usr/bin/true
message-kill-buffer-on-exit t)
#+end_example
Here a sample configuration for SMTP
#+begin_example emacs-lisp
(setq message-send-mail-function 'smtpmail-send-it
smtpmail-stream-type 'starttls
smtpmail-smtp-server "smtp.example.com"
smtpmail-smtp-service 465
smtpmail-stream-type 'ssl)
#+end_example
(setq mu4e-contexts
(list
(make-mu4e-context
:name "Work"
:match-func
(lambda (msg)
(when msg
(string-prefix-p "/Work" (mu4e-message-field msg :maildir))))
:vars '((user-mail-address . "my@work.com")
(user-full-name . "Work Gmail box")
(mu4e-drafts-folder . "/Gmail/[Gmail]/Drafts")
(mu4e-sent-folder . "/Gmail/[Gmail]/Sent Mail")
(mu4e-refile-folder . "/Gmail/[Gmail]/All Mail")
(mu4e-trash-folder . "/Gmail/[Gmail]/Trash")))
(make-mu4e-context
:name "Personal"
:match-func
(lambda (msg)
(when msg
(string-prefix-p "/Personal" (mu4e-message-field msg :maildir))))
:vars '((user-mail-address . "personal@example.com")
(user-full-name . "Personal Gmail box")
(mu4e-drafts-folder . "/Gmail/[Gmail]/Drafts")
(mu4e-sent-folder . "/Gmail/[Gmail]/Sent Mail")
(mu4e-refile-folder . "/Gmail/[Gmail]/All Mail")
(mu4e-trash-folder . "/Gmail/[Gmail]/Trash")))))
(server-mode)
(iconify-frame)
(set-frame-parameter nil 'fullscreen 'fullboth)
(minemacs-package! exwm
:config
(require 'exwm)
(require 'exwm-config)
(exwm-config-example))
(minemacs-package! elfeed)
(minemacs-package! bongo
:hook
(dired-mode . (lambda () (define-key dired-mode-map (kbd "b") 'bongo-dired-append-enqueue-lines))))
(minemacs-package! elpher)
(minemacs-package! golden-ratio)
(minemacs-package! yasnippet
:config
(yas-global-mode))
(minemacs-package! yasnippet-snippets
:after yasnippet)
(minemacs-package! magit
:config
(add-to-list 'project-switch-commands '(magit-status "Git" "m"))
(transient-append-suffix 'magit-rebase "-d" '("-D" "Ingore date" "--ignore-date"))
(transient-append-suffix 'magit-rebase "-r" '("-A" "Set Author" "--author")))
(minemacs-package! forge
:after magit)
(minemacs-package! lsp-mode)
(minemacs-package! yaml-mode
:custom
(yaml-imenu-generic-expression "^\\(:?[a-zA-Z_-]+\\):" 1))
(minemacs-package! csv-mode)
(minemacs-package! web-mode
:custom
(web-mode-code-indent-offset 2)
(web-mode-css-indent-offset 2)
(web-mode-markup-indent-offset 2)
:config
(add-to-list 'auto-mode-alist '("\\.phtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.tpl\\.php\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.[agj]sp\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.as[cp]x\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.erb" . web-mode))
(add-to-list 'auto-mode-alist '("\\.mustache\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.djhtml\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.rest\\'" . restclient-mode)))
(minemacs-package! emmet-mode
:after web-mode
:hook
(sgml-mode . emmet-mode)
(html-mode . emmet-mode)
(web-mode . emmet-mode)
(css-mode . emmet-mode))
(minemacs-package! ruby-mode)
(minemacs-package! bundler)
(minemacs-package! rspec-mode
:config
(add-hook 'after-init-hook 'inf-ruby-switch-setup)
(add-hook 'compilation-filter-hook #'inf-ruby-auto-enter)
(eval-after-load 'rspec-mode '(rspec-install-snippets))
(setq comint-scroll-to-bottom-on-output t))
(minemacs-package! rinari
:config
(defalias 'rake 'rinari-rake))
(minemacs-package! alchemist)
(minemacs-package! exunit)
(minemacs-package! docker)
(load custom-file 'noerrors)
Press "C-h o" (=describe-symbol=) on it to get more informations.
add-file-local-variable-prop-line
browse-url-handlers
comint-scroll-to-bottom-on-output
completion-at-point (C-M-i or M-TAB)
completion-auto-select
dired-listing-switches
dired-switches-in-mode-line
find-name-dired
indent-tabs-mode
initial-buffer-choice
kmacro-to-register
org-startup-folded
proced (get UNIX processes list)
run-at-time / list-timers
shr-inhibit-images
completion-auto-help
completion-auto-select
org-date-from-calendar
I would like to thanks:
- [[http://kelvinh.github.io/][Kelvin Hu]] for his [[https://github.com/kelvinh/.emacs.d][emacs configuration]] and the idea to write it in a *literate style*.
- [[http://www.howardism.org/][Howard Abrams]] for his [[https://github.com/howardabrams/dot-files][dotfiles]].
- [[https://github.com/aaronbieber][Aaron Bieber]] for his dotfiles and for the wonderful speech [[https://www.youtube.com/watch?v%3DJWD1Fpdd4Pc][Evil Mode: Or, How I Learned to Stop Worrying and Love Emacs]] that makes me *fall in love* with Emacs. ;-)
- [[https://protesilaos.com/][Protesilaos Stavrou]] for his [[https://protesilaos.com/dotemacs/][comprehensive "dotemacs" (.emacs) for GNU/Linux]] and [[https://protesilaos.com/codelog/][the huge amount of posts and videos about Emacs]].
- [[https://github.com/sponsors/daviwil][David Wilson]] for his fantastic [[https://www.youtube.com/channel/UCAiiOTio8Yu69c3XnR7nQBQ][System Crafters screencasts]]!
- [[http://staff.science.uva.nl/~dominik/][Carsten Dominik]], creator of the mighty [[http://orgmode.org][org-mode]]. <<org-mode>>
- [[http://ehneilsen.net][Eric H. Neilsen, Jr.]] for his wonderful [[http://ehneilsen.net/notebook/orgExamples/org-examples.html][org-mode examples and cookbook]].
- [[https://www.gnu.org/software/emacs/][The Emacs editor]] and his *guru* [[https://stallman.org/][Richard Stallman]].
- [[https://www.gnu.org/software/emacs/manual/pdf/emacs-lisp.pdf][The Elisp documentation]]