From 899e74af8eac4f490e8db6b31c376f49710a97bf Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 8 Feb 2023 19:00:29 +0200 Subject: emacs: Add todo's --- .emacs.d/emacs.org | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to '.emacs.d') diff --git a/.emacs.d/emacs.org b/.emacs.d/emacs.org index 319f9ea..db546cd 100644 --- a/.emacs.d/emacs.org +++ b/.emacs.d/emacs.org @@ -1,10 +1,9 @@ #+TITLE: Emacs Configuration #+PROPERTY: header-args :tangle test.el #+auto_tangle: t +#+STARTUP: show2levels -* TODO Setting up -Packages - +* TODO Setting up Packages #+begin_src emacs-lisp (require 'package) ;; recheck | Add custon snippets to my path @@ -18,9 +17,9 @@ Packages (setq custom-file (concat user-emacs-directory "/custom.el")) #+end_src ** Setup for GuixSD machines -We check ~$HOSTNAME~ if it's one of my devices running GuixSD, if ~t~ -we use ~guix-emacs-autoload-packages~ to load emacs packages installed using guix -/If you are running guix, change the following hostnames ~fsociety~ or ~heisenberg~ to your own/ +We check the ~$HOSTNAME~, if it's one of my devices running GuixSD. +we use ~guix-emacs-autoload-packages~ to load emacs packages installed using guix if ~t~ ++ If you are running GuixSD, replace the following hostnames ~fsociety~ or ~heisenberg~ with your own ~$HOSTNAME~ #+begin_src emacs-lisp (when (or (string= (system-name) "fsociety") (string= (system-name) "heisenberg")) @@ -112,10 +111,10 @@ Install missing packages (package-install 'use-package)) #+end_src -* TODO Function -* TODO email-module -* TODO keys.el -* TODO all-the-icons-dired.el -* TODO org-config -* UI Settings -** Basic UI +* TODO UI Settings +** TODO Basic UI +** TODO all-the-icons-dired.el +* TODO Functions +* TODO mu4e setup | Email configuration +* TODO Custom key-bindings +* TODO Org-mode Configuration -- cgit v1.2.3 From 9f9afbbbf6601db67e6ca594e15866598a128199 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Wed, 8 Feb 2023 19:07:14 +0200 Subject: emacs: test toc --- .emacs.d/emacs.org | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to '.emacs.d') diff --git a/.emacs.d/emacs.org b/.emacs.d/emacs.org index db546cd..b202a7b 100644 --- a/.emacs.d/emacs.org +++ b/.emacs.d/emacs.org @@ -1,7 +1,26 @@ #+TITLE: Emacs Configuration #+PROPERTY: header-args :tangle test.el #+auto_tangle: t -#+STARTUP: show2levels +#+STARTUP: show2levels + +* Table of contents +:PROPERTIES: +:TOC: :include all +:END: +:CONTENTS: +- [[#table-of-contents][Table of contents]] +- [[#setting-up-packages][Setting up Packages]] + - [[#setup-for-guixsd-machines][Setup for GuixSD machines]] + - [[#define-and-install-packages][Define and install packages]] +- [[#ui-settings][UI Settings]] + - [[#basic-ui][Basic UI]] + - [[#all-the-icons-diredel][all-the-icons-dired.el]] +- [[#functions][Functions]] +- [[#mu4e-setup--email-configuration][mu4e setup | Email configuration]] +- [[#custom-key-bindings][Custom key-bindings]] +- [[#org-mode-configuration][Org-mode Configuration]] +:END: + * TODO Setting up Packages #+begin_src emacs-lisp @@ -118,3 +137,4 @@ Install missing packages * TODO mu4e setup | Email configuration * TODO Custom key-bindings * TODO Org-mode Configuration + -- cgit v1.2.3 From 87cd7bb8a4e70100a2a29cf6460696142166c356 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Thu, 9 Feb 2023 03:29:02 +0200 Subject: emacs: Add mu4e, basic UI, org config --- .emacs.d/emacs.org | 1006 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 964 insertions(+), 42 deletions(-) (limited to '.emacs.d') diff --git a/.emacs.d/emacs.org b/.emacs.d/emacs.org index b202a7b..7a3a7c5 100644 --- a/.emacs.d/emacs.org +++ b/.emacs.d/emacs.org @@ -1,7 +1,7 @@ #+TITLE: Emacs Configuration #+PROPERTY: header-args :tangle test.el #+auto_tangle: t -#+STARTUP: show2levels +#+OPTIONS: num:nil toc:nil * Table of contents :PROPERTIES: @@ -12,29 +12,56 @@ - [[#setting-up-packages][Setting up Packages]] - [[#setup-for-guixsd-machines][Setup for GuixSD machines]] - [[#define-and-install-packages][Define and install packages]] + - [[#list-of-required-packages][List of required packages]] + - [[#installation--activation][Installation & activation]] - [[#ui-settings][UI Settings]] - [[#basic-ui][Basic UI]] - - [[#all-the-icons-diredel][all-the-icons-dired.el]] + - [[#dashboard][Dashboard]] + - [[#theme--modeline][Theme & modeline]] + - [[#ivy][Ivy]] + - [[#helpful][Helpful]] +- [[#dired][Dired]] + - [[#keys][Keys]] + - [[#all-the-iconsel][All-the-icons.el]] +- [[#terminals][Terminals]] + - [[#vterm][Vterm]] + - [[#eshell][Eshell]] +- [[#key-bindings][Key-bindings]] - [[#functions][Functions]] -- [[#mu4e-setup--email-configuration][mu4e setup | Email configuration]] +- [[#mu4e--email-configuration][mu4e | Email Configuration]] + - [[#macos][MacOS]] + - [[#settings--context-setup][Settings & Context setup]] + - [[#shortcuts][Shortcuts]] + - [[#contexts][Contexts]] - [[#custom-key-bindings][Custom key-bindings]] - [[#org-mode-configuration][Org-mode Configuration]] + - [[#org-make-toc][org-make-toc]] + - [[#themes][Themes]] + - [[#dracula][Dracula]] + - [[#darkone][Darkone]] + - [[#settings][Settings]] + - [[#babel][Babel]] +- [[#markdown][Markdown]] + - [[#theme][Theme]] + - [[#settings][Settings]] +- [[#programming][Programming]] + - [[#essentials][Essentials]] + - [[#magit][Magit]] + - [[#emacs-lisp][Emacs lisp]] + - [[#lsp-mode][LSP-Mode]] + - [[#python][Python]] + - [[#json][JSON]] + - [[#javascript][Javascript]] +- [[#elfeed][Elfeed]] +- [[#pdf][PDF]] +- [[#telega][Telega]] +- [[#custom][Custom]] + - [[#chatgpt][ChatGPT]] + - [[#random-functions][Random functions]] +- [[#exwm][EXWM]] :END: - * TODO Setting up Packages -#+begin_src emacs-lisp - (require 'package) - ;; recheck | Add custon snippets to my path - (add-to-list 'load-path "~/dotfiles/.emacs.d/snippets") - - ;; Add the entire dotfiles folder in path, - ;; in case we need to load from .exwm.el - (add-to-list 'load-path "~/dotfiles") - - ;; Set custom.el in a different file, in user-emacs-directory - (setq custom-file (concat user-emacs-directory "/custom.el")) -#+end_src ** Setup for GuixSD machines We check the ~$HOSTNAME~, if it's one of my devices running GuixSD. we use ~guix-emacs-autoload-packages~ to load emacs packages installed using guix if ~t~ @@ -46,23 +73,13 @@ we use ~guix-emacs-autoload-packages~ to load emacs packages installed using gui (guix-emacs-autoload-packages)) #+end_src ** Define and install packages -First, we set our ~package-archives~ -#+begin_src emacs-lisp -(setq package-archives '(("melpa" . "https://melpa.org/packages/") - ("org" . "https://orgmode.org/elpa/") - ("elpa" . "https://elpa.gnu.org/packages/"))) -#+end_src -Load our emacs packages and activate them -#+begin_src emacs-lisp -(package-initialize) -(unless package-archive-contents - (package-refresh-contents)) -#+end_src - -Now we list our packages in ~my-package-list~ +*** List of required packages +Request the following packages: #+begin_src emacs-lisp (defconst my-package-list '(org-snooze all-the-icons + all-the-icons-dired + all-the-icons-ivy-rich general doom-themes doom-modeline @@ -70,7 +87,6 @@ Now we list our packages in ~my-package-list~ which-key ivy ivy-rich - all-the-icons-ivy-rich helpful org org-modern @@ -103,16 +119,24 @@ Now we list our packages in ~my-package-list~ eshell-syntax-highlighting pdf-tools org-superstar - mastodon)) + mastodon + dashboard + org-auto-tangle)) #+end_src -Now we define a list to be populated at each startup. -/Contains the list of packages that need to be installed/ +*** Installation & activation +Set our ~package-archives~, and install our packages #+begin_src emacs-lisp +(setq package-archives '(("melpa" . "https://melpa.org/packages/") + ("org" . "https://orgmode.org/elpa/") + ("elpa" . "https://elpa.gnu.org/packages/"))) +(package-initialize) +(unless package-archive-contents + (package-refresh-contents)) + (defvar my-missing-packages '() -#+end_src + "List populated at each startup. +Contains the list of packages that need to be installed.") -Install missing packages -#+begin_src emacs-lisp (dolist (p my-package-list) (when (not (package-installed-p p)) (add-to-list 'my-missing-packages p))) @@ -127,14 +151,912 @@ Install missing packages (setq my-missing-packages '())) (unless (package-installed-p 'use-package) -(package-install 'use-package)) +(package-install 'use-package)) #+end_src * TODO UI Settings -** TODO Basic UI -** TODO all-the-icons-dired.el +** Basic UI +Fonts and basic appearance settings +#+begin_src emacs-lisp +(setq inhibit-startup-message nil) +;; Transparency +(set-frame-parameter (selected-frame) 'alpha '(90 90)) +(add-to-list 'default-frame-alist '(alpha 90 90)) + +(add-hook 'dired-mode-hook 'all-the-icons-dired-mode) + +(scroll-bar-mode -1) +(tool-bar-mode -1) +(tooltip-mode -1) +(set-fringe-mode 10) +(menu-bar-mode -1) +(blink-cursor-mode -1) +(menu-bar--visual-line-mode-enable) + +(setq visible-bell t) + +(column-number-mode) +(global-display-line-numbers-mode 0) +(menu-bar--display-line-numbers-mode-relative) +;;Disable line numbers for some modes +(dolist (mode '(pdf-view-mode-hook + org-mode-hook + term-mode-hook + shell-mode-hook + eshell-mode-hook + vterm-mode-hook + elfeed)) + (add-hook mode (lambda () (display-line-numbers-mode 0)))) + +(defvar apollo/default-font-size 140) + +(set-face-attribute 'default nil + :font "JetBrains Mono" + :height apollo/default-font-size) + +(set-face-attribute 'fixed-pitch nil + :font "JetBrains Mono" + :height apollo/default-font-size) + +(set-face-attribute 'variable-pitch nil + :font "JetBrains Mono" + :height apollo/default-font-size + :weight 'regular) + +#+end_src +** Dashboard +#+begin_src emacs-lisp + (require 'dashboard) + (require 'all-the-icons) + + (dashboard-setup-startup-hook) + (setq dashboard-items '((recents . 5) + (bookmarks . 5))) + + (setq initial-buffer-choice (lambda () (get-buffer-create "*dashboard*")) + dashboard-item-names '(("Recent Files:" . "Recent Files:") + ("Bookmarks:" . "Study:"))) + ;; Set the banner + (setq dashboard-startup-banner "~/dotfiles/pictures/medicine/plague-doctor-s.png") + ;; Set the title + (setq dashboard-banner-logo-title "Is that a flying flower?") + ;; (setq dashboard-init-info "Bring me your sick and wounded!") + + (setq dashboard-set-init-info t + dashboard-center-content t + dashboard-set-navigator t + dashboard-set-heading-icons t + dashboard-set-file-icons t + dashboard-show-shortcuts nil + dashboard-set-footer t + dashboard-footer-messages '("Welcome to the Church Of Emacs") + dashboard-footer-icon (all-the-icons-octicon "broadcast" + :height 1.15 + :v-adjust -0.05 + :face 'font-lock-keyword-face)) +#+end_src +** Theme & modeline +#+begin_src emacs-lisp +(load-theme 'doom-ayu-dark t) +(doom-modeline-mode 1) + +(setq doom-modeline-height 35) +#+end_src +** Ivy +#+begin_src emacs-lisp + (use-package ivy + :diminish + :bind (("C-s" . swiper) + :map ivy-minibuffer-map + ("TAB" . ivy-alt-done) + ("C-l" . ivy-alt-done) + ("C-j" . ivy-next-line) + ("C-k" . ivy-previous-line) + :map ivy-switch-buffer-map + ("C-k" . ivy-previous-line) + ("C-l" . ivy-done) + ("C-d" . ivy-switch-buffer-kill) + :map ivy-reverse-i-search-map + ("C-k" . ivy-previous-line) + ("C-d" . ivy-reverse-i-search-kill)) + :config + (ivy-mode 1) + (setq ivy-use-selectable-prompt t)) + + (ivy-rich-mode 1) + (all-the-icons-ivy-rich-mode 1) +#+end_src +** Helpful +#+begin_src emacs-lisp +(use-package helpful + :custom + (counsel-describe-function-function #'helpful-callable) + (counsel-describe-variable-function #'helpful-variable) + :bind + ([remap describe-function] . counsel-describe-function) + ([remap describe-command] . helpful-command) + ([remap describe-variable] . counsel-describe-variable) + ([remap describe-key] . helpful-key)) +#+end_src +* Dired +** Keys +#+begin_src emacs-lisp +(define-key dired-mode-map "b" 'dired-up-directory) +#+end_src +** All-the-icons.el + +* Terminals +** Vterm +#+begin_src emacs-lisp +(use-package vterm + :ensure nil + :config + ;; Check if it's one of my guix systems to load from + ;; ~/.guix-profile. Otherwise we use /bin/zsh. + (if + (or (string= (system-name) "fsociety") + (string= (system-name) "heisenberg")) + (setq vterm-shell "~/.guix-profile/bin/zsh") + (setq vterm-shell "/bin/zsh"))) +#+end_src +** Eshell +#+begin_src emacs-lisp +(use-package eshell + :ensure t + :bind (("C-c e" . 'eshell)) + :config + (defvar eshell-path-env (getenv "~/.local/bin"))) + +(defun with-face (str &rest face-plist) + (propertize str 'face face-plist)) + +(defun apollo-eshell-prompt () + (let ((winter-blue "#3F3B6C") + (white-summer "#E5E5CB") + (green-night "#03C988") + (orange-summer "#FFB100") + (green-summer "#A3BB98") + (summer-sea "#2192FF") + (black "#000000")) + (concat + (with-face (concat "[" user-login-name) :foreground orange-summer :background black) + (with-face "@" :foreground orange-summer :background black) + (with-face (concat system-name "]\n") :foreground orange-summer :background black) + (with-face (concat "|" (eshell/pwd) ) :foreground "#F0E9D2" :background winter-blue) + (with-face (format-time-string " | %H:%M" (current-time)) :background winter-blue :foreground "#888") + (with-face "\n -> ")))) + +(setq eshell-prompt-function 'apollo-eshell-prompt) +(setq eshell-highlight-prompt t) +#+end_src +* Key-bindings +#+begin_src emacs-lisp +(global-set-key (kbd "") 'keyboard-escape-quit) +#+end_src + * TODO Functions -* TODO mu4e setup | Email configuration +* mu4e | Email Configuration +** MacOS +If it's a mac, load from homebrew path +#+begin_src emacs-lisp +(when (equal system-type 'darwin) + (use-package mu4e + :load-path "/opt/homebrew/share/emacs/site-lisp/mu/mu4e/")) +#+end_src +** Settings & Context setup +#+begin_src emacs-lisp + (setq mu4e-update-interval (* 10 60)) + (setq mu4e-get-mail-command "mbsync -a") + (setq mu4e-maildir-list "~/Mail/Inbox") + + (defun set-mu4e-context (context-name full-name mail-address signature server) + "Return a mu4e context named CONTEXT-NAME with :match-func matching + folder name CONTEXT-NAME in Maildir. The context's `user-mail-address', + `user-full-name' and `mu4e-compose-signature'`smtpmail-smpt-server' is set to MAIL-ADDRESS + FULL-NAME SIGNATURE and SERVER respectively. + Special folders are set to context specific folders." + (let ((dir-name (concat "/" context-name))) + (make-mu4e-context + :name context-name + ;; we match based on the maildir of the message + :match-func + `(lambda (msg) + (when msg + (string-match-p + ,(concat "^" dir-name) + (mu4e-message-field msg :maildir)))) + :vars + `((user-mail-address . ,mail-address) + (user-full-name . ,full-name) + (mu4e-sent-folder . ,(concat dir-name "/Sent")) + (mu4e-drafts-folder . ,(concat dir-name "/Drafts")) + (mu4e-trash-folder . ,(concat dir-name "/Trash")) + (mu4e-trash-folder . ,(concat dir-name "/Starred")) + (mu4e-refile-folder . ,(concat dir-name "/Archive")) + (smtpmail-smtp-service . ,465) + (smtpmail-smtp-server . ,server) + (mu4e-compose-signature . ,signature))))) + + ;;Fixing duplicate UID errors when using mbsync and mu4e + (setq mu4e-change-filenames-when-moving t) + ;; Messaging + (setq message-send-mail-function 'smtpmail-send-it + smtpmail-stream-type 'ssl) +#+end_src +** Shortcuts +#+begin_src emacs-lisp +(setq mu4e-maildir-shortcuts + '(("/Fastmail/Inbox" . ?i) + ("/Fastmail/Sent" . ?s) + )) +#+end_src +** Contexts +#+begin_src emacs-lisp +(setq mu4e-contexts + `(, (set-mu4e-context + "Fastmail" "Thanos Apollo" + "thanos@thanosapollo.com" "Thanos\nhttps://thanosapollo.com/public" + "smtp.fastmail.com"))) +#+end_src * TODO Custom key-bindings -* TODO Org-mode Configuration +* Org-mode Configuration +** org-make-toc +#+begin_src emacs-lisp + (use-package org-make-toc + :ensure t) +#+end_src +** Themes +*** Dracula +#+begin_src emacs-lisp +(defun apollo/org-theme-dracula () + "Enable Dracula theme for Org headers." + (interactive) + (dolist + (face + '((org-level-1 1.7 "#8be9fd" extra-bold) + (org-level-2 1.6 "#bd93f9" extra-bold) + (org-level-3 1.5 "#50fa7b" bold) + (org-level-4 1.4 "#ff79c6" semi-bold) + (org-level-5 1.3 "#9aedfe" normal) + (org-level-6 1.2 "#caa9fa" normal) + (org-level-7 1.1 "#5af78e" normal) + (org-level-8 1.0 "#ff92d0" normal))) + (set-face-attribute (nth 0 face) nil + :font "JetBrains Mono" + :weight (nth 3 face) + :height (nth 1 face) + :foreground (nth 2 face))) + (set-face-attribute 'org-table nil + :font "JetBrains Mono" + :weight 'normal + :height 1.0 + :foreground "#bfafdf")) +#+end_src +*** Darkone +#+begin_src emacs-lisp +(defun apollo/org-theme-darkone () + "Enable Darkone theme for Org headers." + (interactive) + (dolist + (face + '((org-level-1 1.70 "#51afef" bold) + (org-level-2 1.55 "#7FBCD2" bold) + (org-level-3 1.40 "#da8548" bold) + (org-level-4 1.20 "#da8548" semi-bold) + (org-level-5 1.20 "#5699af" normal) + (org-level-6 1.20 "#a9a1e1" normal) + (org-level-7 1.10 "#46d9ff" normal) + (org-level-8 1.00 "#ff6c6b" normal))) + (set-face-attribute (nth 0 face) nil + :font "Jetbrains Mono" + :weight (nth 3 face) + :height (nth 1 face) + :foreground (nth 2 face))) + (set-face-attribute 'org-table nil + :font "Jetbrains Mono" + :weight 'normal + :height 1.0 + :foreground "#A66CFF")) + +#+end_src +** Settings +#+begin_src emacs-lisp + (setq org-directory "~/org/" + org-agenda-files '("~/org/agenda.org") + org-default-notes-file (expand-file-name "notes.org" org-directory) + org-ellipsis " ▼ " + org-log-done 'time + org-hide-emphasis-markers nil ;;change to t to hide emphasis markers + org-table-convert-region-max-lines 20000 + org-agenda-start-log-mode t + org-log-done 'time + org-log-into-drawer t + org-indent-mode t + org-todo-keywords ;; This overwrites the default Doom org-todo-keywords + '((sequence + "TODO(t)" ;; A task that is ready to be tackled + "BLOG(b)" ;; Blog writing assignments + "GYM(g)" ;; Things to accomplish at the gym + "WAIT(w)" ;; Something is holding up this task + "|" ;; The pipe necessary to separate "active" states and "inactive" states + "DONE(d)" ;; Task has been completed + "CANCELLED(c)" )) + org-superstar-headline-bullets-list '("◉" "●" "○" "●" "○" "●" "◆") + org-superstar-itembullet-alist '((?+ . ?➤) (?- . ?✦))) ;; changes +/- symbols in item lists) + + ;; Startup + (defun apollo/org-mode-setup () + (apollo/org-theme-dracula)) + ;; Hooks + (add-hook 'org-mode-hook 'apollo/org-mode-setup) + (add-hook 'org-mode-hook 'org-superstar-mode) + (add-hook 'org-mode-hook 'flyspell-mode) +#+end_src +** Babel +#+begin_src emacs-lisp +(org-babel-do-load-languages + 'org-babel-load-languages + '((emacs-lisp . t) + (python . t))) + +(add-to-list 'org-structure-template-alist '("sh" . "src shell")) +(add-to-list 'org-structure-template-alist '("b" . "src shell")) +(add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp")) +(add-to-list 'org-structure-template-alist '("py" . "src python")) +#+end_src +* Markdown +** Theme +#+begin_src emacs-lisp +(defun apollo/markdown-theme () + (interactive) + (dolist + (face + '(markdown-header-face-1 :height 2.0)))) +#+end_src +** Settings +#+begin_src emacs-lisp +(setq markdown-header-scaling t) + + +(use-package markdown-mode + :ensure t + :mode (".md" . gfm-mode) + :init (setq markdown-command "multimarkdown")) +#+end_src +* Programming +** Essentials +#+begin_src emacs-lisp +(electric-pair-mode 1) +(global-flycheck-mode) + +(use-package company + :after lsp-mode + :hook (lsp-mode . company-mode) + :bind (:map company-active-map + ("" . company-complete-selection)) + (:map lsp-mode-map + ("" . company-indent-or-complete-common)) + :custom + (company-minimum-prefix-length 1) + (company-idle-delay 0.0)) + +(use-package dap-mode + :custom + (lsp-enable-dap-auto-configure nil) + :config + (dap-ui-mode 1)) + +(use-package company-box + :hook (company-mode . company-box-mode)) +#+end_src +*** Magit +#+begin_src emacs-lisp +(use-package magit + :custom + (magit-display-buffer-function #'magit-display-buffer-same-window-except-diff-v1)) +#+end_src +** Emacs lisp +#+begin_src emacs-lisp +(setq tab-always-indent 'complete) +(add-to-list 'completion-styles 'initials t) + +(add-hook 'emacs-lisp-mode-hook #'rainbow-delimiters-mode) +(add-hook 'scheme-mode-hook #'rainbow-delimiters-mode) +#+end_src +** LSP-Mode +#+begin_src emacs-lisp +(defun apollo/lsp-mode-setup () + (setq lsp-headerline-breadcrumb-segments '(path-up-to-project file symbols)) + (lsp-headerline-breadcrumb-mode)) + +(use-package lsp-mode + :commands (lsp lsp-deferred) + :hook (lsp-mode . apollo/lsp-mode-setup) + :init + (setq lsp-keymap-prefix "C-c l") ;; Or 'C-l', 's-l' + :config + (lsp-enable-which-key-integration t) + (setq lsp-pyls-server-command "~/.local/bin/pylsp")) + +(use-package lsp-ui + :hook (lsp-mode . lsp-ui-mode) + :custom + (lsp-ui-doc-position 'bottom)) +#+end_src +** Python +#+begin_src emacs-lisp +(use-package python-mode + :ensure t + :mode ".py" + :hook (python-mode . lsp-deferred) + :custom + (dap-python-debugger 'debugpy) + :config + (require 'dap-python)) + +(use-package pyvenv + :config + (pyvenv-mode 1)) +#+end_src +** JSON +#+begin_src emacs-lisp +(use-package json-mode + :mode ".json" + :hook (json-mode . lsp-deferred)) +#+end_src +** Javascript +#+begin_src emacs-lisp +(use-package rjsx-mode + :mode ".js" + :hook (rjsx-mode . lsp-deferred) + :config + (defadvice js-jsx-indent-line (after js-jsx-indent-line-after-hack activate) + "Workaround sgml-mode and follow airbnb component style." + (save-excursion + (beginning-of-line) + (if (looking-at-p "^ +\/?> *$") + (delete-char sgml-basic-offset))))) +#+end_src +* Elfeed + +* PDF +#+begin_src emacs-lisp +(use-package pdf-tools + :ensure t + :mode ".pdf" + :config + (add-hook 'pdf-view-mode #'pdf-isearch-minor-mode)) +#+end_src +* Telega +In ~GuixSD~ systems I have telegram installed via guix, and it's loaded via ~guix-emacs-autoload-packages~ +In macOS, I have installed it through homebrew. +#+begin_src emacs-lisp +(when (equal system-type 'darwin) + (use-package telega + :load-path "~/telega.el" + :commands (telega) + :defer t + :config + (setq telega-server-libs-prefix "/opt/homebrew/Cellar/tdlib/HEAD-3d0140b"))) +#+end_src + +* Custom +** ChatGPT +#+begin_src emacs-lisp +(require 'seq) +(eval-when-compile + (require 'cl-lib) + (require 'subr-x) + (require 'env) + (require 'json)) +(defgroup chatgpt nil + "ChatGPT frontend." + :group 'convenience + :prefix "chatgpt-") +(defcustom chatgpt-max-tokens 300 + "Upper limit on the number of tokens the API will return." + :type 'integer) +(defvar chatgpt-buffer "*ChatGPT*" + "Title of the buffer used to store the results of an OpenAI API query.") +(define-error 'chatgpt-error "An error related to the ChatGPT emacs package") +(define-error 'chatgpt-parsing-error + "An error caused by a failure to parse an OpenAI API Response") +(defmacro chatgpt-show-results-buffer-if-active () + "Show the results in other window if necessary." + `(if (and (not ;; visible + (get-buffer-window chatgpt-buffer)) + (called-interactively-p 'interactive)) + (lambda (&optional buf) (ignore buf) + (with-current-buffer buf + (view-mode t)) + (switch-to-buffer-other-window chatgpt-buffer)) + #'identity)) +;;;###autoload +(defun chatgpt-prompt (prompt callback) + "Query OpenAI with PROMPT calling the CALLBACK function on the resulting buffer. +Returns buffer containing the text from this query" + (interactive (list (read-string "Prompt ChatGPT with: ") + (lambda (buf) (with-current-buffer buf + (view-mode t)) + (switch-to-buffer-other-window chatgpt-buffer)))) + (chatgpt--query-open-api prompt + (lambda (results) + (with-current-buffer (get-buffer-create chatgpt-buffer) + ;; Erase contents of buffer after receiving response + (read-only-mode -1) + (erase-buffer) + (insert results) + ;; Return the chatgpt output buffer for non interactive usage + (funcall callback (current-buffer)))))) +;;;###autoload +(defun chatgpt-fix-region (BEG END) + "Takes a region BEG to END asks ChatGPT to explain whats wrong with it. +It then displays the answer in the `chatgpt-buffer'." + (interactive "r") + (let ((current-code (buffer-substring BEG END))) + (chatgpt-prompt (chatgpt--append-to-prompt + current-code + "Why doesn't this code work?") + (chatgpt-show-results-buffer-if-active)))) +;;;###autoload +(defun chatgpt-explain-region (BEG END) + "Takes a region BEG to END asks ChatGPT what it does. +The answer in the displays in `chatgpt-buffer'." + (interactive "r") + (let ((current-code (buffer-substring BEG END))) + (chatgpt-prompt (chatgpt--append-to-prompt + current-code + "What does this code do?") + (chatgpt-show-results-buffer-if-active)))) +;;;###autoload +(defun chatgpt-gen-tests-for-region (BEG END) + "Takes a region BEG to END asks ChatGPT to write a test for it. +It then displays the answer in the `chatgpt-buffer'." + (interactive "r") + (let ((current-code (buffer-substring BEG END))) + (chatgpt-prompt (chatgpt--append-to-prompt + current-code + "Write me a tests for this code") + (chatgpt-show-results-buffer-if-active)))) +;; TODO currently just says what changed but doesn't wanna show the code it's self +;; (defun chatgpt-optimize-region (BEG END) +;; "Takes a region BEG to END asks ChatGPT to optimize it for speed. +;; It then displays the answer in the `chatgpt-buffer'." +;; (interactive "r") +;; (let ((current-code (buffer-substring BEG END))) +;; (chatgpt-prompt (chatgpt--append-to-prompt +;; current-code +;; "Refactor this code for speed and tell me what you changed and why it's faster") +;; (chatgpt-show-results-buffer-if-active)))) +;;;###autoload +(defun chatgpt-refactor-region (BEG END) + "Takes a region BEG to END asks ChatGPT refactor it. +It then displays the answer in the `chatgpt-buffer'." + (interactive "r") + (let ((current-code (buffer-substring BEG END))) + (chatgpt-prompt (chatgpt--append-to-prompt + current-code + "Refactor this code and tell me what you changed") + (chatgpt-show-results-buffer-if-active)))) +;;;###autoload +(defun chatgpt-prompt-region (BEG END) + "Prompt ChatGPT with the region BEG END. +It then displays the results in a separate buffer `chatgpt-buffer'." + (interactive "r") + (chatgpt-prompt (buffer-substring BEG END) + ;; Show the results if not already being viewed + (chatgpt-show-results-buffer-if-active))) +;;;###autoload +(defun chatgpt-prompt-region-and-replace (BEG END) + "Replace region from BEG to END with the response from the ChatGPT API. +The region is BEG and until END" + (interactive "r") + (let ((og-buf (current-buffer))) + (chatgpt-prompt (buffer-substring BEG END) + (lambda (buf) + (save-excursion + (with-current-buffer og-buf + (delete-region BEG END) + (goto-char BEG) + (insert (with-current-buffer buf (buffer-string))))))))) +(defun chatgpt--append-to-prompt (prompt comment-str) + "Append the string COMMENT-STR extra information to a PROMPT as a comment." + (concat prompt + "\n" + comment-start + " " + comment-str)) +(defun chatgpt--extract-text-from-query (query-result) + "Extract the resulting text from a given OpenAI response QUERY-RESULT." + (condition-case err + (thread-last query-result + (assoc-default 'choices) + seq-first + (assoc-default 'text) + string-trim) + (error + (signal 'chatgpt-parsing-error err)))) +(defun chatgpt--parse-response (status callback) + "Ignoring STATUS and parse the response executing the CALLBACK function on the resulting string." + (ignore status) + ;; All this is ran inside the buffer containing the response + (goto-char 0) + (re-search-forward "^$") + (funcall callback (chatgpt--extract-text-from-query (json-read)))) +(defun chatgpt--query-open-api (prompt callback) + "Send a string PROMPT to OpenAI API and pass the resulting buffer to CALLBACK. +The environment variable OPENAI_API_KEY is used as your API key +You can register an account here +https://beta.openai.com/docs/introduction/key-concepts" + (let* ((api-key (getenv "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")) + (url-request-method (encode-coding-string "POST" 'us-ascii)) + (url-request-extra-headers `(("Content-Type" . "application/json") + ("Authorization" . ,(format "Bearer %s" api-key)))) + (url-request-data (json-encode + `(("model" . "text-davinci-003") + ("prompt" . ,prompt) + ("max_tokens" . ,chatgpt-max-tokens) + ("temperature" . 0))))) + (cl-assert (not (string= "" api-key)) + t + "Current contents of the environmental variable OPENAI_API_KEY +are '%s' which is not an appropriate OpenAI token please ensure +you have the correctly set the OPENAI_API_KEY variable" + api-key) + (url-retrieve + "https://api.openai.com/v1/completions" + 'chatgpt--parse-response + (list callback)))) +#+end_src +** Random functions +#+begin_src emacs-lisp +(defun apollo/html-boostrap-boilerplate () + "Insert html boilerplate with boostrap link." + (interactive) + (insert +" + + + + + + My Title + + + + +
+

