Try package-refresh-contents
as a quickfix when a package is not found.
(setq install-list '(
bibtex-completion
ace-window
dirtree
neotree
pdf-tools
popup
yasnippet
ivy
ivy-bibtex
org
ox-twbs
org-bullets
org-ref
ob-async
org-contrib ;; non gnu
gnuplot
gnuplot-mode
material-theme
markdown-mode
magit
flycheck
sly
all-the-icons
all-the-icons-ibuffer
projectile
ibuffer-projectile
ibuffer-sidebar
load-relative
elpy
rainbow-delimiters
cmake-ide
yaml-mode
visual-fill-column
use-package
dockerfile-mode
sr-speedbar
latex-math-preview
vue-mode
js2-mode
json-mode
json-reformat
all-the-icons-dired
highlight-symbol
origami
paredit
clojure-mode
clojure-mode-extra-font-locking
cider
ido-completing-read+
tagedit
vundo
csharp-mode
))
(setq require-list '(
bibtex
dirtree
neotree
pdf-tools
popup
yasnippet
org-ref
org-ref-ivy
company
flycheck
eldoc
all-the-icons
all-the-icons-ibuffer
projectile
ibuffer-projectile
ibuffer-sidebar
load-relative
elpy
cc-mode
yaml-mode
visual-fill-column
use-package
dockerfile-mode
sr-speedbar
json-mode
json-reformat
highlight-symbol
origami
))
(setq package-archives '(("nongnu" . "https://elpa.nongnu.org/nongnu/")
("gnu" . "https://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/")))
(setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
(require 'package)
(package-initialize)
(unless package-archive-contents
(package-refresh-contents))
(setq inhibit-splash-screen t)
(tool-bar-mode -1)
(toggle-scroll-bar -1)
Set with alpha
(“This parameter specifies the opacity of the frame,
on graphical displays that support variable opacity. It should be an
integer between 0 and 100, where 0 means completely transparent and
100 means completely opaque. It can also have a nil value, which tells
Emacs not to set the frame opacity (leaving it to the window
manager).” Font and Color Parameters)
(set-frame-parameter (selected-frame) 'alpha '(98 . 94))
(add-to-list 'default-frame-alist '(alpha . (98 . 85)))
(add-to-list 'initial-frame-alist '(fullscreen . maximized))
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(dolist (package install-list)
(unless (package-installed-p package)
(package-install package)))
(dolist (package require-list)
(require package))
;; turn off #?!&/!!-bell
(setq ring-bell-function 'ignore)
;; show row AND col in the status line
(setq column-number-mode t)
;; always auto-revert
(global-auto-revert-mode 1)
(tool-bar-mode -1)
(yas-global-mode 1)
(electric-pair-mode 1)
(global-flycheck-mode 1)
(show-paren-mode 1)
(global-set-key (kbd "M-n") 'switch-to-buffer)
(global-set-key (kbd "C-c p p") 'projectile-switch-project)
(global-set-key (kbd "C-c i") 'ibuffer)
Latex related
(global-set-key (kbd "M-p") 'latex-math-preview-expression)
Recentf bind to openfiles
(global-set-key (kbd "C-c o") 'recentf-open-files)
Convenience keybindings
(global-set-key (kbd "C-c C-l") 'eww-follow-link)
(defun variable-set-p (variable)
"Throw an error if VARIABLE is not defined."
(when (not (boundp variable))
(error (format "The variable '%s' is not defined. Set it in your 'init.el' or '.emacs' config file." variable))))
(variable-set-p 'my/omnisharp-server-location)
(variable-set-p 'my/plantuml-jar-path)
(variable-set-p '*bib-files*)
(use-package eglot
:ensure t
:config
(let ((omnisharp-server my/omnisharp-server-location))
(if (file-exists-p omnisharp-server)
(progn
(add-to-list 'eglot-server-programs
`(csharp-mode . (,omnisharp-server "-lsp" "-stdio")))
(setq eglot-connect-timeout 3000))
(error "Omnisharp file not found!"))))
(use-package corfu
:ensure t
;; Optional customizations
:custom
(corfu-cycle t) ;; Enable cycling for `corfu-next/previous'
(corfu-auto t) ;; Enable auto completion
(corfu-auto-prefix 2)
:init
(global-corfu-mode)
(corfu-history-mode))
(use-package corfu-terminal
:ensure t)
(use-package vertico
:ensure t
:init
(vertico-mode)
;; Different scroll margin
(setq vertico-scroll-margin 0)
;; Show more candidates
(setq vertico-count 20)
;; Grow and shrink the Vertico minibuffer
(setq vertico-resize t)
;; Optionally enable cycling for `vertico-next' and `vertico-previous'.
(setq vertico-cycle t))
(use-package vertico-posframe
:after vertico
:ensure t
:config
(vertico-posframe-mode 1))
(use-package marginalia
:ensure t
:init
(marginalia-mode 1))
(use-package orderless
:ensure t
:init
(setq completion-styles '(orderless basic)
completion-category-defaults nil
completion-category-overrides '((file (styles . (partial-completion))))))
(add-hook 'ibuffer-hook
(lambda ()
(ibuffer-projectile-set-filter-groups)
(unless (eq ibuffer-sorting-mode 'alphabetic)
(ibuffer-do-sort-by-alphabetic))))
(unless (find-font (font-spec :name "all-the-icons"))
(all-the-icons-install-fonts t))
(setq all-the-icons-scale-factor 1)
(all-the-icons-ibuffer-mode 1)
(use-package flycheck
:ensure t)
(add-hook 'dired-mode-hook
(lambda ()
(dired-hide-details-mode)))
(add-hook 'dired-mode-hook 'all-the-icons-dired-mode)
Configuration copied from jkitchin/org-ref. Append bib files to the bib-files list.
;; Add bib-files to the bibtex-completion list if they can be found
(dolist (file *bib-files*)
(if (and (file-exists-p file) (not (member file bibtex-completion-bibliography)))
(push file bibtex-completion-bibliography)))
;; enable org-ref functions and keybindings when there is at least one bib-file present
(defun my/bibtex-completion-setting ()
"Call this whenever `bibtex-completion-bibliography' was set to a value."
(if bibtex-completion-bibliography
(progn
(setq org-ref-insert-link-function 'org-ref-insert-link-hydra/body
org-ref-insert-cite-function 'org-ref-cite-insert-ivy
org-ref-insert-label-function 'org-ref-insert-label-link
org-ref-insert-ref-function 'org-ref-insert-ref-link
org-ref-cite-onclick-function (lambda (_) (org-ref-citation-hydra/body)))
(define-key org-mode-map (kbd "C-c ]") 'org-ref-insert-link)
(define-key org-mode-map (kbd "s-[") 'org-ref-insert-link-hydra/body))))
(setq org-babel-lisp-eval-fn 'sly-eval)
At some point this junk of stuff should be sparated into source blocks…
;; loaddefs
;; not sure why this was there in there
;; (require 'org-loaddefs)
(defun my/org-init ()
"Only require the packages related to 'org-mode' when using org."
(let ((org-requirements '(org-bullets org-contrib ox ox-publish ox-latex
ox-beamer ox-twbs ox-extra ob-async)))
(dolist (req org-requirements)
(require req))))
(defun my/org-visual-column-linum ()
"Appearance configurations for 'org-mode'."
(progn
(setq-default visual-fill-column-width 120)
(setq-default visual-fill-column-center-text t)
(setq org-list-allow-alphabetical t)
(visual-fill-column-mode)
(visual-line-mode)
(display-line-numbers-mode -1)))
(defun my/org-settings ()
"Consider this for more uncategorized settings like the src-window."
(setq org-src-window-setup "current-window"))
(defun my/org-publishing ()
"Publishing specific settings."
(setq org-publish-project-alist
'(("org-notes"
:base-directory "~/org/"
:base-extension "org"
:publishing-directory "~/public_html/"
:recursive t
:publishing-function org-twbs-publish-to-html
:with-sub-superscript nil
:headline-levels 4
:auto-preamble t
)
("org-static"
:base-directory "~/org/"
:base-extension "css\\|js\\|png\\|jpg\\|gif\\|pdf\\|mp3\\|ogg\\|swf"
:publishing-directory "~/public_html/"
:recursive t
:publishing-function org-publish-attachment
)
("org" :components ("org-notes" "org-static")))))
(defun my/org-babel-lang ()
"Which languages shall be loaded into babel."
(org-babel-do-load-languages
'org-babel-load-languages
'((latex . t)
(gnuplot . t)
(python . t)
(C . t)
(lisp . t))))
(defun my/eval-w/o-confirmation ()
"Languages in the list don't require confirmation to be executed."
(let ((confirmed-babel-langs (lambda (lang body)
(not (or
(string= lang "emacs-lisp")
(string= lang "latex")
(string= lang "elisp")
(string= lang "lisp")
(string= lang "gnuplot")
(string= lang "python")
(string= lang "dot")
(string= lang "C++"))))))
(setq org-confirm-babel-evaluate confirmed-babel-langs)))
(use-package org
:init (my/org-init)
:mode (("\\.org$" . org-mode))
:ensure
:hook
(org-mode . org-bullets-mode)
(org-mode . my/org-visual-column-linum)
(org-mode . my/org-publishing)
(org-mode . my/org-babel-lang)
(org-mode . my/eval-w/o-confirmation)
(org-mode . my/org-settings)
(org-mode . my/bibtex-completion-setting))
Some global settings that cannot be added to org-mode
as a hook.
;; agenda toggle mode
(global-set-key (kbd "C-c a") 'org-agenda)
(global-set-key (kbd "C-c l") 'org-store-link)
;; global agenda to-do file
(setq org-agenda-files (quote ("~/todo.org")))
;; global target file for notes
(setq org-default-notes-file (concat org-directory "~/notes.org"))
;;set priority range from A to C with default A
(setq org-highest-priority ?A)
(setq org-lowest-priority ?C)
(setq org-default-priority ?A)
;; set priority color
(setq org-priority-faces '((?A . (:foreground "FF6670" :weight bold))
(?B . (:foreground "F8FF42"))
(?C . (:foreground "60FFFF"))))
(define-key global-map (kbd "C-c c") 'org-capture)
(setq org-capture-templates
'(("t" "Todo" entry (file+headline "~/todo.org" "Tasks")
"* TODO %?\n %i\n %a")))
(setq org-latex-pdf-process (list "latexmk -shell-escape -bibtex -f -pdf %f"))
(org-reload)
Add additional html-export that embeds images into the generated html. Mostly copied from https://niklasfasching.de/posts/org-html-export-inline-images/
(defun org-html-export-to-mhtml (async subtree visible body)
(cl-letf (((symbol-function 'org-html--format-image) 'format-image-inline))
(org-html-export-to-html nil subtree visible body)))
(defun format-image-inline (source attributes info)
(let* ((ext (file-name-extension source))
(prefix (if (string= "svg" ext) "data:image/svg+xml;base64," "data:;base64,"))
(data (with-temp-buffer (url-insert-file-contents source) (buffer-string)))
(data-url (concat prefix (base64-encode-string data)))
(attributes (org-combine-plists `(:src ,data-url) attributes)))
(org-html-close-tag "img" (org-html--make-attribute-string attributes) info)))
(org-export-define-derived-backend 'html-inline-images 'html
:menu-entry '(?h "Export to HTML" ((?m "As MHTML file" org-html-export-to-mhtml))))
(org-export-define-derived-backend 'html-inline-imgaes 'html
:menu-entry '(?h "Export to HTML" ((?M "As MHTML file and open"
(lambda (a s v b)
(if a (org-html-export-to-mhtml t s v b)
(org-open-file (org-html-export-to-mhtml nil s v b))))))))
(when (executable-find "hunspell")
(setq ispell-program-name "hunspell"))
On windows ~MSYS~ is the easiest way to get gcc
which is needed to compile the database for org-roam.
This configuration makes use of an environment variable pointing to the root directory of org-roam, called ORGROAM
. Make sure to export this pointing to whatever directory should be used for it. If not using org-roam, setting ensure
to nil
in the following use-package sexp should do the trick.
(defun my/get-org-roam-dir ()
(let ((dir (getenv "ORGROAM")))
(if (eq nil dir)
(error "No environment variable 'ORGROAM' was found. Set one and start again.")
(expand-file-name dir))))
(use-package org-roam
:ensure t
:custom
(org-roam-directory (file-truename (my/get-org-roam-dir)))
:bind (("C-c n l" . org-roam-buffer-toggle)
("C-c n f" . org-roam-node-find)
("C-c n g" . org-roam-graph)
("C-c n i" . org-roam-node-insert)
("C-c n c" . org-roam-capture))
:config
(org-roam-db-autosync-mode)
(setq org-roam-database-connector 'emacsql-sqlite))
;; Do not call this outside of the `org-roam-bibtex' use-package section as it depends on this package.
;; From the doc of `orb-open-attached-file': CITEKEY must be a list for compatibility with `bibtex-completion'
(defun my/orb-open-attached-file-wrapper ()
"Only works in org-roam files wiht a 'ROAM_REFS' section containig a citekey that `orb-get-node-citekey' can grab.
If there is no file attached, do so with `orb-note-actions'."
(interactive)
(orb-open-attached-file (list (orb-get-node-citekey))))
(use-package org-roam-bibtex
:ensure t
:after org-roam
:bind (("C-c b a" . orb-note-actions)
("C-c b i" . orb-insert-link)
("C-c b o" . my/orb-open-attached-file-wrapper))
:config
(require 'org-ref))
For this configuration it makes sense to set the directory of org-ql (org-directory
) to the default org-roam directory (org-roam-directory
) as this is the standard query directory. Consequently, it should only be initialized after org-roam.
(use-package org-ql
:after org-roam
:ensure t
:custom
(org-directory (file-truename (my/get-org-roam-dir))))
;; require latex snippets in org mode
(defun my-org-latex-yas ()
"Activate org and LaTeX yas expansion in org-mode buffers."
(yas-minor-mode)
(yas-activate-extra-mode 'latex-mode))
(add-hook 'org-mode-hook #'my-org-latex-yas)
global mode
(yas-global-mode 1)
(global-set-key (kbd "M-o") 'ace-window)
(global-set-key (kbd "s-j") 'windmove-left)
(global-set-key (kbd "s-;") 'windmove-right)
(use-package sr-speedbar
:ensure t
:init
(lambda ()
(display-line-numbers-mode -1)))
(setq projectile-indexing-method 'hybrid)
(projectile-global-mode)
See NeoTree Docs Use icons for file and let the widht be altered.
(setq neo-theme 'icons)
(setq neo-window-fixed-size nil)
Jump to the current file node when neotree is opened.
(setq neo-smart-open t)
Change neotree when switching projectile project (projectile-switch-project
)
;; (setq projectile-switch-project-action 'neotree-projectile-action)
(add-hook 'lisp-mode-hook '(lambda ()
(rainbow-delimiters-mode)
(prettify-symbols-mode)
(display-line-numbers-mode)))
(add-hook 'emacs-lisp-mode-hook #'rainbow-delimiters-mode)
From https://www.youtube.com/watch?v=51eSeqcaikM History of recent files
(recentf-mode 1)
Minibuffer history
(setq history-length 10)
(savehist-mode 1)
Jump back to where the cursor was before closing a file or emacs. Adds lag when opening a file.
(save-place-mode 1)
(global-set-key [(control f3)] 'highlight-symbol)
(global-set-key [f3] 'highlight-symbol-next)
(global-set-key [(shift f3)] 'highlight-symbol-prev)
(global-set-key [(meta f3)] 'highlight-symbol-query-replace)
Show/hide text regions.
(define-key origami-mode-map (kbd "C-c C-z") 'origami-recursively-toggle-node)
(defun my/org-present-mode-hook ()
"Setup org-present-mode."
(org-display-inline-images))
(defun my/org-present-mode-hook-quit ()
"Revert settings from my/org-present-mode-hook when leaving org-present-mode."
(org-remove-inline-images))
(use-package org-present
:ensure t
:hook ((org-present-mode . my/org-present-mode-hook)
(org-present-mode-quit . my/org-present-mode-hook-quit)))
(use-package plantuml-mode
:ensure t
:config
(when (file-exists-p my/plantuml-jar-path)
(setq plantuml-jar-path my/plantuml-jar-path))
(setq plantuml-default-exec-mode 'jar)
(add-to-list 'auto-mode-alist '("\\.puml\\'" . plantuml-mode)))
(use-package elfeed
:ensure t
:config
(setq url-queue-timeout 30)
(setq elfeed-feeds
'(("https://www.scientificamerican.com/platform/syndication/rss/" scientificamerican)
;; ("https://www.nature.com/nature.rss" nature)
("https://www.nature.com/natcomputsci.rss" naturecomputation)
("https://www.nature.com/nphys.rss" naturephysics)
("https://www.nature.com/nphoton.rss" naturephoton)
("https://www.nature.com/nnano.rss" naturenano)
("https://onlinelibrary.wiley.com/feed/13652818/most-recent" microscopyjournal)
("https://herbsutter.com/feed/" herbsutter)
("https://sachachua.com/blog/category/emacs/feed/" emacsnews))))
(define-key c-mode-base-map (kbd "<f5>") 'compile)
(define-key c-mode-base-map (kbd "<f6>") 'recompile)
(add-hook 'c-mode-hook 'origami-mode)
(add-hook 'c++-mode-hook 'origami-mode)
(add-hook 'c++-mode-hook 'display-line-numbers-mode)
Check if the inferior-lisp-program
variable is set. If not, try to default it to sbcl
(when (not (boundp 'inferior-lisp-program))
(let ((sbcl (executable-find "sbcl")))
(if sbcl
(setq inferior-lisp-program sbcl)
(error "No lisp compiler identified. Try install sbcl and check if it is in PATH."))))
(add-hook 'TeX-after-TeX-LaTeX-command-finished-hook
#'TeX-revert-document-buffer)
(add-to-list 'org-latex-classes
'("beamer"
"\\documentclass\[presentation\]\{beamer\}"
("\\section\{%s\}" . "\\section*\{%s\}")
("\\subsection\{%s\}" . "\\subsection*\{%s\}")
("\\subsubsection\{%s\}" . "\\subsubsection*\{%s\}")))
;; for export purposes
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
Remove the headline while exporting the content in the respective subtree using the ignore tag.
(ox-extras-activate '(ignore-headlines))
(add-hook 'pdf-view-mode-hook '(lambda () (pdf-tools-enable-minor-modes)))
(add-to-list 'auto-mode-alist '("\\.pdf\\'" . pdf-view-mode))
See https://melpa.org/#/yaml-mode
(add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode))
(elpy-enable)
(add-to-list 'process-coding-system-alist '("python" . (utf-8 . utf-8)))
(setq elpy-rpc-python-command "python3")
(add-hook 'python-mode-hook 'origami-mode)
From:
(use-package markdown-mode
:ensure t
:commands (markdown-mode gfm-mode)
:mode (("README\\.md\\'" . gfm-mode)
("\\.md\\'" . markdown-mode)
("\\.markdown\\'" . markdown-mode))
:init (setq markdown-command "multimarkdown"))
(add-to-list 'auto-mode-alist '("Dockerfile\\'" . dockerfile-mode))
See documentation on lsp-mode-website
With vue-mode
and lsp-mode
installed.
Needs a lsp-backend (e.g. M-x lsp-install-server ts-ls
for JavaScript and TypeScript).
(use-package lsp-mode
:commands lsp)
(use-package vue-mode
:mode "\\.vue\\'"
:hook (vue-mode . lsp-deferred))
(setq js-indent-level 2)
Same as *vue -> needs lsp-mode
(use-package js2-mode
:mode "\\.js\\'"
:hook (js2-mode . lsp-deferred))
Attention when using interactive: the first character in the string for the interactive function determines the type of the value assigned to the argument provided. Multiple arguments in the top-level function must be seperated by “\n” characters.
(defun revert (l)
"reverts a list"
(cond
((null l) '())
(t (append (revert (cdr l)) (list (car l))))))
(defun time-to-list (s)
"generates a list of numbers from :-separetd time string"
(mapcar 'string-to-number (split-string s ":")))
(defun multiply-lists (l mult acc)
"multiplies each element of the lists and returns the sum of multiplied tuples"
(cond
((null l) acc)
(t (multiply-lists (cdr l) (cdr mult) (+ acc (* (car l) (car mult)))))))
(defun make-seconds (s)
"computes seconds form dd:hh:mm:ss time string"
(multiply-lists (revert (time-to-list s)) '(1 60 3600 86400) 0))
(defun seconds-to-time-precise (s)
"generate time in hh:mm:ss format from seconds"
(let ((hr (mod s 3600)))
(let ((mr (mod hr 60)))
(concat
(number-to-string (/ (- s hr) 3600))
":"
(number-to-string (/ (- hr mr) 60))
":"
(number-to-string mr)))))
(defun minutes-to-time (s)
"comma-separated minute-value to time mm:ss"
(let ((f (floor s)))
(concat
(number-to-string f)
":"
(number-to-string (round (* (- s f) 60))))))
(defun psi-to-kgcm2 (psi)
"pressure in psi to kg/cm²"
(* 0.070307 psi))
(defun psi-to-gcm2 (psi)
"pressure in psi to g/cm²"
(* (psi-to-kgcm2 psi) 1000))
(defun rpm-to-ms (r rpm)
"get speed in m/s from disk radius and rpm"
(let ((u (* 2 pi r))
(rps (/ rpm 60.0)))
(* u rps)))
(defun ms-to-rpm (r ms)
"get rpm from disk radius and speed in m/s"
(let ((u (* 2 pi r)))
(let ((rps (/ ms u)))
(* rps 60.0))))
(defun round-to (n d)
"round the number n to d specified decimals"
(/ (fround (* (expt 10 d) n)) (expt 10 d)))
(defun make-link (l)
(cond
((< (length l) 3) (get-link l))
((not (equal (substring l 0 3) "[[*")) (get-link l))
(t l)))
(defun make-link-append-front (a l)
(let ((to-link (concat a " " l)))
(cond
((< (length l) 3)
(get-link to-link))
((not (equal (substring l 0 3) "[[*"))
(get-link to-link))
(t l))))
(defun get-link (l)
(concat "[[*" l "][" l "]]"))
(defun a-to-nm (a)
"convert Å to nm"
(/ a 10.0))
(defun nm-to-a (nm)
"convert nm to Å"
(* nm 10.0))
(defun inline-src-elisp (ex re)
"With arguments EX for :exports and RE for :results generate base for src_elisp."
(interactive "s:exports:\ns:results:")
(let ((insertion (concat "src_elisp[:exports "
ex
" :results "
re
"]{}")))
(insert insertion))
(backward-char))
(fset 'to-num 'string-to-number)
(global-set-key (kbd "M-s M-e") 'inline-src-elisp)
(setq org-todo-keywords
'((sequence "TODO" "IN-PROGRESS" "WAITING" "DONE")))