Starting point

+
+ + +" )) + + +(defun apollo/center-buffer () + "Centers/Uncenters selected buffer" + (interactive) + (if visual-fill-column-center-text + (setq visual-fill-column-center-text nil) + (setq visual-fill-column-center-text t)) + (visual-fill-column-mode 1) + (message "General's task completed!")) + + +(defun apollo/rofi-switch-window () + "Navigate X11 buffers using rofi." + (interactive) + (start-process-shell-command + "rofi" nil "rofi -show window")) + +(defun apollo/run-in-background (command) + "Run COMMAND in the background." + (let ((command-parts (split-string command "[ ]+"))) + (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts))))) + +(defun rofi () + "Run Rofi." + (interactive) + (apollo/run-in-background "rofi -show drun")) + +(defun apollo/volume-increase () + "Increase Volume." + (interactive) + (start-process-shell-command + "amixer" nil "amixer sset Master 5%+")) + +(defun apollo/volume-decrease () + "Decrease Volume." + (interactive) + (start-process-shell-command + "amixer" nil "amixer sset Master 5%-")) + +(defun apollo/restore-wallpaper () + "Set NAME as wallpaper." + (interactive) + (start-process-shell-command + "feh" nil "feh --bg-scale ~/dotfiles/wallpaper.png")) + +(defun apollo/emacs-keys () + "Swap caps with ctrl." + (interactive) + (start-process-shell-command + "setxkbmap" nil "setxkbmap us -option ctrl:swapcaps")) + +(defun apollo/greek-keyboard () + "Swap caps with ctrl." + (interactive) + (start-process-shell-command + "setxkbmap" nil "setxkbmap gr")) + +(defun apollo/exwm-update-class () + (exwm-workspace-rename-buffer exwm-class-name)) + +(defun eshell-new() + "Open a new instance of eshell." + (interactive) + (eshell 'N)) + +(defun make-mini-geiser () + (interactive) + (split-window-below 60) + (geiser nil)) + +(defun start-polybar () + "Check which system is running, start polybar accordingly." + (interactive) + (if (string= (system-name) "fsociety") + (start-process-shell-command + "polybar" nil "polybar main & polybar second") + (start-process-shell-command + "polybar" nil "polybar main"))) +#+end_src +* TODO EXWM +TODO: tangle with .exwm.el & organize + +#+begin_src emacs-lisp +(defun apollo/exwm-init-hook () + "Do this upon start." + (if (string= (system-name) "fsociety") ;; Check if it's my desktop, otherwise display battery + (display-battery-mode 0) + (display-battery-mode 1)) + + (setq display-time-day-and-date t) + (display-time-mode 1) + + (exwm-firefox-holyK-mode 1) + + ;;Launch apps that will run in the background + ;; (apollo/run-in-background "blueman-applet") + (apollo/run-in-background "picom") + ;; (apollo/run-in-background "nm-applet") + (apollo/emacs-keys) + (apollo/restore-wallpaper) + ) + +(defun apollo/exwm-update-class () + (exwm-workspace-rename-buffer exwm-class-name)) + + +(setq exwm-workspace-number 6) +;; When window "class" updates, use it to set the buffer name +(add-hook 'exwm-update-class-hook #'apollo/exwm-update-class) + +;;When EXWM starts up, run this hook +(add-hook 'exwm-init-hook #'apollo/exwm-init-hook) +(start-process-shell-command + "xrandr" nil "xrandr --output DisplayPort-0 --primary --mode 2560x1440 --pos 1930x0 --rotate normal --output DisplayPort-1 --off --output DisplayPort-2 --off --output HDMI-A-0 --mode 1920x1080 --pos 0x0 --rotate normal") + +;; Set the screen resolution + +(require 'exwm-randr) +(setq exwm-randr-workspace-monitor-plist '(0 "DP-1" 2 "HDMI-A-0")) +(add-hook 'exwm-randr-screen-change-hook + (lambda () + (start-process-shell-command + "xrandr" nil "xrandr --output DisplayPort-2 --primary --mode 2560x1440 --pos 1920x0 --rotate normal --output HDMI-A-0 --mode 1920x1080 --pos 0x0 --rotate normal" ))) +(exwm-randr-enable) + + +;; Load the system tray before exwm-init +(require 'exwm-systemtray) +(exwm-systemtray-enable) + +;; These keys should always pass through to Emacs +(setq exwm-input-prefix-keys + '(?\C-x + ?\C-u + ?\C-h + ?\C-w + ?\M-x + ?\M-` + ?\M-& + ?\M-: + ?\s-d + ?\C-\M-j ;; Buffer list + ?\C-\ + ?\C-k + ?\C-y + ?\C-n + ?\C-p + ?\C-f + ?\C-b + ?\C-s + ?\M-f + ?\M-b + ?\M-< + ?\M->)) + +;; Ctrl+Q will enable the next key to be sent directly +(define-key exwm-mode-map [?\C-q] 'exwm-input-send-next-key) + +;; Set up global key bindings. These always work, no matter the input state! +;; Keep in mind that changing this list after EXWM initializes has no effect. +(setq exwm-input-global-keys + `( + + ([?\s-r] . exwm-reset) + + + + ;; ;; Launch applications via shell command + ;; ([?\s-&] . (lambda (command) + ;; (interactive (list (read-shell-command "$ "))) + ;; (start-process-shell-command command nil command))) + + ;; Switch workspace + ([?\s-e] . exwm-workspace-switch) + ([?\s-`] . (lambda () (interactive) (exwm-workspace-switch-create 0))) + ([?\s-2] . (lambda () (interactive) (exwm-workspace-switch-create 1))) + ([?\s-3] . (lambda () (interactive) (exwm-workspace-switch-create 2))) + ([?\s-4] . (lambda () (interactive) (exwm-workspace-switch-create 3))) + ([?\s-5] . (lambda () (interactive) (exwm-workspace-switch-create 4))) + + ,@(mapcar (lambda (i) + `(,(kbd (format "s-%d" i)) . + (lambda () + (interactive) + (exwm-workspace-switch-create ,i)))) + (number-sequence 0 9)))) + +(defun exwm-enlarge-horizontally-50 () + (interactive) + (exwm-layout-enlarge-window-horizontally 50)) + +(defun exwm-shrink-horizontally-50 () + "Shrink window horizontally by 10" + (interactive) + (exwm-layout-shrink-window-horizontally 50)) + +(defun exwm-shrink-vertically-50 () + "Shrink window by 50." + (interactive) + (exwm-layout-shrink-window 50)) + +(defun exwm-enlarge-vertically-50 () + "Enlarge window by 50." + (interactive) + (exwm-layout-enlarge-window 50)) + +(exwm-input-set-key (kbd "C-c d") 'dmenu) +(exwm-input-set-key (kbd "s-") 'rofi) +(exwm-input-set-key (kbd "s-Q") 'kill-emacs) +(exwm-input-set-key (kbd "") 'apollo/volume-increase) +(exwm-input-set-key (kbd "") 'apollo/volume-decrease) +(exwm-input-set-key (kbd "s-0") 'apollo/emacs-keys) +(exwm-input-set-key (kbd "s-9") 'apollo/greek-keyboard) +(exwm-input-set-key (kbd "C-c C-") 'exwm-shrink-horizontally-50) +(exwm-input-set-key (kbd "C-c C-") 'exwm-enlarge-horizontally-50) +(exwm-input-set-key (kbd "C-c C-") 'exwm-shrink-vertically-50) +(exwm-input-set-key (kbd "C-c C-") 'exwm-enlarge-vertically-50) +(exwm-input-set-key (kbd "C-c C-e") 'exwm-layout-toggle-fullscreen) + + +(exwm-enable) + +;;Transparency +(set-frame-parameter (selected-frame) 'alpha '(90 90)) +(add-to-list 'default-frame-alist '(alpha 90 90)) + +#+end_src -- cgit v1.2.3 From 0c384c528269b1e332f1bdbecbc48ad71fed8711 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Thu, 9 Feb 2023 03:35:27 +0200 Subject: emacs: ChatGPT fix --- .emacs.d/emacs.org | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to '.emacs.d') diff --git a/.emacs.d/emacs.org b/.emacs.d/emacs.org index 7a3a7c5..74bfe80 100644 --- a/.emacs.d/emacs.org +++ b/.emacs.d/emacs.org @@ -788,7 +788,7 @@ The region is BEG and until END" The environment variable OPENAI_API_KEY is used as your API key You can register an account here https://beta.openai.com/docs/introduction/key-concepts" - (let* ((api-key (getenv "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")) + (let* ((api-key (getenv secret-api)) (url-request-method (encode-coding-string "POST" 'us-ascii)) (url-request-extra-headers `(("Content-Type" . "application/json") ("Authorization" . ,(format "Bearer %s" api-key)))) -- cgit v1.2.3 From 5d265841976d13affc568557d125c65782b3d50f Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 10 Feb 2023 04:57:03 +0200 Subject: emacs: Complete transition to literate config --- .emacs.d/emacs.org | 555 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 469 insertions(+), 86 deletions(-) (limited to '.emacs.d') diff --git a/.emacs.d/emacs.org b/.emacs.d/emacs.org index 74bfe80..dfcbcaa 100644 --- a/.emacs.d/emacs.org +++ b/.emacs.d/emacs.org @@ -1,5 +1,5 @@ #+TITLE: Emacs Configuration -#+PROPERTY: header-args :tangle test.el +#+PROPERTY: header-args :tangle init.el #+auto_tangle: t #+OPTIONS: num:nil toc:nil @@ -29,11 +29,9 @@ - [[#key-bindings][Key-bindings]] - [[#functions][Functions]] - [[#mu4e--email-configuration][mu4e | Email Configuration]] - - [[#macos][MacOS]] - - [[#settings--context-setup][Settings & Context setup]] - - [[#shortcuts][Shortcuts]] - - [[#contexts][Contexts]] - [[#custom-key-bindings][Custom key-bindings]] + - [[#general][General]] + - [[#hydra][Hydra]] - [[#org-mode-configuration][Org-mode Configuration]] - [[#org-make-toc][org-make-toc]] - [[#themes][Themes]] @@ -53,6 +51,8 @@ - [[#json][JSON]] - [[#javascript][Javascript]] - [[#elfeed][Elfeed]] + - [[#feeds][Feeds]] + - [[#settings][Settings]] - [[#pdf][PDF]] - [[#telega][Telega]] - [[#custom][Custom]] @@ -61,7 +61,7 @@ - [[#exwm][EXWM]] :END: -* TODO Setting up Packages +* Setting up Packages ** Setup for GuixSD machines We check the ~$HOSTNAME~, if it's one of my devices running GuixSD. we use ~guix-emacs-autoload-packages~ to load emacs packages installed using guix if ~t~ @@ -154,7 +154,7 @@ Contains the list of packages that need to be installed.") (package-install 'use-package)) #+end_src -* TODO UI Settings +* UI Settings ** Basic UI Fonts and basic appearance settings #+begin_src emacs-lisp @@ -284,7 +284,114 @@ Fonts and basic appearance settings (define-key dired-mode-map "b" 'dired-up-directory) #+end_src ** All-the-icons.el +#+begin_src emacs-lisp +;;; all-the-icons-dired.el --- Shows icons for each file in dired mode -*- lexical-binding: t; -*- + +;;; Code: + +(require 'cl-lib) +(require 'dired) +(require 'all-the-icons) + +(defface all-the-icons-dired-dir-face + '((((background dark)) :foreground "white") + (((background light)) :foreground "black")) + "Face for the directory icon" + :group 'all-the-icons-faces) + +(defcustom all-the-icons-dired-v-adjust 0.01 + "The default vertical adjustment of the icon in the dired buffer." + :group 'all-the-icons + :type 'number) + +(defvar all-the-icons-dired-mode) + +(defun all-the-icons-dired--add-overlay (pos string) + "Add overlay to display STRING at POS." + (let ((ov (make-overlay (1- pos) pos))) + (overlay-put ov 'all-the-icons-dired-overlay t) + (overlay-put ov 'after-string string))) + +(defun all-the-icons-dired--overlays-in (beg end) + "Get all all-the-icons-dired overlays between BEG to END." + (cl-remove-if-not + (lambda (ov) + (overlay-get ov 'all-the-icons-dired-overlay)) + (overlays-in beg end))) + +(defun all-the-icons-dired--overlays-at (pos) + "Get all-the-icons-dired overlays at POS." + (apply #'all-the-icons-dired--overlays-in `(,pos ,pos))) + +(defun all-the-icons-dired--remove-all-overlays () + "Remove all `all-the-icons-dired' overlays." + (save-restriction + (widen) + (mapc #'delete-overlay + (all-the-icons-dired--overlays-in (point-min) (point-max))))) + +(defun all-the-icons-dired--refresh () + "Display the icons of files in a dired buffer." + (all-the-icons-dired--remove-all-overlays) + (save-excursion + (goto-char (point-min)) + (while (not (eobp)) + (when (dired-move-to-filename nil) + (let ((file (dired-get-filename 'relative 'noerror))) + (when file + (let ((icon (if (file-directory-p file) + (all-the-icons-icon-for-dir file + :face 'all-the-icons-dired-dir-face + :v-adjust all-the-icons-dired-v-adjust) + (all-the-icons-icon-for-file file :v-adjust all-the-icons-dired-v-adjust)))) + (if (member file '("." "..")) + (all-the-icons-dired--add-overlay (point) " \t") + (all-the-icons-dired--add-overlay (point) (concat icon "\t"))))))) + (forward-line 1)))) + +(defun all-the-icons-dired--refresh-advice (fn &rest args) + "Advice function for FN with ARGS." + (apply fn args) + (when all-the-icons-dired-mode + (all-the-icons-dired--refresh))) + +(defun all-the-icons-dired--setup () + "Setup `all-the-icons-dired'." + (when (derived-mode-p 'dired-mode) + (setq-local tab-width 1) + (advice-add 'dired-readin :around #'all-the-icons-dired--refresh-advice) + (advice-add 'dired-revert :around #'all-the-icons-dired--refresh-advice) + (advice-add 'dired-internal-do-deletions :around #'all-the-icons-dired--refresh-advice) + (advice-add 'dired-insert-subdir :around #'all-the-icons-dired--refresh-advice) + (advice-add 'dired-do-kill-lines :around #'all-the-icons-dired--refresh-advice) + (with-eval-after-load 'dired-narrow + (advice-add 'dired-narrow--internal :around #'all-the-icons-dired--refresh-advice)) + (all-the-icons-dired--refresh))) + +(defun all-the-icons-dired--teardown () + "Functions used as advice when redisplaying buffer." + (advice-remove 'dired-readin #'all-the-icons-dired--refresh-advice) + (advice-remove 'dired-revert #'all-the-icons-dired--refresh-advice) + (advice-remove 'dired-internal-do-deletions #'all-the-icons-dired--refresh-advice) + (advice-remove 'dired-narrow--internal #'all-the-icons-dired--refresh-advice) + (advice-remove 'dired-insert-subdir #'all-the-icons-dired--refresh-advice) + (advice-remove 'dired-do-kill-lines #'all-the-icons-dired--refresh-advice) + (all-the-icons-dired--remove-all-overlays)) + +;;;###autoload +(define-minor-mode all-the-icons-dired-mode + "Display all-the-icons icon for each files in a dired buffer." + :lighter " all-the-icons-dired-mode" + (when (and (derived-mode-p 'dired-mode) (display-graphic-p)) + (if all-the-icons-dired-mode + (all-the-icons-dired--setup) + (all-the-icons-dired--teardown)))) +#+end_src +Hook with ~dired-mode~ +#+begin_src emacs-lisp +(add-hook 'dired-mode-hook 'all-the-icons-dired-mode) +#+end_src * Terminals ** Vterm #+begin_src emacs-lisp @@ -334,76 +441,332 @@ Fonts and basic appearance settings (global-set-key (kbd "") 'keyboard-escape-quit) #+end_src -* TODO Functions +* Functions +#+begin_src emacs-lisp +(defun apollo/html-boostrap-boilerplate () + "Insert html boilerplate with boostrap link." + (interactive) + (insert +" + + + + + + My Title + + + + +
+

Starting point

+
+ + +" )) + + +(defun apollo/center-buffer () + "Centers/Uncenters selected buffer" + (interactive) + (if visual-fill-column-center-text + (setq visual-fill-column-center-text nil) + (setq visual-fill-column-center-text t)) + (visual-fill-column-mode 1) + (message "General's task completed!")) + + +(defun apollo/rofi-switch-window () + "Navigate X11 buffers using rofi." + (interactive) + (start-process-shell-command + "rofi" nil "rofi -show window")) + +(defun apollo/run-in-background (command) + "Run COMMAND in the background." + (let ((command-parts (split-string command "[ ]+"))) + (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts))))) + +(defun rofi () + "Run Rofi." + (interactive) + (apollo/run-in-background "rofi -show drun")) + +(defun apollo/volume-increase () + "Increase Volume." + (interactive) + (start-process-shell-command + "amixer" nil "amixer sset Master 5%+")) + +(defun apollo/volume-decrease () + "Decrease Volume." + (interactive) + (start-process-shell-command + "amixer" nil "amixer sset Master 5%-")) + +(defun apollo/restore-wallpaper () + "Set NAME as wallpaper." + (interactive) + (start-process-shell-command + "feh" nil "feh --bg-scale ~/dotfiles/wallpaper.png")) + +(defun apollo/emacs-keys () + "Swap caps with ctrl." + (interactive) + (start-process-shell-command + "setxkbmap" nil "setxkbmap us -option ctrl:swapcaps")) + +(defun apollo/greek-keyboard () + "Swap caps with ctrl." + (interactive) + (start-process-shell-command + "setxkbmap" nil "setxkbmap gr")) + +(defun apollo/exwm-init-hook () + "Do this upon start." + (display-battery-mode 0) ;;Change to 1 to display battery + + (setq display-time-day-and-date t) + (display-time-mode 1) + + ;;Launch apps that will run in the background +;; (apollo/run-in-background "blueman-applet") + (apollo/run-in-background "picom") +;; (apollo/run-in-background "nm-applet") + (apollo/emacs-keys) + (apollo/set-wallpaper) + (start-polybar) + ) + +(defun apollo/exwm-update-class () + (exwm-workspace-rename-buffer exwm-class-name)) + +(defun eshell-new() + "Open a new instance of eshell." + (interactive) + (eshell 'N)) + +(defun make-mini-buffer () + (interactive) + (split-window-below 40) + (other-window 1)) + +(defun make-mini-geiser () + (interactive) + (split-window-below 60) + (geiser nil)) + +(defun start-polybar () + "Check which system is running, start polybar accordingly." + (interactive) + (if (string= (system-name) "fsociety") + (start-process-shell-command + "polybar" nil "polybar main & polybar second") + (start-process-shell-command + "polybar" nil "polybar main"))) +#+end_src * mu4e | Email Configuration -** MacOS -If it's a mac, load from homebrew path + +# ** MacOS +# If it's a mac, load from homebrew path + +# #+begin_src emacs-lisp +# (when (equal system-type 'darwin) +# (use-package mu4e +# :load-path "/opt/homebrew/share/emacs/site-lisp/mu/mu4e/")) +# #+end_src + #+begin_src emacs-lisp (when (equal system-type 'darwin) (use-package mu4e :load-path "/opt/homebrew/share/emacs/site-lisp/mu/mu4e/")) -#+end_src -** Settings & Context setup -#+begin_src emacs-lisp - (setq mu4e-update-interval (* 10 60)) - (setq mu4e-get-mail-command "mbsync -a") - (setq mu4e-maildir-list "~/Mail/Inbox") - - (defun set-mu4e-context (context-name full-name mail-address signature server) - "Return a mu4e context named CONTEXT-NAME with :match-func matching - folder name CONTEXT-NAME in Maildir. The context's `user-mail-address', - `user-full-name' and `mu4e-compose-signature'`smtpmail-smpt-server' is set to MAIL-ADDRESS - FULL-NAME SIGNATURE and SERVER respectively. - Special folders are set to context specific folders." - (let ((dir-name (concat "/" context-name))) - (make-mu4e-context - :name context-name - ;; we match based on the maildir of the message - :match-func - `(lambda (msg) - (when msg - (string-match-p - ,(concat "^" dir-name) - (mu4e-message-field msg :maildir)))) - :vars - `((user-mail-address . ,mail-address) - (user-full-name . ,full-name) - (mu4e-sent-folder . ,(concat dir-name "/Sent")) - (mu4e-drafts-folder . ,(concat dir-name "/Drafts")) - (mu4e-trash-folder . ,(concat dir-name "/Trash")) - (mu4e-trash-folder . ,(concat dir-name "/Starred")) - (mu4e-refile-folder . ,(concat dir-name "/Archive")) - (smtpmail-smtp-service . ,465) - (smtpmail-smtp-server . ,server) - (mu4e-compose-signature . ,signature))))) - - ;;Fixing duplicate UID errors when using mbsync and mu4e - (setq mu4e-change-filenames-when-moving t) - ;; Messaging - (setq message-send-mail-function 'smtpmail-send-it - smtpmail-stream-type 'ssl) -#+end_src -** Shortcuts -#+begin_src emacs-lisp + +(require 'mu4e) + +(setq mu4e-update-interval (* 10 60)) +(setq mu4e-get-mail-command "mbsync -a") +(setq mu4e-maildir-list "~/Mail/Inbox") + +(defun set-mu4e-context (context-name full-name mail-address signature server) + "Return a mu4e context named CONTEXT-NAME with :match-func matching + folder name CONTEXT-NAME in Maildir. The context's `user-mail-address', + `user-full-name' and `mu4e-compose-signature'`smtpmail-smpt-server' is set to MAIL-ADDRESS + FULL-NAME SIGNATURE and SERVER respectively. + Special folders are set to context specific folders." + (let ((dir-name (concat "/" context-name))) + (make-mu4e-context + :name context-name + ;; we match based on the maildir of the message + :match-func + `(lambda (msg) + (when msg + (string-match-p + ,(concat "^" dir-name) + (mu4e-message-field msg :maildir)))) + :vars + `((user-mail-address . ,mail-address) + (user-full-name . ,full-name) + (mu4e-sent-folder . ,(concat dir-name "/Sent")) + (mu4e-drafts-folder . ,(concat dir-name "/Drafts")) + (mu4e-trash-folder . ,(concat dir-name "/Trash")) + (mu4e-trash-folder . ,(concat dir-name "/Starred")) + (mu4e-refile-folder . ,(concat dir-name "/Archive")) + (smtpmail-smtp-service . ,465) + (smtpmail-smtp-server . ,server) + (mu4e-compose-signature . ,signature))))) +;;Fixing duplicate UID errors when using mbsync and mu4e +(setq mu4e-change-filenames-when-moving t) + (setq mu4e-maildir-shortcuts '(("/Fastmail/Inbox" . ?i) ("/Fastmail/Sent" . ?s) + ;; ("/Gmail/Trash" . ?t) + ;; ("/Gmail/Drafts" . ?d) + ;; ("/Gmail/[Gmail]/All Mail" . ?a )) -#+end_src -** Contexts -#+begin_src emacs-lisp + (setq mu4e-contexts `(, (set-mu4e-context "Fastmail" "Thanos Apollo" "thanos@thanosapollo.com" "Thanos\nhttps://thanosapollo.com/public" "smtp.fastmail.com"))) + +;; (setq smtpmail-smtp-service 465 +;; smtpmail-stream-type 'ssl +;; smtpmail-smtp-server "smtp.fastmail.com") + + + +(setq message-send-mail-function 'smtpmail-send-it + smtpmail-stream-type 'ssl) + +#+end_src + +# ** Settings & Context setup +# #+begin_src emacs-lisp +# (require 'mu4e) +# (setq mu4e-update-interval (* 10 60)) +# (setq mu4e-get-mail-command "mbsync -a") +# (setq mu4e-maildir-list "~/Mail/Inbox") + +# (defun set-mu4e-context (context-name full-name mail-address signature server) +# "Return a mu4e context named CONTEXT-NAME with :match-func matching +# folder name CONTEXT-NAME in Maildir. The context's `user-mail-address', +# `user-full-name' and `mu4e-compose-signature'`smtpmail-smpt-server' is set to MAIL-ADDRESS +# FULL-NAME SIGNATURE and SERVER respectively. +# Special folders are set to context specific folders." +# (let ((dir-name (concat "/" context-name))) +# (make-mu4e-context +# :name context-name +# ;; we match based on the maildir of the message +# :match-func +# `(lambda (msg) +# (when msg +# (string-match-p +# ,(concat "^" dir-name) +# (mu4e-message-field msg :maildir)))) +# :vars +# `((user-mail-address . ,mail-address) +# (user-full-name . ,full-name) +# (mu4e-sent-folder . ,(concat dir-name "/Sent")) +# (mu4e-drafts-folder . ,(concat dir-name "/Drafts")) +# (mu4e-trash-folder . ,(concat dir-name "/Trash")) +# (mu4e-trash-folder . ,(concat dir-name "/Starred")) +# (mu4e-refile-folder . ,(concat dir-name "/Archive")) +# (smtpmail-smtp-service . ,465) +# (smtpmail-smtp-server . ,server) +# (mu4e-compose-signature . ,signature))))) + +# ;;Fixing duplicate UID errors when using mbsync and mu4e +# (setq mu4e-change-filenames-when-moving t) +# ;; Messaging +# (setq message-send-mail-function 'smtpmail-send-it +# smtpmail-stream-type 'ssl) +# #+end_src +# ** Shortcuts +# #+begin_src emacs-lisp +# (setq mu4e-maildir-shortcuts +# '(("/Fastmail/Inbox" . ?i) +# ("/Fastmail/Sent" . ?s) +# )) +# #+end_src +# ** Contexts +# #+begin_src emacs-lisp +# (setq mu4e-contexts +# `(, (set-mu4e-context +# "Fastmail" "Thanos Apollo" +# "thanos@thanosapollo.com" "Thanos\nhttps://thanosapollo.com/public" +# "smtp.fastmail.com"))) +# #+end_src +* Custom key-bindings +** General +#+begin_src emacs-lisp + + ;; my general's leader key! + (defconst general-key "C-c g") + + (general-create-definer general-does + :prefix general-key) + + ;; Basic functions + (general-define-key + "C-d" 'kill-region + "C-k" 'copy-region-as-kill + "C-c v" 'multi-vterm-next + "C-x 9" 'make-mini-buffer + "C-c l e" 'apollo/emacs-keys + ;;Change keyboard layouts/language + "C-c l g" 'apollo/greek-keyboard + "C-κ" 'apollo/emacs-keys + "C-x C-b" 'ibuffer) + + + + ;; My Generals does: + (general-does + "t" 'counsel-load-theme + "l" 'display-line-numbers-mode + "v" 'multi-vterm-next + "e" 'eshell + "i" 'circe + "c" 'apollo/center-buffer + "m" 'mu4e + "f" 'elfeed + "C-t" 'telega) + + ;;pdf-tools + (general-define-key + :keymaps 'pdf-view-mode-map + "C-c d" 'pdf-view-midnight-minor-mode + "C-s" 'isearch-forward + "C-o" 'pdf-isearch-occur) + + ;;vterm + (general-does + :keymaps 'vterm-mode-map + "n" 'multi-vterm-next + "o" 'multi-vterm + "p" 'multi-vterm-prev) + + (general-does + :keymaps 'eshell-mode-map + "n" 'eshell-new) + + (general-does + :keymaps 'org-mode-map + "3" 'org-insert-image-size-300) +#+end_src +** Hydra +#+begin_src emacs-lisp +(defhydra hydra-zoom (global-map "s-z") + "zoom" + ("=" text-scale-increase "in") + ("-" text-scale-decrease "out")) #+end_src -* TODO Custom key-bindings * Org-mode Configuration ** org-make-toc #+begin_src emacs-lisp - (use-package org-make-toc - :ensure t) + (add-hook 'org-mode-hook 'org-make-toc-mode) #+end_src ** Themes *** Dracula @@ -484,25 +847,25 @@ If it's a mac, load from homebrew path org-superstar-headline-bullets-list '("◉" "●" "○" "●" "○" "●" "◆") org-superstar-itembullet-alist '((?+ . ?➤) (?- . ?✦))) ;; changes +/- symbols in item lists) - ;; Startup - (defun apollo/org-mode-setup () - (apollo/org-theme-dracula)) ;; Hooks - (add-hook 'org-mode-hook 'apollo/org-mode-setup) + (add-hook 'org-mode-hook 'apollo/org-theme-dracula) (add-hook 'org-mode-hook 'org-superstar-mode) (add-hook 'org-mode-hook 'flyspell-mode) #+end_src ** Babel #+begin_src emacs-lisp -(org-babel-do-load-languages - 'org-babel-load-languages - '((emacs-lisp . t) - (python . t))) - -(add-to-list 'org-structure-template-alist '("sh" . "src shell")) -(add-to-list 'org-structure-template-alist '("b" . "src shell")) -(add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp")) -(add-to-list 'org-structure-template-alist '("py" . "src python")) + (org-babel-do-load-languages + 'org-babel-load-languages + '((emacs-lisp . t) + (python . t))) + + (add-to-list 'org-structure-template-alist '("sh" . "src shell")) + (add-to-list 'org-structure-template-alist '("b" . "src shell")) + (add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp")) + (add-to-list 'org-structure-template-alist '("py" . "src python")) + + ;;Auto tangle + (add-hook 'org-mode-hook 'org-auto-tangle-mode) #+end_src * Markdown ** Theme @@ -618,14 +981,38 @@ If it's a mac, load from homebrew path (delete-char sgml-basic-offset))))) #+end_src * Elfeed - +** Feeds +#+begin_src emacs-lisp +(require 'elfeed) +(require 'elfeed-goodies) + +(setq elfeed-feeds (quote + ( + ("https://hackaday.com/blog/feed/" hackaday linux) + ("https://opensource.com/feed" opensource linux) + ("https://linux.softpedia.com/backend.xml" softpedia linux) + ("https://www.thelancet.com/rssfeed/lancet_current.xml" Lancet lancet) + ("https://www.thelancet.com/rssfeed/lancet_online.xml" LancetOnline lancet) + ("https://www.thelancet.com/rssfeed/lanmic_online.xml" LancetOnline Microbiology) + ("https://www.techrepublic.com/rssfeeds/topic/open-source/" techrepublic linux) + ("https://www.thanosapollo.com/public/feed.xml" Thanos) + ("https://protesilaos.com/news.xml" Protesilaos News) + ("https://protesilaos.com/codelog.xml" Proetesilaos Coding) + ("https://stallman.org/rss/rss.xml" Stallman news) + ))) +#+end_src +** Settings +#+begin_src emacs-lisp +(setq elfeed-goodies/entry-pane-size 0.5) +#+end_src * PDF #+begin_src emacs-lisp -(use-package pdf-tools - :ensure t - :mode ".pdf" - :config - (add-hook 'pdf-view-mode #'pdf-isearch-minor-mode)) + +;;Add pdf-isearch-minor-mode hook, otherwise isearch will be buggy +;;Darkmode hook, cause I don't want color or light in my life, I'm a vampire. +(add-hook 'pdf-view-mode-hook 'pdf-isearch-minor-mode) +(add-hook 'pdf-view-mode-hook 'pdf-view-midnight-minor-mode) +(add-to-list 'auto-mode-alist '("\\.pdf\\'" . pdf-view-mode)) #+end_src * Telega In ~GuixSD~ systems I have telegram installed via guix, and it's loaded via ~guix-emacs-autoload-packages~ @@ -911,10 +1298,11 @@ you have the correctly set the OPENAI_API_KEY variable" (start-process-shell-command "polybar" nil "polybar main"))) #+end_src -* TODO EXWM -TODO: tangle with .exwm.el & organize +* EXWM +EXWM configuration is tangled with ~.exwm~ ++ In GuixSD ~emacs-exwm~ package will look for ~~/.exwm~ -#+begin_src emacs-lisp +#+begin_src emacs-lisp :tangle ../.exwm.el (defun apollo/exwm-init-hook () "Do this upon start." (if (string= (system-name) "fsociety") ;; Check if it's my desktop, otherwise display battery @@ -1053,10 +1441,5 @@ TODO: tangle with .exwm.el & organize (exwm-enable) - -;;Transparency -(set-frame-parameter (selected-frame) 'alpha '(90 90)) -(add-to-list 'default-frame-alist '(alpha 90 90)) - #+end_src -- cgit v1.2.3 From f2ac9d5f8bcb91a01e0e313faba4205c31824a15 Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 10 Feb 2023 04:57:40 +0200 Subject: emacs: Tangle files --- .emacs.d/init.el | 1093 +++++++++++++++++++++++++++++++++++++++++------------- .exwm.el | 8 - 2 files changed, 835 insertions(+), 266 deletions(-) (limited to '.emacs.d') diff --git a/.emacs.d/init.el b/.emacs.d/init.el index da8e000..531c460 100644 --- a/.emacs.d/init.el +++ b/.emacs.d/init.el @@ -1,40 +1,12 @@ -;; init.el - -;;; Code: - -(require 'package) -(add-to-list 'load-path "~/dotfiles/.emacs.d/snippets") - -(add-to-list 'load-path "~/dotfiles") - - -(setq custom-file (concat user-emacs-directory "/custom.el")) - - - -;; Check if system-name is one of my guix systems -;; Change this strings to your machines $HOSTNAME -;; if you are using guix (when (or (string= (system-name) "fsociety") (string= (system-name) "heisenberg")) (add-to-list 'load-path "~/.guix-profile/share/emacs/site-lisp") (guix-emacs-autoload-packages)) - - -(setq package-archives '(("melpa" . "https://melpa.org/packages/") - ("org" . "https://orgmode.org/elpa/") - ("elpa" . "https://elpa.gnu.org/packages/"))) - -(setq browse-url-browser-function 'eww-browse-url) - -(package-initialize) -(unless package-archive-contents - (package-refresh-contents)) - -;; Request packages: (defconst my-package-list '(org-snooze all-the-icons + all-the-icons-dired + all-the-icons-ivy-rich general doom-themes doom-modeline @@ -42,7 +14,6 @@ which-key ivy ivy-rich - all-the-icons-ivy-rich helpful org org-modern @@ -75,7 +46,16 @@ eshell-syntax-highlighting pdf-tools org-superstar - mastodon)) + mastodon + dashboard + org-auto-tangle)) + +(setq package-archives '(("melpa" . "https://melpa.org/packages/") + ("org" . "https://orgmode.org/elpa/") + ("elpa" . "https://elpa.gnu.org/packages/"))) +(package-initialize) +(unless package-archive-contents + (package-refresh-contents)) (defvar my-missing-packages '() "List populated at each startup. @@ -97,29 +77,11 @@ Contains the list of packages that need to be installed.") (unless (package-installed-p 'use-package) (package-install 'use-package)) -(require 'use-package) -(setq use-package-always-ensure t) -(load "functions") -(load "email-module") -(load "keys.el") -(load "all-the-icons-dired.el") -;;(load "secret") -;;(load "org-config") -(load-file custom-file) ;; Load custom.el - -;; if you are using guix, emacs-exwm will look for ~/.exwm.el - (setq inhibit-startup-message nil) - ;; Transparency (set-frame-parameter (selected-frame) 'alpha '(90 90)) (add-to-list 'default-frame-alist '(alpha 90 90)) -;; UI settings -(defvar apollo/default-font-size 140) - -(set-face-attribute 'default nil :font "JetBrains Mono" :height 130) - (add-hook 'dired-mode-hook 'all-the-icons-dired-mode) (scroll-bar-mode -1) @@ -129,23 +91,8 @@ Contains the list of packages that need to be installed.") (menu-bar-mode -1) (blink-cursor-mode -1) (menu-bar--visual-line-mode-enable) -;;Visible bell -(setq visible-bell t) - - - -(use-package vterm - :ensure nil - :config - ;; Check if it's one of my guix systems to load from - ;; ~/.guix-profile. Otherwise we use /bin/zsh. - (if - (or (string= (system-name) "fsociety") - (string= (system-name) "heisenberg")) - (setq vterm-shell "~/.guix-profile/bin/zsh") - (setq vterm-shell "/bin/zsh"))) - +(setq visible-bell t) (column-number-mode) (global-display-line-numbers-mode 0) @@ -160,6 +107,8 @@ Contains the list of packages that need to be installed.") elfeed)) (add-hook mode (lambda () (display-line-numbers-mode 0)))) +(defvar apollo/default-font-size 140) + (set-face-attribute 'default nil :font "JetBrains Mono" :height apollo/default-font-size) @@ -173,15 +122,15 @@ Contains the list of packages that need to be installed.") :height apollo/default-font-size :weight 'regular) -;; Dashboard settings (require 'dashboard) (require 'all-the-icons) (dashboard-setup-startup-hook) (setq dashboard-items '((recents . 5) - (bookmarks . 5))) -(setq initial-buffer-choice (lambda () (get-buffer-create "*dashboard*"))) -(setq dashboard-item-names '(("Recent Files:" . "Recent Files:") + (bookmarks . 5))) + +(setq initial-buffer-choice (lambda () (get-buffer-create "*dashboard*")) + dashboard-item-names '(("Recent Files:" . "Recent Files:") ("Bookmarks:" . "Study:"))) ;; Set the banner (setq dashboard-startup-banner "~/dotfiles/pictures/medicine/plague-doctor-s.png") @@ -198,35 +147,15 @@ Contains the list of packages that need to be installed.") dashboard-set-footer t dashboard-footer-messages '("Welcome to the Church Of Emacs") dashboard-footer-icon (all-the-icons-octicon "broadcast" - :height 1.15 - :v-adjust -0.05 - :face 'font-lock-keyword-face)) - -(set-face-attribute 'dashboard-items-face nil :inherit 'unspecified) - -(dashboard-refresh-buffer) - - - -(defvar eshell-path-env (getenv "~/.local/bin")) + :height 1.15 + :v-adjust -0.05 + :face 'font-lock-keyword-face)) (load-theme 'doom-ayu-dark t) (doom-modeline-mode 1) (setq doom-modeline-height 35) -;; (use-package counsel -;; :bind (("C-M-j" . 'counsel-switch-buffer) -;; :map minibuffer-local-map -;; ("C-r" . 'counsel-minibuffer-history) -;; ("C-'" . 'counsel-find-file)) -;; :config -;; (counsel-mode 1)) - - -(which-key-mode) -(setq which-key-idle-delay 0.5) - (use-package ivy :diminish :bind (("C-s" . swiper) @@ -249,7 +178,6 @@ Contains the list of packages that need to be installed.") (ivy-rich-mode 1) (all-the-icons-ivy-rich-mode 1) - (use-package helpful :custom (counsel-describe-function-function #'helpful-callable) @@ -260,42 +188,538 @@ Contains the list of packages that need to be installed.") ([remap describe-variable] . counsel-describe-variable) ([remap describe-key] . helpful-key)) -;; (use-package smart-cursor-color -;; :config -;; (smart-cursor-color-mode -1)) +(define-key dired-mode-map "b" 'dired-up-directory) + +;;; all-the-icons-dired.el --- Shows icons for each file in dired mode -*- lexical-binding: t; -*- + +;;; Code: -;; Make ESC quit prompts - (global-set-key (kbd "") 'keyboard-escape-quit) +(require 'cl-lib) +(require 'dired) +(require 'all-the-icons) -(define-prefix-command 'window) +(defface all-the-icons-dired-dir-face + '((((background dark)) :foreground "white") + (((background light)) :foreground "black")) + "Face for the directory icon" + :group 'all-the-icons-faces) + +(defcustom all-the-icons-dired-v-adjust 0.01 + "The default vertical adjustment of the icon in the dired buffer." + :group 'all-the-icons + :type 'number) + +(defvar all-the-icons-dired-mode) + +(defun all-the-icons-dired--add-overlay (pos string) + "Add overlay to display STRING at POS." + (let ((ov (make-overlay (1- pos) pos))) + (overlay-put ov 'all-the-icons-dired-overlay t) + (overlay-put ov 'after-string string))) + +(defun all-the-icons-dired--overlays-in (beg end) + "Get all all-the-icons-dired overlays between BEG to END." + (cl-remove-if-not + (lambda (ov) + (overlay-get ov 'all-the-icons-dired-overlay)) + (overlays-in beg end))) + +(defun all-the-icons-dired--overlays-at (pos) + "Get all-the-icons-dired overlays at POS." + (apply #'all-the-icons-dired--overlays-in `(,pos ,pos))) + +(defun all-the-icons-dired--remove-all-overlays () + "Remove all `all-the-icons-dired' overlays." + (save-restriction + (widen) + (mapc #'delete-overlay + (all-the-icons-dired--overlays-in (point-min) (point-max))))) + +(defun all-the-icons-dired--refresh () + "Display the icons of files in a dired buffer." + (all-the-icons-dired--remove-all-overlays) + (save-excursion + (goto-char (point-min)) + (while (not (eobp)) + (when (dired-move-to-filename nil) + (let ((file (dired-get-filename 'relative 'noerror))) + (when file + (let ((icon (if (file-directory-p file) + (all-the-icons-icon-for-dir file + :face 'all-the-icons-dired-dir-face + :v-adjust all-the-icons-dired-v-adjust) + (all-the-icons-icon-for-file file :v-adjust all-the-icons-dired-v-adjust)))) + (if (member file '("." "..")) + (all-the-icons-dired--add-overlay (point) " \t") + (all-the-icons-dired--add-overlay (point) (concat icon "\t"))))))) + (forward-line 1)))) + +(defun all-the-icons-dired--refresh-advice (fn &rest args) + "Advice function for FN with ARGS." + (apply fn args) + (when all-the-icons-dired-mode + (all-the-icons-dired--refresh))) + +(defun all-the-icons-dired--setup () + "Setup `all-the-icons-dired'." + (when (derived-mode-p 'dired-mode) + (setq-local tab-width 1) + (advice-add 'dired-readin :around #'all-the-icons-dired--refresh-advice) + (advice-add 'dired-revert :around #'all-the-icons-dired--refresh-advice) + (advice-add 'dired-internal-do-deletions :around #'all-the-icons-dired--refresh-advice) + (advice-add 'dired-insert-subdir :around #'all-the-icons-dired--refresh-advice) + (advice-add 'dired-do-kill-lines :around #'all-the-icons-dired--refresh-advice) + (with-eval-after-load 'dired-narrow + (advice-add 'dired-narrow--internal :around #'all-the-icons-dired--refresh-advice)) + (all-the-icons-dired--refresh))) + +(defun all-the-icons-dired--teardown () + "Functions used as advice when redisplaying buffer." + (advice-remove 'dired-readin #'all-the-icons-dired--refresh-advice) + (advice-remove 'dired-revert #'all-the-icons-dired--refresh-advice) + (advice-remove 'dired-internal-do-deletions #'all-the-icons-dired--refresh-advice) + (advice-remove 'dired-narrow--internal #'all-the-icons-dired--refresh-advice) + (advice-remove 'dired-insert-subdir #'all-the-icons-dired--refresh-advice) + (advice-remove 'dired-do-kill-lines #'all-the-icons-dired--refresh-advice) + (all-the-icons-dired--remove-all-overlays)) + +;;;###autoload +(define-minor-mode all-the-icons-dired-mode + "Display all-the-icons icon for each files in a dired buffer." + :lighter " all-the-icons-dired-mode" + (when (and (derived-mode-p 'dired-mode) (display-graphic-p)) + (if all-the-icons-dired-mode + (all-the-icons-dired--setup) + (all-the-icons-dired--teardown)))) +(add-hook 'dired-mode-hook 'all-the-icons-dired-mode) +(use-package vterm + :ensure nil + :config + ;; Check if it's one of my guix systems to load from + ;; ~/.guix-profile. Otherwise we use /bin/zsh. + (if + (or (string= (system-name) "fsociety") + (string= (system-name) "heisenberg")) + (setq vterm-shell "~/.guix-profile/bin/zsh") + (setq vterm-shell "/bin/zsh"))) +(use-package eshell + :ensure t + :bind (("C-c e" . 'eshell)) + :config + (defvar eshell-path-env (getenv "~/.local/bin"))) + +(defun with-face (str &rest face-plist) + (propertize str 'face face-plist)) + +(defun apollo-eshell-prompt () + (let ((winter-blue "#3F3B6C") + (white-summer "#E5E5CB") + (green-night "#03C988") + (orange-summer "#FFB100") + (green-summer "#A3BB98") + (summer-sea "#2192FF") + (black "#000000")) + (concat + (with-face (concat "[" user-login-name) :foreground orange-summer :background black) + (with-face "@" :foreground orange-summer :background black) + (with-face (concat system-name "]\n") :foreground orange-summer :background black) + (with-face (concat "|" (eshell/pwd) ) :foreground "#F0E9D2" :background winter-blue) + (with-face (format-time-string " | %H:%M" (current-time)) :background winter-blue :foreground "#888") + (with-face "\n -> ")))) + +(setq eshell-prompt-function 'apollo-eshell-prompt) +(setq eshell-highlight-prompt t) + +(global-set-key (kbd "") 'keyboard-escape-quit) + +(defun apollo/html-boostrap-boilerplate () + "Insert html boilerplate with boostrap link." + (interactive) + (insert +" + + + + + + My Title + + + + +
+

Starting point

+
+ + +" )) + + +(defun apollo/center-buffer () + "Centers/Uncenters selected buffer" + (interactive) + (if visual-fill-column-center-text + (setq visual-fill-column-center-text nil) + (setq visual-fill-column-center-text t)) + (visual-fill-column-mode 1) + (message "General's task completed!")) + + +(defun apollo/rofi-switch-window () + "Navigate X11 buffers using rofi." + (interactive) + (start-process-shell-command + "rofi" nil "rofi -show window")) + +(defun apollo/run-in-background (command) + "Run COMMAND in the background." + (let ((command-parts (split-string command "[ ]+"))) + (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts))))) + +(defun rofi () + "Run Rofi." + (interactive) + (apollo/run-in-background "rofi -show drun")) + +(defun apollo/volume-increase () + "Increase Volume." + (interactive) + (start-process-shell-command + "amixer" nil "amixer sset Master 5%+")) + +(defun apollo/volume-decrease () + "Decrease Volume." + (interactive) + (start-process-shell-command + "amixer" nil "amixer sset Master 5%-")) + +(defun apollo/restore-wallpaper () + "Set NAME as wallpaper." + (interactive) + (start-process-shell-command + "feh" nil "feh --bg-scale ~/dotfiles/wallpaper.png")) + +(defun apollo/emacs-keys () + "Swap caps with ctrl." + (interactive) + (start-process-shell-command + "setxkbmap" nil "setxkbmap us -option ctrl:swapcaps")) + +(defun apollo/greek-keyboard () + "Swap caps with ctrl." + (interactive) + (start-process-shell-command + "setxkbmap" nil "setxkbmap gr")) + +(defun apollo/exwm-init-hook () + "Do this upon start." + (display-battery-mode 0) ;;Change to 1 to display battery + + (setq display-time-day-and-date t) + (display-time-mode 1) + + ;;Launch apps that will run in the background +;; (apollo/run-in-background "blueman-applet") + (apollo/run-in-background "picom") +;; (apollo/run-in-background "nm-applet") + (apollo/emacs-keys) + (apollo/set-wallpaper) + (start-polybar) + ) + +(defun apollo/exwm-update-class () + (exwm-workspace-rename-buffer exwm-class-name)) + +(defun eshell-new() + "Open a new instance of eshell." + (interactive) + (eshell 'N)) + +(defun make-mini-buffer () + (interactive) + (split-window-below 40) + (other-window 1)) + +(defun make-mini-geiser () + (interactive) + (split-window-below 60) + (geiser nil)) + +(defun start-polybar () + "Check which system is running, start polybar accordingly." + (interactive) + (if (string= (system-name) "fsociety") + (start-process-shell-command + "polybar" nil "polybar main & polybar second") + (start-process-shell-command + "polybar" nil "polybar main"))) -;;; Developer +(when (equal system-type 'darwin) + (use-package mu4e + :load-path "/opt/homebrew/share/emacs/site-lisp/mu/mu4e/")) + +(require 'mu4e) + +(setq mu4e-update-interval (* 10 60)) +(setq mu4e-get-mail-command "mbsync -a") +(setq mu4e-maildir-list "~/Mail/Inbox") + +(defun set-mu4e-context (context-name full-name mail-address signature server) + "Return a mu4e context named CONTEXT-NAME with :match-func matching + folder name CONTEXT-NAME in Maildir. The context's `user-mail-address', + `user-full-name' and `mu4e-compose-signature'`smtpmail-smpt-server' is set to MAIL-ADDRESS + FULL-NAME SIGNATURE and SERVER respectively. + Special folders are set to context specific folders." + (let ((dir-name (concat "/" context-name))) + (make-mu4e-context + :name context-name + ;; we match based on the maildir of the message + :match-func + `(lambda (msg) + (when msg + (string-match-p + ,(concat "^" dir-name) + (mu4e-message-field msg :maildir)))) + :vars + `((user-mail-address . ,mail-address) + (user-full-name . ,full-name) + (mu4e-sent-folder . ,(concat dir-name "/Sent")) + (mu4e-drafts-folder . ,(concat dir-name "/Drafts")) + (mu4e-trash-folder . ,(concat dir-name "/Trash")) + (mu4e-trash-folder . ,(concat dir-name "/Starred")) + (mu4e-refile-folder . ,(concat dir-name "/Archive")) + (smtpmail-smtp-service . ,465) + (smtpmail-smtp-server . ,server) + (mu4e-compose-signature . ,signature))))) +;;Fixing duplicate UID errors when using mbsync and mu4e +(setq mu4e-change-filenames-when-moving t) + +(setq mu4e-maildir-shortcuts + '(("/Fastmail/Inbox" . ?i) + ("/Fastmail/Sent" . ?s) + ;; ("/Gmail/Trash" . ?t) + ;; ("/Gmail/Drafts" . ?d) + ;; ("/Gmail/[Gmail]/All Mail" . ?a + )) + +(setq mu4e-contexts + `(, (set-mu4e-context + "Fastmail" "Thanos Apollo" + "thanos@thanosapollo.com" "Thanos\nhttps://thanosapollo.com/public" + "smtp.fastmail.com"))) + +;; (setq smtpmail-smtp-service 465 +;; smtpmail-stream-type 'ssl +;; smtpmail-smtp-server "smtp.fastmail.com") + + + +(setq message-send-mail-function 'smtpmail-send-it + smtpmail-stream-type 'ssl) + +;; my general's leader key! +(defconst general-key "C-c g") + +(general-create-definer general-does + :prefix general-key) + +;; Basic functions +(general-define-key + "C-d" 'kill-region + "C-k" 'copy-region-as-kill + "C-c v" 'multi-vterm-next + "C-x 9" 'make-mini-buffer + "C-c l e" 'apollo/emacs-keys + ;;Change keyboard layouts/language + "C-c l g" 'apollo/greek-keyboard + "C-κ" 'apollo/emacs-keys + "C-x C-b" 'ibuffer) + + + +;; My Generals does: +(general-does + "t" 'counsel-load-theme + "l" 'display-line-numbers-mode + "v" 'multi-vterm-next + "e" 'eshell + "i" 'circe + "c" 'apollo/center-buffer + "m" 'mu4e + "f" 'elfeed + "C-t" 'telega) + +;;pdf-tools +(general-define-key + :keymaps 'pdf-view-mode-map + "C-c d" 'pdf-view-midnight-minor-mode + "C-s" 'isearch-forward + "C-o" 'pdf-isearch-occur) + +;;vterm +(general-does + :keymaps 'vterm-mode-map + "n" 'multi-vterm-next + "o" 'multi-vterm + "p" 'multi-vterm-prev) + +(general-does + :keymaps 'eshell-mode-map + "n" 'eshell-new) + +(general-does + :keymaps 'org-mode-map + "3" 'org-insert-image-size-300) + +(defhydra hydra-zoom (global-map "s-z") + "zoom" + ("=" text-scale-increase "in") + ("-" text-scale-decrease "out")) + +(add-hook 'org-mode-hook 'org-make-toc-mode) + +(defun apollo/org-theme-dracula () + "Enable Dracula theme for Org headers." + (interactive) + (dolist + (face + '((org-level-1 1.7 "#8be9fd" extra-bold) + (org-level-2 1.6 "#bd93f9" extra-bold) + (org-level-3 1.5 "#50fa7b" bold) + (org-level-4 1.4 "#ff79c6" semi-bold) + (org-level-5 1.3 "#9aedfe" normal) + (org-level-6 1.2 "#caa9fa" normal) + (org-level-7 1.1 "#5af78e" normal) + (org-level-8 1.0 "#ff92d0" normal))) + (set-face-attribute (nth 0 face) nil + :font "JetBrains Mono" + :weight (nth 3 face) + :height (nth 1 face) + :foreground (nth 2 face))) + (set-face-attribute 'org-table nil + :font "JetBrains Mono" + :weight 'normal + :height 1.0 + :foreground "#bfafdf")) + +(defun apollo/org-theme-darkone () + "Enable Darkone theme for Org headers." + (interactive) + (dolist + (face + '((org-level-1 1.70 "#51afef" bold) + (org-level-2 1.55 "#7FBCD2" bold) + (org-level-3 1.40 "#da8548" bold) + (org-level-4 1.20 "#da8548" semi-bold) + (org-level-5 1.20 "#5699af" normal) + (org-level-6 1.20 "#a9a1e1" normal) + (org-level-7 1.10 "#46d9ff" normal) + (org-level-8 1.00 "#ff6c6b" normal))) + (set-face-attribute (nth 0 face) nil + :font "Jetbrains Mono" + :weight (nth 3 face) + :height (nth 1 face) + :foreground (nth 2 face))) + (set-face-attribute 'org-table nil + :font "Jetbrains Mono" + :weight 'normal + :height 1.0 + :foreground "#A66CFF")) + +(setq org-directory "~/org/" + org-agenda-files '("~/org/agenda.org") + org-default-notes-file (expand-file-name "notes.org" org-directory) + org-ellipsis " ▼ " + org-log-done 'time + org-hide-emphasis-markers nil ;;change to t to hide emphasis markers + org-table-convert-region-max-lines 20000 + org-agenda-start-log-mode t + org-log-done 'time + org-log-into-drawer t + org-indent-mode t + org-todo-keywords ;; This overwrites the default Doom org-todo-keywords + '((sequence + "TODO(t)" ;; A task that is ready to be tackled + "BLOG(b)" ;; Blog writing assignments + "GYM(g)" ;; Things to accomplish at the gym + "WAIT(w)" ;; Something is holding up this task + "|" ;; The pipe necessary to separate "active" states and "inactive" states + "DONE(d)" ;; Task has been completed + "CANCELLED(c)" )) + org-superstar-headline-bullets-list '("◉" "●" "○" "●" "○" "●" "◆") + org-superstar-itembullet-alist '((?+ . ?➤) (?- . ?✦))) ;; changes +/- symbols in item lists) + +;; Hooks +(add-hook 'org-mode-hook 'apollo/org-theme-dracula) +(add-hook 'org-mode-hook 'org-superstar-mode) +(add-hook 'org-mode-hook 'flyspell-mode) + +(org-babel-do-load-languages + 'org-babel-load-languages + '((emacs-lisp . t) + (python . t))) + +(add-to-list 'org-structure-template-alist '("sh" . "src shell")) +(add-to-list 'org-structure-template-alist '("b" . "src shell")) +(add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp")) +(add-to-list 'org-structure-template-alist '("py" . "src python")) + +;;Auto tangle +(add-hook 'org-mode-hook 'org-auto-tangle-mode) + +(defun apollo/markdown-theme () + (interactive) + (dolist + (face + '(markdown-header-face-1 :height 2.0)))) + +(setq markdown-header-scaling t) + + +(use-package markdown-mode + :ensure t + :mode (".md" . gfm-mode) + :init (setq markdown-command "multimarkdown")) -;;Essentials (electric-pair-mode 1) -(setq sgml-quick-keys nil) +(global-flycheck-mode) + +(use-package company + :after lsp-mode + :hook (lsp-mode . company-mode) + :bind (:map company-active-map + ("" . company-complete-selection)) + (:map lsp-mode-map + ("" . company-indent-or-complete-common)) + :custom + (company-minimum-prefix-length 1) + (company-idle-delay 0.0)) + +(use-package dap-mode + :custom + (lsp-enable-dap-auto-configure nil) + :config + (dap-ui-mode 1)) + +(use-package company-box + :hook (company-mode . company-box-mode)) +(use-package magit + :custom + (magit-display-buffer-function #'magit-display-buffer-same-window-except-diff-v1)) -;;emacs-lisp (setq tab-always-indent 'complete) (add-to-list 'completion-styles 'initials t) (add-hook 'emacs-lisp-mode-hook #'rainbow-delimiters-mode) (add-hook 'scheme-mode-hook #'rainbow-delimiters-mode) - -;;instal flyckeck -(global-flycheck-mode) -;;Enable globally - - -;;setup lsp-mode - (defun apollo/lsp-mode-setup () - (setq lsp-headerline-breadcrumb-segments '(path-up-to-project file symbols)) - (lsp-headerline-breadcrumb-mode)) +(defun apollo/lsp-mode-setup () + (setq lsp-headerline-breadcrumb-segments '(path-up-to-project file symbols)) + (lsp-headerline-breadcrumb-mode)) (use-package lsp-mode :commands (lsp lsp-deferred) @@ -304,39 +728,30 @@ Contains the list of packages that need to be installed.") (setq lsp-keymap-prefix "C-c l") ;; Or 'C-l', 's-l' :config (lsp-enable-which-key-integration t) - (setq lsp-pyls-server-command "~/.local/bin/pylsp") - ) + (setq lsp-pyls-server-command "~/.local/bin/pylsp")) (use-package lsp-ui :hook (lsp-mode . lsp-ui-mode) :custom (lsp-ui-doc-position 'bottom)) -;; (use-package dap-node) -;; (use-package dap-mode -;; ;; Uncomment the config below if you want all UI panes to be hidden by default! -;; ;; :custom -;; ;; (lsp-enable-dap-auto-configure nil) -;; ;; :config -;; ;; (dap-ui-mode 1) - -;; :config -;; ;; Set up Node debugging -;; (require 'dap-node) -;; (dap-node-setup) ;; Automatically installs Node debug adapter if needed - -;; ;; Bind `C-c l d` to `dap-hydra` for easy access -;; (general-define-key -;; :keymaps 'lsp-mode-map -;; :prefix lsp-keymap-prefix -;; "d" '(dap-hydra t :wk "debugger"))) +(use-package python-mode + :ensure t + :mode ".py" + :hook (python-mode . lsp-deferred) + :custom + (dap-python-debugger 'debugpy) + :config + (require 'dap-python)) +(use-package pyvenv + :config + (pyvenv-mode 1)) (use-package json-mode :mode ".json" :hook (json-mode . lsp-deferred)) - (use-package rjsx-mode :mode ".js" :hook (rjsx-mode . lsp-deferred) @@ -348,139 +763,32 @@ Contains the list of packages that need to be installed.") (if (looking-at-p "^ +\/?> *$") (delete-char sgml-basic-offset))))) -;; (use-package ac-html -;; :mode ".html" -;; :hook (html-mode . lsp-deferred) -;; :config -;; (defadvice js-jsx-indent-line (after js-jsx-indent-line-after-hack activate) -;; "Workaround sgml-mode and follow airbnb component style." -;; (save-excursion -;; (beginning-of-line) -;; (if (looking-at-p "^ +\/?> *$") -;; (delete-char sgml-basic-offset))))) - -(use-package typescript-mode - :mode ".ts'" - :hook (typescript-mode .lsp-deferred) - :config - (setq typescript-indent-level 2)) - -(use-package python-mode - :ensure t - :mode ".py" - :hook (python-mode . lsp-deferred) - :custom - (dap-python-debugger 'debugpy) - :config - (require 'dap-python)) - -;;autocomplete - - ;;Pyenv -(use-package pyvenv - :config - (pyvenv-mode 1)) - -(use-package company - :after lsp-mode - :hook (lsp-mode . company-mode) - :bind (:map company-active-map - ("" . company-complete-selection)) - (:map lsp-mode-map - ("" . company-indent-or-complete-common)) - :custom - (company-minimum-prefix-length 1) - (company-idle-delay 0.0)) - -(use-package company-box - :hook (company-mode . company-box-mode)) - -(use-package magit - :custom - (magit-display-buffer-function #'magit-display-buffer-same-window-except-diff-v1)) - - - -;;elfeed (require 'elfeed) (require 'elfeed-goodies) + (setq elfeed-feeds (quote ( ("https://hackaday.com/blog/feed/" hackaday linux) ("https://opensource.com/feed" opensource linux) ("https://linux.softpedia.com/backend.xml" softpedia linux) - ("https://www.thelancet.com/rssfeed/ebiom_current.xml" Lancet ebiom) ("https://www.thelancet.com/rssfeed/lancet_current.xml" Lancet lancet) - ("https://www.thelancet.com/rssfeed/ebiom_online.xml" LancetOnline ebiom) ("https://www.thelancet.com/rssfeed/lancet_online.xml" LancetOnline lancet) ("https://www.thelancet.com/rssfeed/lanmic_online.xml" LancetOnline Microbiology) ("https://www.techrepublic.com/rssfeeds/topic/open-source/" techrepublic linux) ("https://www.thanosapollo.com/public/feed.xml" Thanos) ("https://protesilaos.com/news.xml" Protesilaos News) ("https://protesilaos.com/codelog.xml" Proetesilaos Coding) + ("https://stallman.org/rss/rss.xml" Stallman news) ))) - -(elfeed-goodies/setup) (setq elfeed-goodies/entry-pane-size 0.5) -;; (use-package vterm -;; :config -;; (setq vterm-shell "/bin/zsh") -;; :bind(("C-c C-v c" . 'vterm-send-stop))) - -(use-package eshell - :ensure t - :bind (("C-c e" . 'eshell))) - +;;Add pdf-isearch-minor-mode hook, otherwise isearch will be buggy +;;Darkmode hook, cause I don't want color or light in my life, I'm a vampire. +(add-hook 'pdf-view-mode-hook 'pdf-isearch-minor-mode) +(add-hook 'pdf-view-mode-hook 'pdf-view-midnight-minor-mode) +(add-to-list 'auto-mode-alist '("\\.pdf\\'" . pdf-view-mode)) -(add-hook 'pdf-view-mode #'pdf-isearch-minor-mode) - - -(define-key dired-mode-map "b" 'dired-up-directory) - -(put 'downcase-region 'disabled nil) -(put 'dired-find-alternate-file 'disabled nil) -(put 'set-goal-column 'disabled nil) - -;; (use-package treemacs-icons-dired -;; :config -;; (add-hook 'dired-mode-hook 'treemacs-icons-dired-mode)) - -(use-package sudo-edit) - - -(use-package consult - :ensure t - :bind(("M-g g" . consult-goto-line))) - -(use-package alsamixer - :ensure t) - -(use-package simple-httpd - :ensure t) - -(use-package circe - :ensure t - :config - (setq circe-network-options - '(("Libera Chat" - :tls t - :nick "apo11o" - :sasl-username "apo11o" - :sasl-password libera-pass)))) - -(use-package eshell-syntax-highlighting - :ensure t - :config - (eshell-syntax-highlighting-global-mode)) - -(use-package pdf-tools - :ensure t - :mode ".pdf") - -;; Check if it's my macbook, if t -;; load tdlib from homebrew (when (equal system-type 'darwin) (use-package telega :load-path "~/telega.el" @@ -489,12 +797,281 @@ Contains the list of packages that need to be installed.") :config (setq telega-server-libs-prefix "/opt/homebrew/Cellar/tdlib/HEAD-3d0140b"))) - -;;mastodon -(setq mastodon-instance-url "https://emacs.ch" - mastodon-active-user "apo11o") - - - -(server-start) - +(require 'seq) +(eval-when-compile + (require 'cl-lib) + (require 'subr-x) + (require 'env) + (require 'json)) +(defgroup chatgpt nil + "ChatGPT frontend." + :group 'convenience + :prefix "chatgpt-") +(defcustom chatgpt-max-tokens 300 + "Upper limit on the number of tokens the API will return." + :type 'integer) +(defvar chatgpt-buffer "*ChatGPT*" + "Title of the buffer used to store the results of an OpenAI API query.") +(define-error 'chatgpt-error "An error related to the ChatGPT emacs package") +(define-error 'chatgpt-parsing-error + "An error caused by a failure to parse an OpenAI API Response") +(defmacro chatgpt-show-results-buffer-if-active () + "Show the results in other window if necessary." + `(if (and (not ;; visible + (get-buffer-window chatgpt-buffer)) + (called-interactively-p 'interactive)) + (lambda (&optional buf) (ignore buf) + (with-current-buffer buf + (view-mode t)) + (switch-to-buffer-other-window chatgpt-buffer)) + #'identity)) +;;;###autoload +(defun chatgpt-prompt (prompt callback) + "Query OpenAI with PROMPT calling the CALLBACK function on the resulting buffer. +Returns buffer containing the text from this query" + (interactive (list (read-string "Prompt ChatGPT with: ") + (lambda (buf) (with-current-buffer buf + (view-mode t)) + (switch-to-buffer-other-window chatgpt-buffer)))) + (chatgpt--query-open-api prompt + (lambda (results) + (with-current-buffer (get-buffer-create chatgpt-buffer) + ;; Erase contents of buffer after receiving response + (read-only-mode -1) + (erase-buffer) + (insert results) + ;; Return the chatgpt output buffer for non interactive usage + (funcall callback (current-buffer)))))) +;;;###autoload +(defun chatgpt-fix-region (BEG END) + "Takes a region BEG to END asks ChatGPT to explain whats wrong with it. +It then displays the answer in the `chatgpt-buffer'." + (interactive "r") + (let ((current-code (buffer-substring BEG END))) + (chatgpt-prompt (chatgpt--append-to-prompt + current-code + "Why doesn't this code work?") + (chatgpt-show-results-buffer-if-active)))) +;;;###autoload +(defun chatgpt-explain-region (BEG END) + "Takes a region BEG to END asks ChatGPT what it does. +The answer in the displays in `chatgpt-buffer'." + (interactive "r") + (let ((current-code (buffer-substring BEG END))) + (chatgpt-prompt (chatgpt--append-to-prompt + current-code + "What does this code do?") + (chatgpt-show-results-buffer-if-active)))) +;;;###autoload +(defun chatgpt-gen-tests-for-region (BEG END) + "Takes a region BEG to END asks ChatGPT to write a test for it. +It then displays the answer in the `chatgpt-buffer'." + (interactive "r") + (let ((current-code (buffer-substring BEG END))) + (chatgpt-prompt (chatgpt--append-to-prompt + current-code + "Write me a tests for this code") + (chatgpt-show-results-buffer-if-active)))) +;; TODO currently just says what changed but doesn't wanna show the code it's self +;; (defun chatgpt-optimize-region (BEG END) +;; "Takes a region BEG to END asks ChatGPT to optimize it for speed. +;; It then displays the answer in the `chatgpt-buffer'." +;; (interactive "r") +;; (let ((current-code (buffer-substring BEG END))) +;; (chatgpt-prompt (chatgpt--append-to-prompt +;; current-code +;; "Refactor this code for speed and tell me what you changed and why it's faster") +;; (chatgpt-show-results-buffer-if-active)))) +;;;###autoload +(defun chatgpt-refactor-region (BEG END) + "Takes a region BEG to END asks ChatGPT refactor it. +It then displays the answer in the `chatgpt-buffer'." + (interactive "r") + (let ((current-code (buffer-substring BEG END))) + (chatgpt-prompt (chatgpt--append-to-prompt + current-code + "Refactor this code and tell me what you changed") + (chatgpt-show-results-buffer-if-active)))) +;;;###autoload +(defun chatgpt-prompt-region (BEG END) + "Prompt ChatGPT with the region BEG END. +It then displays the results in a separate buffer `chatgpt-buffer'." + (interactive "r") + (chatgpt-prompt (buffer-substring BEG END) + ;; Show the results if not already being viewed + (chatgpt-show-results-buffer-if-active))) +;;;###autoload +(defun chatgpt-prompt-region-and-replace (BEG END) + "Replace region from BEG to END with the response from the ChatGPT API. +The region is BEG and until END" + (interactive "r") + (let ((og-buf (current-buffer))) + (chatgpt-prompt (buffer-substring BEG END) + (lambda (buf) + (save-excursion + (with-current-buffer og-buf + (delete-region BEG END) + (goto-char BEG) + (insert (with-current-buffer buf (buffer-string))))))))) +(defun chatgpt--append-to-prompt (prompt comment-str) + "Append the string COMMENT-STR extra information to a PROMPT as a comment." + (concat prompt + "\n" + comment-start + " " + comment-str)) +(defun chatgpt--extract-text-from-query (query-result) + "Extract the resulting text from a given OpenAI response QUERY-RESULT." + (condition-case err + (thread-last query-result + (assoc-default 'choices) + seq-first + (assoc-default 'text) + string-trim) + (error + (signal 'chatgpt-parsing-error err)))) +(defun chatgpt--parse-response (status callback) + "Ignoring STATUS and parse the response executing the CALLBACK function on the resulting string." + (ignore status) + ;; All this is ran inside the buffer containing the response + (goto-char 0) + (re-search-forward "^$") + (funcall callback (chatgpt--extract-text-from-query (json-read)))) +(defun chatgpt--query-open-api (prompt callback) + "Send a string PROMPT to OpenAI API and pass the resulting buffer to CALLBACK. +The environment variable OPENAI_API_KEY is used as your API key +You can register an account here +https://beta.openai.com/docs/introduction/key-concepts" + (let* ((api-key (getenv secret-api)) + (url-request-method (encode-coding-string "POST" 'us-ascii)) + (url-request-extra-headers `(("Content-Type" . "application/json") + ("Authorization" . ,(format "Bearer %s" api-key)))) + (url-request-data (json-encode + `(("model" . "text-davinci-003") + ("prompt" . ,prompt) + ("max_tokens" . ,chatgpt-max-tokens) + ("temperature" . 0))))) + (cl-assert (not (string= "" api-key)) + t + "Current contents of the environmental variable OPENAI_API_KEY +are '%s' which is not an appropriate OpenAI token please ensure +you have the correctly set the OPENAI_API_KEY variable" + api-key) + (url-retrieve + "https://api.openai.com/v1/completions" + 'chatgpt--parse-response + (list callback)))) + +(defun apollo/html-boostrap-boilerplate () + "Insert html boilerplate with boostrap link." + (interactive) + (insert +" + + + + + + My Title + + + + +
+

Starting point

+
+ + +" )) + + +(defun apollo/center-buffer () + "Centers/Uncenters selected buffer" + (interactive) + (if visual-fill-column-center-text + (setq visual-fill-column-center-text nil) + (setq visual-fill-column-center-text t)) + (visual-fill-column-mode 1) + (message "General's task completed!")) + + +(defun apollo/rofi-switch-window () + "Navigate X11 buffers using rofi." + (interactive) + (start-process-shell-command + "rofi" nil "rofi -show window")) + +(defun apollo/run-in-background (command) + "Run COMMAND in the background." + (let ((command-parts (split-string command "[ ]+"))) + (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts))))) + +(defun rofi () + "Run Rofi." + (interactive) + (apollo/run-in-background "rofi -show drun")) + +(defun apollo/volume-increase () + "Increase Volume." + (interactive) + (start-process-shell-command + "amixer" nil "amixer sset Master 5%+")) + +(defun apollo/volume-decrease () + "Decrease Volume." + (interactive) + (start-process-shell-command + "amixer" nil "amixer sset Master 5%-")) + +(defun apollo/restore-wallpaper () + "Set NAME as wallpaper." + (interactive) + (start-process-shell-command + "feh" nil "feh --bg-scale ~/dotfiles/wallpaper.png")) + +(defun apollo/emacs-keys () + "Swap caps with ctrl." + (interactive) + (start-process-shell-command + "setxkbmap" nil "setxkbmap us -option ctrl:swapcaps")) + +(defun apollo/greek-keyboard () + "Swap caps with ctrl." + (interactive) + (start-process-shell-command + "setxkbmap" nil "setxkbmap gr")) + +(defun apollo/exwm-update-class () + (exwm-workspace-rename-buffer exwm-class-name)) + +(defun eshell-new() + "Open a new instance of eshell." + (interactive) + (eshell 'N)) + +(defun make-mini-geiser () + (interactive) + (split-window-below 60) + (geiser nil)) + +(defun start-polybar () + "Check which system is running, start polybar accordingly." + (interactive) + (if (string= (system-name) "fsociety") + (start-process-shell-command + "polybar" nil "polybar main & polybar second") + (start-process-shell-command + "polybar" nil "polybar main"))) +(custom-set-variables + ;; custom-set-variables was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + '(package-selected-packages + '(geiser-guile desktop-environment multi-vterm vertico-posframe page-break-lines dashboard notmuch mbsync mu4e-alert zone-nyan which-key weblorg typescript-mode sudo-edit simple-httpd rjsx-mode rainbow-delimiters quelpa-use-package pyvenv python-mode pelican-mode pdf-tools paredit org-superstar org-snooze org-modern org-make-toc org-auto-tangle nyan-mode monkeytype mastodon magit lsp-ui json-mode helpful guix general flycheck fireplace exwm-mff exwm-firefox-core eshell-syntax-highlighting embark elfeed-goodies ef-themes doom-themes doom-modeline dap-mode counsel corfu consult company-box circe chatgpt babel-repl alsamixer all-the-icons-ivy-rich all-the-icons-dired))) +(custom-set-faces + ;; custom-set-faces was added by Custom. + ;; If you edit it by hand, you could mess it up, so be careful. + ;; Your init file should contain only one such instance. + ;; If there is more than one, they won't work right. + ) diff --git a/.exwm.el b/.exwm.el index 92243e6..00d4514 100644 --- a/.exwm.el +++ b/.exwm.el @@ -1,7 +1,3 @@ -;;; My EΧWM configuration -;; This files loads before .emacs/init.el when used with -;; GNU Guix emacs-desktop-environment - (defun apollo/exwm-init-hook () "Do this upon start." (if (string= (system-name) "fsociety") ;; Check if it's my desktop, otherwise display battery @@ -140,7 +136,3 @@ (exwm-enable) - -;;Transparency -(set-frame-parameter (selected-frame) 'alpha '(90 90)) -(add-to-list 'default-frame-alist '(alpha 90 90)) -- cgit v1.2.3 From 332935a39c8ecf4156abeefb5e617de4d655ec3a Mon Sep 17 00:00:00 2001 From: Thanos Apollo Date: Fri, 10 Feb 2023 05:43:06 +0200 Subject: emacs: Update TOC & org-mode hooks --- .emacs.d/emacs.org | 896 +++++++++++++++++++++++------------------------------ 1 file changed, 382 insertions(+), 514 deletions(-) (limited to '.emacs.d') diff --git a/.emacs.d/emacs.org b/.emacs.d/emacs.org index dfcbcaa..c564e7f 100644 --- a/.emacs.d/emacs.org +++ b/.emacs.d/emacs.org @@ -3,17 +3,10 @@ #+auto_tangle: t #+OPTIONS: num:nil toc:nil -* Table of contents -:PROPERTIES: -:TOC: :include all -:END: -:CONTENTS: -- [[#table-of-contents][Table of contents]] +* Table of contents :TOC: - [[#setting-up-packages][Setting up Packages]] - [[#setup-for-guixsd-machines][Setup for GuixSD machines]] - [[#define-and-install-packages][Define and install packages]] - - [[#list-of-required-packages][List of required packages]] - - [[#installation--activation][Installation & activation]] - [[#ui-settings][UI Settings]] - [[#basic-ui][Basic UI]] - [[#dashboard][Dashboard]] @@ -26,25 +19,20 @@ - [[#terminals][Terminals]] - [[#vterm][Vterm]] - [[#eshell][Eshell]] -- [[#key-bindings][Key-bindings]] -- [[#functions][Functions]] -- [[#mu4e--email-configuration][mu4e | Email Configuration]] -- [[#custom-key-bindings][Custom key-bindings]] - - [[#general][General]] - - [[#hydra][Hydra]] +- [[#custom][Custom]] + - [[#chatgpt][ChatGPT]] + - [[#random-functions][Random functions]] + - [[#key-bindings][Key-bindings]] - [[#org-mode-configuration][Org-mode Configuration]] - [[#org-make-toc][org-make-toc]] - [[#themes][Themes]] - - [[#dracula][Dracula]] - - [[#darkone][Darkone]] - [[#settings][Settings]] - [[#babel][Babel]] - [[#markdown][Markdown]] - [[#theme][Theme]] - - [[#settings][Settings]] + - [[#settings-1][Settings]] - [[#programming][Programming]] - [[#essentials][Essentials]] - - [[#magit][Magit]] - [[#emacs-lisp][Emacs lisp]] - [[#lsp-mode][LSP-Mode]] - [[#python][Python]] @@ -52,14 +40,11 @@ - [[#javascript][Javascript]] - [[#elfeed][Elfeed]] - [[#feeds][Feeds]] - - [[#settings][Settings]] + - [[#settings-2][Settings]] - [[#pdf][PDF]] - [[#telega][Telega]] -- [[#custom][Custom]] - - [[#chatgpt][ChatGPT]] - - [[#random-functions][Random functions]] +- [[#mu4e--email-configuration][mu4e | Email Configuration]] - [[#exwm][EXWM]] -:END: * Setting up Packages ** Setup for GuixSD machines @@ -76,52 +61,53 @@ we use ~guix-emacs-autoload-packages~ to load emacs packages installed using gui *** List of required packages Request the following packages: #+begin_src emacs-lisp -(defconst my-package-list '(org-snooze - all-the-icons - all-the-icons-dired - all-the-icons-ivy-rich - general - doom-themes - doom-modeline - counsel - which-key - ivy - ivy-rich - helpful - org - org-modern - visual-fill-column - rainbow-delimiters - flycheck - lsp-mode - lsp-ui - json-mode - rjsx-mode - typescript-mode - python-mode - pyvenv - company - company-box - magit - elfeed - elfeed-goodies - paredit - corfu - monkeytype - sudo-edit - exwm - exwm-mff - exwm-firefox-core - consult - alsamixer - simple-httpd - circe - eshell-syntax-highlighting - pdf-tools - org-superstar - mastodon - dashboard - org-auto-tangle)) + (defconst my-package-list '(org-snooze + all-the-icons + all-the-icons-dired + all-the-icons-ivy-rich + toc-org + general + doom-themes + doom-modeline + counsel + which-key + ivy + ivy-rich + helpful + org + org-modern + visual-fill-column + rainbow-delimiters + flycheck + lsp-mode + lsp-ui + json-mode + rjsx-mode + typescript-mode + python-mode + pyvenv + company + company-box + magit + elfeed + elfeed-goodies + paredit + corfu + monkeytype + sudo-edit + exwm + exwm-mff + exwm-firefox-core + consult + alsamixer + simple-httpd + circe + eshell-syntax-highlighting + pdf-tools + org-superstar + mastodon + dashboard + org-auto-tangle)) #+end_src *** Installation & activation Set our ~package-archives~, and install our packages @@ -408,40 +394,203 @@ Hook with ~dired-mode~ #+end_src ** Eshell #+begin_src emacs-lisp -(use-package eshell - :ensure t - :bind (("C-c e" . 'eshell)) - :config - (defvar eshell-path-env (getenv "~/.local/bin"))) - -(defun with-face (str &rest face-plist) - (propertize str 'face face-plist)) - -(defun apollo-eshell-prompt () - (let ((winter-blue "#3F3B6C") - (white-summer "#E5E5CB") - (green-night "#03C988") - (orange-summer "#FFB100") - (green-summer "#A3BB98") - (summer-sea "#2192FF") - (black "#000000")) - (concat - (with-face (concat "[" user-login-name) :foreground orange-summer :background black) - (with-face "@" :foreground orange-summer :background black) - (with-face (concat system-name "]\n") :foreground orange-summer :background black) - (with-face (concat "|" (eshell/pwd) ) :foreground "#F0E9D2" :background winter-blue) - (with-face (format-time-string " | %H:%M" (current-time)) :background winter-blue :foreground "#888") - (with-face "\n -> ")))) - -(setq eshell-prompt-function 'apollo-eshell-prompt) -(setq eshell-highlight-prompt t) + (use-package eshell + :ensure nil + :bind (("C-c e" . 'eshell)) + :config + (defvar eshell-path-env (getenv "~/.local/bin"))) + + (defun with-face (str &rest face-plist) + (propertize str 'face face-plist)) + + (defun apollo-eshell-prompt () + (let ((winter-blue "#3F3B6C") + (white-summer "#E5E5CB") + (green-night "#03C988") + (orange-summer "#FFB100") + (green-summer "#A3BB98") + (summer-sea "#2192FF") + (black "#000000")) + (concat + (with-face (concat "[" user-login-name) :foreground orange-summer :background black) + (with-face "@" :foreground orange-summer :background black) + (with-face (concat system-name "]\n") :foreground orange-summer :background black) + (with-face (concat "|" (eshell/pwd) ) :foreground "#F0E9D2" :background winter-blue) + (with-face (format-time-string " | %H:%M" (current-time)) :background winter-blue :foreground "#888") + (with-face "\n -> ")))) + + ;; (setq eshell-prompt-function 'apollo-eshell-prompt) + ;; (setq eshell-highlight-prompt t) #+end_src -* Key-bindings +* Custom +** ChatGPT #+begin_src emacs-lisp -(global-set-key (kbd "") 'keyboard-escape-quit) + (require 'seq) + (eval-when-compile + (require 'cl-lib) + (require 'subr-x) + (require 'env) + (require 'json)) + (defgroup chatgpt nil + "ChatGPT frontend." + :group 'convenience + :prefix "chatgpt-") + (defcustom chatgpt-max-tokens 300 + "Upper limit on the number of tokens the API will return." + :type 'integer) + (defvar chatgpt-buffer "*ChatGPT*" + "Title of the buffer used to store the results of an OpenAI API query.") + (define-error 'chatgpt-error "An error related to the ChatGPT emacs package") + (define-error 'chatgpt-parsing-error + "An error caused by a failure to parse an OpenAI API Response") + (defmacro chatgpt-show-results-buffer-if-active () + "Show the results in other window if necessary." + `(if (and (not ;; visible + (get-buffer-window chatgpt-buffer)) + (called-interactively-p 'interactive)) + (lambda (&optional buf) (ignore buf) + (with-current-buffer buf + (view-mode t)) + (switch-to-buffer-other-window chatgpt-buffer)) + #'identity)) + ;;;###autoload + (defun chatgpt-prompt (prompt callback) + "Query OpenAI with PROMPT calling the CALLBACK function on the resulting buffer. + Returns buffer containing the text from this query" + (interactive (list (read-string "Prompt ChatGPT with: ") + (lambda (buf) (with-current-buffer buf + (view-mode t)) + (switch-to-buffer-other-window chatgpt-buffer)))) + (chatgpt--query-open-api prompt + (lambda (results) + (with-current-buffer (get-buffer-create chatgpt-buffer) + ;; Erase contents of buffer after receiving response + (read-only-mode -1) + (erase-buffer) + (insert results) + ;; Return the chatgpt output buffer for non interactive usage + (funcall callback (current-buffer)))))) + ;;;###autoload + (defun chatgpt-fix-region (BEG END) + "Takes a region BEG to END asks ChatGPT to explain whats wrong with it. + It then displays the answer in the `chatgpt-buffer'." + (interactive "r") + (let ((current-code (buffer-substring BEG END))) + (chatgpt-prompt (chatgpt--append-to-prompt + current-code + "Why doesn't this code work?") + (chatgpt-show-results-buffer-if-active)))) + ;;;###autoload + (defun chatgpt-explain-region (BEG END) + "Takes a region BEG to END asks ChatGPT what it does. + The answer in the displays in `chatgpt-buffer'." + (interactive "r") + (let ((current-code (buffer-substring BEG END))) + (chatgpt-prompt (chatgpt--append-to-prompt + current-code + "What does this code do?") + (chatgpt-show-results-buffer-if-active)))) + ;;;###autoload + (defun chatgpt-gen-tests-for-region (BEG END) + "Takes a region BEG to END asks ChatGPT to write a test for it. + It then displays the answer in the `chatgpt-buffer'." + (interactive "r") + (let ((current-code (buffer-substring BEG END))) + (chatgpt-prompt (chatgpt--append-to-prompt + current-code + "Write me a tests for this code") + (chatgpt-show-results-buffer-if-active)))) + ;; TODO currently just says what changed but doesn't wanna show the code it's self + ;; (defun chatgpt-optimize-region (BEG END) + ;; "Takes a region BEG to END asks ChatGPT to optimize it for speed. + ;; It then displays the answer in the `chatgpt-buffer'." + ;; (interactive "r") + ;; (let ((current-code (buffer-substring BEG END))) + ;; (chatgpt-prompt (chatgpt--append-to-prompt + ;; current-code + ;; "Refactor this code for speed and tell me what you changed and why it's faster") + ;; (chatgpt-show-results-buffer-if-active)))) + ;;;###autoload + (defun chatgpt-refactor-region (BEG END) + "Takes a region BEG to END asks ChatGPT refactor it. + It then displays the answer in the `chatgpt-buffer'." + (interactive "r") + (let ((current-code (buffer-substring BEG END))) + (chatgpt-prompt (chatgpt--append-to-prompt + current-code + "Refactor this code and tell me what you changed") + (chatgpt-show-results-buffer-if-active)))) + ;;;###autoload + (defun chatgpt-prompt-region (BEG END) + "Prompt ChatGPT with the region BEG END. + It then displays the results in a separate buffer `chatgpt-buffer'." + (interactive "r") + (chatgpt-prompt (buffer-substring BEG END) + ;; Show the results if not already being viewed + (chatgpt-show-results-buffer-if-active))) + ;;;###autoload + (defun chatgpt-prompt-region-and-replace (BEG END) + "Replace region from BEG to END with the response from the ChatGPT API. + The region is BEG and until END" + (interactive "r") + (let ((og-buf (current-buffer))) + (chatgpt-prompt (buffer-substring BEG END) + (lambda (buf) + (save-excursion + (with-current-buffer og-buf + (delete-region BEG END) + (goto-char BEG) + (insert (with-current-buffer buf (buffer-string))))))))) + (defun chatgpt--append-to-prompt (prompt comment-str) + "Append the string COMMENT-STR extra information to a PROMPT as a comment." + (concat prompt + "\n" + comment-start + " " + comment-str)) + (defun chatgpt--extract-text-from-query (query-result) + "Extract the resulting text from a given OpenAI response QUERY-RESULT." + (condition-case err + (thread-last query-result + (assoc-default 'choices) + seq-first + (assoc-default 'text) + string-trim) + (error + (signal 'chatgpt-parsing-error err)))) + (defun chatgpt--parse-response (status callback) + "Ignoring STATUS and parse the response executing the CALLBACK function on the resulting string." + (ignore status) + ;; All this is ran inside the buffer containing the response + (goto-char 0) + (re-search-forward "^$") + (funcall callback (chatgpt--extract-text-from-query (json-read)))) + (defun chatgpt--query-open-api (prompt callback) + "Send a string PROMPT to OpenAI API and pass the resulting buffer to CALLBACK. + The environment variable OPENAI_API_KEY is used as your API key + You can register an account here + https://beta.openai.com/docs/introduction/key-concepts" + (let* ((api-key (getenv secret-api)) + (url-request-method (encode-coding-string "POST" 'us-ascii)) + (url-request-extra-headers `(("Content-Type" . "application/json") + ("Authorization" . ,(format "Bearer %s" api-key)))) + (url-request-data (json-encode + `(("model" . "text-davinci-003") + ("prompt" . ,prompt) + ("max_tokens" . ,chatgpt-max-tokens) + ("temperature" . 0))))) + (cl-assert (not (string= "" api-key)) + t + "Current contents of the environmental variable OPENAI_API_KEY + are '%s' which is not an appropriate OpenAI token please ensure + you have the correctly set the OPENAI_API_KEY variable" + api-key) + (url-retrieve + "https://api.openai.com/v1/completions" + 'chatgpt--parse-response + (list callback)))) #+end_src - -* Functions +** Random functions #+begin_src emacs-lisp (defun apollo/html-boostrap-boilerplate () "Insert html boilerplate with boostrap link." @@ -521,22 +670,6 @@ Hook with ~dired-mode~ (interactive) (start-process-shell-command "setxkbmap" nil "setxkbmap gr")) - -(defun apollo/exwm-init-hook () - "Do this upon start." - (display-battery-mode 0) ;;Change to 1 to display battery - - (setq display-time-day-and-date t) - (display-time-mode 1) - - ;;Launch apps that will run in the background -;; (apollo/run-in-background "blueman-applet") - (apollo/run-in-background "picom") -;; (apollo/run-in-background "nm-applet") - (apollo/emacs-keys) - (apollo/set-wallpaper) - (start-polybar) - ) (defun apollo/exwm-update-class () (exwm-workspace-rename-buffer exwm-class-name)) @@ -546,11 +679,6 @@ Hook with ~dired-mode~ (interactive) (eshell 'N)) -(defun make-mini-buffer () - (interactive) - (split-window-below 40) - (other-window 1)) - (defun make-mini-geiser () (interactive) (split-window-below 60) @@ -565,141 +693,11 @@ Hook with ~dired-mode~ (start-process-shell-command "polybar" nil "polybar main"))) #+end_src -* mu4e | Email Configuration - -# ** MacOS -# If it's a mac, load from homebrew path - -# #+begin_src emacs-lisp -# (when (equal system-type 'darwin) -# (use-package mu4e -# :load-path "/opt/homebrew/share/emacs/site-lisp/mu/mu4e/")) -# #+end_src - +** Key-bindings #+begin_src emacs-lisp -(when (equal system-type 'darwin) - (use-package mu4e - :load-path "/opt/homebrew/share/emacs/site-lisp/mu/mu4e/")) - -(require 'mu4e) - -(setq mu4e-update-interval (* 10 60)) -(setq mu4e-get-mail-command "mbsync -a") -(setq mu4e-maildir-list "~/Mail/Inbox") - -(defun set-mu4e-context (context-name full-name mail-address signature server) - "Return a mu4e context named CONTEXT-NAME with :match-func matching - folder name CONTEXT-NAME in Maildir. The context's `user-mail-address', - `user-full-name' and `mu4e-compose-signature'`smtpmail-smpt-server' is set to MAIL-ADDRESS - FULL-NAME SIGNATURE and SERVER respectively. - Special folders are set to context specific folders." - (let ((dir-name (concat "/" context-name))) - (make-mu4e-context - :name context-name - ;; we match based on the maildir of the message - :match-func - `(lambda (msg) - (when msg - (string-match-p - ,(concat "^" dir-name) - (mu4e-message-field msg :maildir)))) - :vars - `((user-mail-address . ,mail-address) - (user-full-name . ,full-name) - (mu4e-sent-folder . ,(concat dir-name "/Sent")) - (mu4e-drafts-folder . ,(concat dir-name "/Drafts")) - (mu4e-trash-folder . ,(concat dir-name "/Trash")) - (mu4e-trash-folder . ,(concat dir-name "/Starred")) - (mu4e-refile-folder . ,(concat dir-name "/Archive")) - (smtpmail-smtp-service . ,465) - (smtpmail-smtp-server . ,server) - (mu4e-compose-signature . ,signature))))) -;;Fixing duplicate UID errors when using mbsync and mu4e -(setq mu4e-change-filenames-when-moving t) - -(setq mu4e-maildir-shortcuts - '(("/Fastmail/Inbox" . ?i) - ("/Fastmail/Sent" . ?s) - ;; ("/Gmail/Trash" . ?t) - ;; ("/Gmail/Drafts" . ?d) - ;; ("/Gmail/[Gmail]/All Mail" . ?a - )) - -(setq mu4e-contexts - `(, (set-mu4e-context - "Fastmail" "Thanos Apollo" - "thanos@thanosapollo.com" "Thanos\nhttps://thanosapollo.com/public" - "smtp.fastmail.com"))) - -;; (setq smtpmail-smtp-service 465 -;; smtpmail-stream-type 'ssl -;; smtpmail-smtp-server "smtp.fastmail.com") - - - -(setq message-send-mail-function 'smtpmail-send-it - smtpmail-stream-type 'ssl) - +(global-set-key (kbd "") 'keyboard-escape-quit) #+end_src - -# ** Settings & Context setup -# #+begin_src emacs-lisp -# (require 'mu4e) -# (setq mu4e-update-interval (* 10 60)) -# (setq mu4e-get-mail-command "mbsync -a") -# (setq mu4e-maildir-list "~/Mail/Inbox") - -# (defun set-mu4e-context (context-name full-name mail-address signature server) -# "Return a mu4e context named CONTEXT-NAME with :match-func matching -# folder name CONTEXT-NAME in Maildir. The context's `user-mail-address', -# `user-full-name' and `mu4e-compose-signature'`smtpmail-smpt-server' is set to MAIL-ADDRESS -# FULL-NAME SIGNATURE and SERVER respectively. -# Special folders are set to context specific folders." -# (let ((dir-name (concat "/" context-name))) -# (make-mu4e-context -# :name context-name -# ;; we match based on the maildir of the message -# :match-func -# `(lambda (msg) -# (when msg -# (string-match-p -# ,(concat "^" dir-name) -# (mu4e-message-field msg :maildir)))) -# :vars -# `((user-mail-address . ,mail-address) -# (user-full-name . ,full-name) -# (mu4e-sent-folder . ,(concat dir-name "/Sent")) -# (mu4e-drafts-folder . ,(concat dir-name "/Drafts")) -# (mu4e-trash-folder . ,(concat dir-name "/Trash")) -# (mu4e-trash-folder . ,(concat dir-name "/Starred")) -# (mu4e-refile-folder . ,(concat dir-name "/Archive")) -# (smtpmail-smtp-service . ,465) -# (smtpmail-smtp-server . ,server) -# (mu4e-compose-signature . ,signature))))) - -# ;;Fixing duplicate UID errors when using mbsync and mu4e -# (setq mu4e-change-filenames-when-moving t) -# ;; Messaging -# (setq message-send-mail-function 'smtpmail-send-it -# smtpmail-stream-type 'ssl) -# #+end_src -# ** Shortcuts -# #+begin_src emacs-lisp -# (setq mu4e-maildir-shortcuts -# '(("/Fastmail/Inbox" . ?i) -# ("/Fastmail/Sent" . ?s) -# )) -# #+end_src -# ** Contexts -# #+begin_src emacs-lisp -# (setq mu4e-contexts -# `(, (set-mu4e-context -# "Fastmail" "Thanos Apollo" -# "thanos@thanosapollo.com" "Thanos\nhttps://thanosapollo.com/public" -# "smtp.fastmail.com"))) -# #+end_src -* Custom key-bindings -** General +*** General #+begin_src emacs-lisp ;; my general's leader key! @@ -756,7 +754,7 @@ Hook with ~dired-mode~ :keymaps 'org-mode-map "3" 'org-insert-image-size-300) #+end_src -** Hydra +*** Hydra #+begin_src emacs-lisp (defhydra hydra-zoom (global-map "s-z") "zoom" @@ -850,23 +848,31 @@ Hook with ~dired-mode~ ;; Hooks (add-hook 'org-mode-hook 'apollo/org-theme-dracula) (add-hook 'org-mode-hook 'org-superstar-mode) - (add-hook 'org-mode-hook 'flyspell-mode) + (add-hook 'org-mode-hook 'flyspell-mode) + (add-hook 'org-mode-hook 'toc-org-mode) #+end_src ** Babel + #+begin_src emacs-lisp + (defadvice org-edit-src-code (around set-buffer-file-name activate compile) + (let ((file-name (buffer-file-name))) ;; (1) + ad-do-it ;; (2) + (setq buffer-file-name file-name))) ;; (3) + (org-babel-do-load-languages 'org-babel-load-languages '((emacs-lisp . t) (python . t))) (add-to-list 'org-structure-template-alist '("sh" . "src shell")) - (add-to-list 'org-structure-template-alist '("b" . "src shell")) + (add-to-list 'org-structure-template-alist '("b" . "src bash")) (add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp")) (add-to-list 'org-structure-template-alist '("py" . "src python")) ;;Auto tangle (add-hook 'org-mode-hook 'org-auto-tangle-mode) #+end_src + * Markdown ** Theme #+begin_src emacs-lisp @@ -1027,277 +1033,139 @@ In macOS, I have installed it through homebrew. (setq telega-server-libs-prefix "/opt/homebrew/Cellar/tdlib/HEAD-3d0140b"))) #+end_src -* Custom -** ChatGPT -#+begin_src emacs-lisp -(require 'seq) -(eval-when-compile - (require 'cl-lib) - (require 'subr-x) - (require 'env) - (require 'json)) -(defgroup chatgpt nil - "ChatGPT frontend." - :group 'convenience - :prefix "chatgpt-") -(defcustom chatgpt-max-tokens 300 - "Upper limit on the number of tokens the API will return." - :type 'integer) -(defvar chatgpt-buffer "*ChatGPT*" - "Title of the buffer used to store the results of an OpenAI API query.") -(define-error 'chatgpt-error "An error related to the ChatGPT emacs package") -(define-error 'chatgpt-parsing-error - "An error caused by a failure to parse an OpenAI API Response") -(defmacro chatgpt-show-results-buffer-if-active () - "Show the results in other window if necessary." - `(if (and (not ;; visible - (get-buffer-window chatgpt-buffer)) - (called-interactively-p 'interactive)) - (lambda (&optional buf) (ignore buf) - (with-current-buffer buf - (view-mode t)) - (switch-to-buffer-other-window chatgpt-buffer)) - #'identity)) -;;;###autoload -(defun chatgpt-prompt (prompt callback) - "Query OpenAI with PROMPT calling the CALLBACK function on the resulting buffer. -Returns buffer containing the text from this query" - (interactive (list (read-string "Prompt ChatGPT with: ") - (lambda (buf) (with-current-buffer buf - (view-mode t)) - (switch-to-buffer-other-window chatgpt-buffer)))) - (chatgpt--query-open-api prompt - (lambda (results) - (with-current-buffer (get-buffer-create chatgpt-buffer) - ;; Erase contents of buffer after receiving response - (read-only-mode -1) - (erase-buffer) - (insert results) - ;; Return the chatgpt output buffer for non interactive usage - (funcall callback (current-buffer)))))) -;;;###autoload -(defun chatgpt-fix-region (BEG END) - "Takes a region BEG to END asks ChatGPT to explain whats wrong with it. -It then displays the answer in the `chatgpt-buffer'." - (interactive "r") - (let ((current-code (buffer-substring BEG END))) - (chatgpt-prompt (chatgpt--append-to-prompt - current-code - "Why doesn't this code work?") - (chatgpt-show-results-buffer-if-active)))) -;;;###autoload -(defun chatgpt-explain-region (BEG END) - "Takes a region BEG to END asks ChatGPT what it does. -The answer in the displays in `chatgpt-buffer'." - (interactive "r") - (let ((current-code (buffer-substring BEG END))) - (chatgpt-prompt (chatgpt--append-to-prompt - current-code - "What does this code do?") - (chatgpt-show-results-buffer-if-active)))) -;;;###autoload -(defun chatgpt-gen-tests-for-region (BEG END) - "Takes a region BEG to END asks ChatGPT to write a test for it. -It then displays the answer in the `chatgpt-buffer'." - (interactive "r") - (let ((current-code (buffer-substring BEG END))) - (chatgpt-prompt (chatgpt--append-to-prompt - current-code - "Write me a tests for this code") - (chatgpt-show-results-buffer-if-active)))) -;; TODO currently just says what changed but doesn't wanna show the code it's self -;; (defun chatgpt-optimize-region (BEG END) -;; "Takes a region BEG to END asks ChatGPT to optimize it for speed. -;; It then displays the answer in the `chatgpt-buffer'." -;; (interactive "r") -;; (let ((current-code (buffer-substring BEG END))) -;; (chatgpt-prompt (chatgpt--append-to-prompt -;; current-code -;; "Refactor this code for speed and tell me what you changed and why it's faster") -;; (chatgpt-show-results-buffer-if-active)))) -;;;###autoload -(defun chatgpt-refactor-region (BEG END) - "Takes a region BEG to END asks ChatGPT refactor it. -It then displays the answer in the `chatgpt-buffer'." - (interactive "r") - (let ((current-code (buffer-substring BEG END))) - (chatgpt-prompt (chatgpt--append-to-prompt - current-code - "Refactor this code and tell me what you changed") - (chatgpt-show-results-buffer-if-active)))) -;;;###autoload -(defun chatgpt-prompt-region (BEG END) - "Prompt ChatGPT with the region BEG END. -It then displays the results in a separate buffer `chatgpt-buffer'." - (interactive "r") - (chatgpt-prompt (buffer-substring BEG END) - ;; Show the results if not already being viewed - (chatgpt-show-results-buffer-if-active))) -;;;###autoload -(defun chatgpt-prompt-region-and-replace (BEG END) - "Replace region from BEG to END with the response from the ChatGPT API. -The region is BEG and until END" - (interactive "r") - (let ((og-buf (current-buffer))) - (chatgpt-prompt (buffer-substring BEG END) - (lambda (buf) - (save-excursion - (with-current-buffer og-buf - (delete-region BEG END) - (goto-char BEG) - (insert (with-current-buffer buf (buffer-string))))))))) -(defun chatgpt--append-to-prompt (prompt comment-str) - "Append the string COMMENT-STR extra information to a PROMPT as a comment." - (concat prompt - "\n" - comment-start - " " - comment-str)) -(defun chatgpt--extract-text-from-query (query-result) - "Extract the resulting text from a given OpenAI response QUERY-RESULT." - (condition-case err - (thread-last query-result - (assoc-default 'choices) - seq-first - (assoc-default 'text) - string-trim) - (error - (signal 'chatgpt-parsing-error err)))) -(defun chatgpt--parse-response (status callback) - "Ignoring STATUS and parse the response executing the CALLBACK function on the resulting string." - (ignore status) - ;; All this is ran inside the buffer containing the response - (goto-char 0) - (re-search-forward "^$") - (funcall callback (chatgpt--extract-text-from-query (json-read)))) -(defun chatgpt--query-open-api (prompt callback) - "Send a string PROMPT to OpenAI API and pass the resulting buffer to CALLBACK. -The environment variable OPENAI_API_KEY is used as your API key -You can register an account here -https://beta.openai.com/docs/introduction/key-concepts" - (let* ((api-key (getenv secret-api)) - (url-request-method (encode-coding-string "POST" 'us-ascii)) - (url-request-extra-headers `(("Content-Type" . "application/json") - ("Authorization" . ,(format "Bearer %s" api-key)))) - (url-request-data (json-encode - `(("model" . "text-davinci-003") - ("prompt" . ,prompt) - ("max_tokens" . ,chatgpt-max-tokens) - ("temperature" . 0))))) - (cl-assert (not (string= "" api-key)) - t - "Current contents of the environmental variable OPENAI_API_KEY -are '%s' which is not an appropriate OpenAI token please ensure -you have the correctly set the OPENAI_API_KEY variable" - api-key) - (url-retrieve - "https://api.openai.com/v1/completions" - 'chatgpt--parse-response - (list callback)))) -#+end_src -** Random functions -#+begin_src emacs-lisp -(defun apollo/html-boostrap-boilerplate () - "Insert html boilerplate with boostrap link." - (interactive) - (insert -" - - - - - - My Title - - - - -
-

Starting point

-
- - -" )) - +* mu4e | Email Configuration -(defun apollo/center-buffer () - "Centers/Uncenters selected buffer" - (interactive) - (if visual-fill-column-center-text - (setq visual-fill-column-center-text nil) - (setq visual-fill-column-center-text t)) - (visual-fill-column-mode 1) - (message "General's task completed!")) +# ** MacOS +# If it's a mac, load from homebrew path +# #+begin_src emacs-lisp +# (when (equal system-type 'darwin) +# (use-package mu4e +# :load-path "/opt/homebrew/share/emacs/site-lisp/mu/mu4e/")) +# #+end_src -(defun apollo/rofi-switch-window () - "Navigate X11 buffers using rofi." - (interactive) - (start-process-shell-command - "rofi" nil "rofi -show window")) +#+begin_src emacs-lisp +(when (equal system-type 'darwin) + (use-package mu4e + :load-path "/opt/homebrew/share/emacs/site-lisp/mu/mu4e/")) -(defun apollo/run-in-background (command) - "Run COMMAND in the background." - (let ((command-parts (split-string command "[ ]+"))) - (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts))))) +(require 'mu4e) -(defun rofi () - "Run Rofi." - (interactive) - (apollo/run-in-background "rofi -show drun")) +(setq mu4e-update-interval (* 10 60)) +(setq mu4e-get-mail-command "mbsync -a") +(setq mu4e-maildir-list "~/Mail/Inbox") -(defun apollo/volume-increase () - "Increase Volume." - (interactive) - (start-process-shell-command - "amixer" nil "amixer sset Master 5%+")) +(defun set-mu4e-context (context-name full-name mail-address signature server) + "Return a mu4e context named CONTEXT-NAME with :match-func matching + folder name CONTEXT-NAME in Maildir. The context's `user-mail-address', + `user-full-name' and `mu4e-compose-signature'`smtpmail-smpt-server' is set to MAIL-ADDRESS + FULL-NAME SIGNATURE and SERVER respectively. + Special folders are set to context specific folders." + (let ((dir-name (concat "/" context-name))) + (make-mu4e-context + :name context-name + ;; we match based on the maildir of the message + :match-func + `(lambda (msg) + (when msg + (string-match-p + ,(concat "^" dir-name) + (mu4e-message-field msg :maildir)))) + :vars + `((user-mail-address . ,mail-address) + (user-full-name . ,full-name) + (mu4e-sent-folder . ,(concat dir-name "/Sent")) + (mu4e-drafts-folder . ,(concat dir-name "/Drafts")) + (mu4e-trash-folder . ,(concat dir-name "/Trash")) + (mu4e-trash-folder . ,(concat dir-name "/Starred")) + (mu4e-refile-folder . ,(concat dir-name "/Archive")) + (smtpmail-smtp-service . ,465) + (smtpmail-smtp-server . ,server) + (mu4e-compose-signature . ,signature))))) +;;Fixing duplicate UID errors when using mbsync and mu4e +(setq mu4e-change-filenames-when-moving t) -(defun apollo/volume-decrease () - "Decrease Volume." - (interactive) - (start-process-shell-command - "amixer" nil "amixer sset Master 5%-")) +(setq mu4e-maildir-shortcuts + '(("/Fastmail/Inbox" . ?i) + ("/Fastmail/Sent" . ?s) + ;; ("/Gmail/Trash" . ?t) + ;; ("/Gmail/Drafts" . ?d) + ;; ("/Gmail/[Gmail]/All Mail" . ?a + )) -(defun apollo/restore-wallpaper () - "Set NAME as wallpaper." - (interactive) - (start-process-shell-command - "feh" nil "feh --bg-scale ~/dotfiles/wallpaper.png")) +(setq mu4e-contexts + `(, (set-mu4e-context + "Fastmail" "Thanos Apollo" + "thanos@thanosapollo.com" "Thanos\nhttps://thanosapollo.com/public" + "smtp.fastmail.com"))) -(defun apollo/emacs-keys () - "Swap caps with ctrl." - (interactive) - (start-process-shell-command - "setxkbmap" nil "setxkbmap us -option ctrl:swapcaps")) +;; (setq smtpmail-smtp-service 465 +;; smtpmail-stream-type 'ssl +;; smtpmail-smtp-server "smtp.fastmail.com") -(defun apollo/greek-keyboard () - "Swap caps with ctrl." - (interactive) - (start-process-shell-command - "setxkbmap" nil "setxkbmap gr")) - -(defun apollo/exwm-update-class () - (exwm-workspace-rename-buffer exwm-class-name)) -(defun eshell-new() - "Open a new instance of eshell." - (interactive) - (eshell 'N)) -(defun make-mini-geiser () - (interactive) - (split-window-below 60) - (geiser nil)) +(setq message-send-mail-function 'smtpmail-send-it + smtpmail-stream-type 'ssl) -(defun start-polybar () - "Check which system is running, start polybar accordingly." - (interactive) - (if (string= (system-name) "fsociety") - (start-process-shell-command - "polybar" nil "polybar main & polybar second") - (start-process-shell-command - "polybar" nil "polybar main"))) #+end_src + +# ** Settings & Context setup +# #+begin_src emacs-lisp +# (require 'mu4e) +# (setq mu4e-update-interval (* 10 60)) +# (setq mu4e-get-mail-command "mbsync -a") +# (setq mu4e-maildir-list "~/Mail/Inbox") + +# (defun set-mu4e-context (context-name full-name mail-address signature server) +# "Return a mu4e context named CONTEXT-NAME with :match-func matching +# folder name CONTEXT-NAME in Maildir. The context's `user-mail-address', +# `user-full-name' and `mu4e-compose-signature'`smtpmail-smpt-server' is set to MAIL-ADDRESS +# FULL-NAME SIGNATURE and SERVER respectively. +# Special folders are set to context specific folders." +# (let ((dir-name (concat "/" context-name))) +# (make-mu4e-context +# :name context-name +# ;; we match based on the maildir of the message +# :match-func +# `(lambda (msg) +# (when msg +# (string-match-p +# ,(concat "^" dir-name) +# (mu4e-message-field msg :maildir)))) +# :vars +# `((user-mail-address . ,mail-address) +# (user-full-name . ,full-name) +# (mu4e-sent-folder . ,(concat dir-name "/Sent")) +# (mu4e-drafts-folder . ,(concat dir-name "/Drafts")) +# (mu4e-trash-folder . ,(concat dir-name "/Trash")) +# (mu4e-trash-folder . ,(concat dir-name "/Starred")) +# (mu4e-refile-folder . ,(concat dir-name "/Archive")) +# (smtpmail-smtp-service . ,465) +# (smtpmail-smtp-server . ,server) +# (mu4e-compose-signature . ,signature))))) + +# ;;Fixing duplicate UID errors when using mbsync and mu4e +# (setq mu4e-change-filenames-when-moving t) +# ;; Messaging +# (setq message-send-mail-function 'smtpmail-send-it +# smtpmail-stream-type 'ssl) +# #+end_src +# ** Shortcuts +# #+begin_src emacs-lisp +# (setq mu4e-maildir-shortcuts +# '(("/Fastmail/Inbox" . ?i) +# ("/Fastmail/Sent" . ?s) +# )) +# #+end_src +# ** Contexts +# #+begin_src emacs-lisp +# (setq mu4e-contexts +# `(, (set-mu4e-context +# "Fastmail" "Thanos Apollo" +# "thanos@thanosapollo.com" "Thanos\nhttps://thanosapollo.com/public" +# "smtp.fastmail.com"))) +# #+end_src * EXWM EXWM configuration is tangled with ~.exwm~ + In GuixSD ~emacs-exwm~ package will look for ~~/.exwm~ -- cgit v1.2.3