;;; $DOOMDIR/config.el -*- lexical-binding: t; -*- ;; Place your private configuration here! Remember, you do not need to run 'doom ;; sync' after modifying this file! ;; Some functionality uses this to identify you, e.g. GPG configuration, email ;; clients, file templates and snippets. It is optional. ;; (setq user-full-name "John Doe" ;; user-mail-address "john@doe.com") ;; Doom exposes five (optional) variables for controlling fonts in Doom: ;; ;; - `doom-font' -- the primary font to use ;; - `doom-variable-pitch-font' -- a non-monospace font (where applicable) ;; - `doom-big-font' -- used for `doom-big-font-mode'; use this for ;; presentations or streaming. ;; - `doom-symbol-font' -- for symbols ;; - `doom-serif-font' -- for the `fixed-pitch-serif' face ;; ;; See 'C-h v doom-font' for documentation and more examples of what they ;; accept. For example: ;; ;;(setq doom-font (font-spec :family "Fira Code" :size 12 :weight 'semi-light) ;; doom-variable-pitch-font (font-spec :family "Fira Sans" :size 13)) ;; ;; If you or Emacs can't find your font, use 'M-x describe-font' to look them ;; up, `M-x eval-region' to execute elisp code, and 'M-x doom/reload-font' to ;; refresh your font settings. If Emacs still can't find your font, it likely ;; wasn't installed correctly. Font issues are rarely Doom issues! ;; There are two ways to load a theme. Both assume the theme is installed and ;; available. You can either set `doom-theme' or manually load a theme with the ;; `load-theme' function. This is the default: (setq doom-theme 'doom-one) ;; This determines the style of line numbers in effect. If set to `nil', line ;; numbers are disabled. For relative line numbers, set this to `relative'. (setq display-line-numbers-type t) ;; If you use `org' and don't want your org files in the default location below, ;; change `org-directory'. It must be set before org loads! (setq org-directory "~/org/") ;; Whenever you reconfigure a package, make sure to wrap your config in an ;; `after!' block, otherwise Doom's defaults may override your settings. E.g. ;; ;; (after! PACKAGE ;; (setq x y)) ;; ;; The exceptions to this rule: ;; ;; - Setting file/directory variables (like `org-directory') ;; - Setting variables which explicitly tell you to set them before their ;; package is loaded (see 'C-h v VARIABLE' to look up their documentation). ;; - Setting doom variables (which start with 'doom-' or '+'). ;; ;; Here are some additional functions/macros that will help you configure Doom. ;; ;; - `load!' for loading external *.el files relative to this one ;; - `use-package!' for configuring packages ;; - `after!' for running code after a package has loaded ;; - `add-load-path!' for adding directories to the `load-path', relative to ;; this file. Emacs searches the `load-path' when you load packages with ;; `require' or `use-package'. ;; - `map!' for binding new keys ;; ;; To get information about any of these functions/macros, move the cursor over ;; the highlighted symbol at press 'K' (non-evil users must press 'C-c c k'). ;; This will open documentation for it, including demos of how they are used. ;; Alternatively, use `C-h o' to look up a symbol (functions, variables, faces, ;; etc). ;; ;; You can also try 'gd' (or 'C-c c d') to jump to their definition and see how ;; they are implemented. ;; set emacs to use vivaldi to open all links (setq browse-url-browser-function 'browse-url-generic browse-url-generic-program "/Applications/Vivaldi.app/Contents/MacOS/Vivaldi") ; associate gdscript mode with .gd file extensions (add-to-list 'auto-mode-alist '("\\.gd\\'" . gdscript-mode)) ;; Enable Python in Org Babel (after! org (org-babel-do-load-languages 'org-babel-load-languages '((python . t)))) ;; Turn on Python execution ;; Optional: Don’t ask for confirmation every time (setq org-confirm-babel-evaluate nil) (setq org-ditaa-jar-path "/opt/homebrew/Cellar/ditaa/0.11.0_1/libexec/ditaa-0.11.0-standalone.jar") (org-babel-do-load-languages 'org-babel-load-languages '((ditaa . t) (emacs-lisp . t))) (after! org (setq org-plantuml-jar-path (expand-file-name "/opt/homebrew/Cellar/plantuml/1.2025.8/libexec/plantuml.jar")) (org-babel-do-load-languages 'org-babel-load-languages'((plantuml . t)))) (setenv "JAVA_HOME" "/opt/homebrew/opt/openjdk/libexec/openjdk.jdk/Contents/Home") (setenv "PATH" (concat (getenv "JAVA_HOME") "/bin:" (getenv "PATH"))) (add-to-list 'exec-path (concat (getenv "JAVA_HOME") "/bin")) (defun ronny/insert-ecomm-template () "Insert the e-commerce lesson template into the current buffer." (interactive) (insert-file-contents "~/.doom.d/templates/notes/ecomm-lesson.org") (save-excursion (goto-char (point-min)) (when (re-search-forward "%(file-name-base buffer-file-name)" nil t) (replace-match (file-name-base (or buffer-file-name "Untitled")))))) (defun ronny/insert-envy-template () "Insert the facebook envy lesson template into the current buffer." (interactive) (insert-file-contents "~/.doom.d/templates/notes/facebook_envy-lesson.org") (let* (( base ( file-name-base (or buffer-file-name "Untitled"))) ;; From: \"S04|22 - scale by hiring freelanders\" ;; To: \"S04|22\" (lesson-code (car (split-string base " - ")))) (save-excursion (goto-char (point-min)) ;; existing behavior (when (search-forward "%(file-name-base buffer-file-name)" nil t) (replace-match base t t)) ;; new placeholder for S04|22 (goto-char (point-min)) (when (search-forward "%(lesson-code)" nil t) (replace-match lesson-code t t))))) (defun ronny/insert-radiate-template () "Insert the radiate lesson template into the current buffer." (interactive) (insert-file-contents "~/.doom.d/templates/notes/radiate-lesson.org") (let* (( base ( file-name-base (or buffer-file-name "Untitled"))) ;; From: \"S04|22 - scale by hiring freelanders\" ;; To: \"S04|22\" (lesson-code (car (split-string base " - ")))) (save-excursion (goto-char (point-min)) ;; existing behavior (when (search-forward "%(file-name-base buffer-file-name)" nil t) (replace-match base t t)) ;; new placeholder for S04|22 (goto-char (point-min)) (when (search-forward "%(lesson-code)" nil t) (replace-match lesson-code t t))))) ;; commands to export properly ;; ;; html: org-export-html-to-exports ;; pdf: org-export-pdf-to-exports ;; retrieve the top level path that contains _exports (defun ronny/exports-root () "Find the nearest parent directory containing _exports." (let ((root (locate-dominating-file default-directory "_exports"))) (unless root (error "Could not find project root containing _exports/")) (expand-file-name root))) ;; takes the current file and return its path relative to the project root (defun ronny/exports-relative-path () "Return current Org file path relative to the project root." ;; check whether current buffer is currently attached to a file ;; ;; 1a. call the exports-root function to get the _export root ;; 1b. make sure it ends with a trailing slash ;; ;; 2a. get the full absolute path of the current file ;; 2b. put it in a variable called "file" ;; ;; 3a. make sure that the file is located somewhere under the root path that ALSO contains "_exports" ;; 3b strip away the root part and return the relative part (unless buffer-file-name (error "Buffer is not visiting a file")) (let* ((root (file-name-as-directory (ronny/exports-root))) ;; 1a / 1b (file (expand-file-name buffer-file-name))) ;; 2a, 2b (unless (string-prefix-p root file) ;; 3a (error "Current file is not under project root")) (file-relative-name file root))) ;; 3b ;; compute the _exports path for the file ;; ;; args: ;; format-dir -> "html" / "pdf" ;; extension -> ".html" / ".pdf" ;; ;; 1a get the project root and store it in "root" ;; 2a get the relative path and store it in "relpath" ;; 2b remove the extension from the file and store in "rel-no-ext" ;; 3a create the filepath that will exist from _exports + the relative filepath and ext ;; 3b put that under the root path ;; 4a retrieve only the directory part of the path ;; 4b make the directory if it doesn't exist ;; 5a return the final path (defun ronny/exports-path (format-dir extension) "Build export path under _exports/FORMAT-DIR preserving source structure." (let* ((root (ronny/exports-root)) ;; 1a (relpath (ronny/exports-relative-path)) ;; 2a (rel-no-ext (file-name-sans-extension relpath)) ;; 2b (outfile (expand-file-name (concat "_exports/" format-dir "/" rel-no-ext extension) ;; 3a root)) ;; 3b (outdir (file-name-directory outfile))) ;; 4a (make-directory outdir t) ;; 4b outfile)) ;; 5a ;; command to export the current Org file to HTML (run interactively) ;; ;; 1a make the function callable as an emacs command ;; - can run with M-x ;; - can bind to a key ;; 2a get the full export path for an html export ;; 3a call the export to command to generate an html file based on the current org file ;; 3b confirmation message display in minibuffer (defun ronny/org-export-html-to-exports () "Export current Org file to _exports/html preserving directory structure." (interactive) ;; 1a (let ((outfile (ronny/exports-path "html" ".html"))) ;; 2a (org-export-to-file 'html outfile nil nil nil nil nil) ;; 3a (message "Exported HTML to %s" outfile))) ;; 3b ;; same as above but for latex/pdf ;; (defun ronny/org-export-pdf-to-exports () ;; "Export current Org file to _exports/pdf preserving directory structure." ;; (interactive) ;; (let ((outfile (ronny/exports-path "pdf" ".pdf"))) ;; (org-export-to-file 'latex outfile nil nil nil nil nil) ;; (message "Exported PDF to %s" outfile))) ;; export to pdf ;; ;; generate the pdf in the normal way ;; file is created next to the org source file ;; move it to where it should be under _exports ;; ;; 1a make this funciton callable ;; ;; 2a put the final _export path as a string in "outfile" ;; 2b get the src dir and put it in srcdir ;; 2c get the src file name and put it in base ;; 2d replace the ext org with pdf and put this value in pdf-src ;; ;; 3a generate the pdf normally ;; ;; 4a use rename to move the pdf to _exports ;; (defun ronny/org-export-pdf-to-exports () "Export current Org file to _exports/pdf and clean up LaTeX artifacts." (interactive) ; 1a (let* ((outfile (ronny/exports-path "pdf" ".pdf")) ;; 2a (srcdir (file-name-directory buffer-file-name)) ;; 2b (base (file-name-base buffer-file-name)) ;; 2c (pdf-src (expand-file-name (concat base ".pdf") srcdir))) ;; 2d ;; Export PDF next to the source Org file (org-latex-export-to-pdf) ; 3a ;; Move PDF to _exports (unless (file-exists-p pdf-src) (error "Expected PDF not found: %s" pdf-src)) (rename-file pdf-src outfile t) ;; 4a ;; Delete common LaTeX byproducts left next to the source Org file (dolist (f (directory-files srcdir t (concat "^" (regexp-quote base) "\\.\\(tex\\|aux\\|log\\|out\\|toc\\|nav\\|snm\\|fls\\|fdb_latexmk\\)$"))) (delete-file f)) (message "Exported PDF to %s" outfile))) ;; exports to odt and docx ;; see above (defun ronny/org-export-odt-to-exports () "Export current Org file to _exports/odt." (interactive) (let* ((outfile (ronny/ecomm-export-path "odt" ".odt")) (srcdir (file-name-directory buffer-file-name)) (base (file-name-base buffer-file-name)) (odt-src (expand-file-name (concat base ".odt") srcdir))) ;; export (org-odt-export-to-odt) ;; move file (unless (file-exists-p odt-src) (error "Expected ODT not found: %s" odt-src)) (rename-file odt-src outfile t) (message "Exported ODT to %s" outfile))) (defun ronny/org-export-docx-to-exports () "Export current Org file to _exports/docx via ODT." (interactive) (let* ((odt-out (ronny/exports-path "odt" ".odt")) (docx-out (ronny/exports-path "docx" ".docx")) (base (file-name-base buffer-file-name))) ;; first export ODT (ronny/org-export-odt-to-exports) ;; convert to docx (call-process "soffice" nil 0 nil "--headless" "--convert-to" "docx" "--outdir" (file-name-directory docx-out) odt-out) ;; rename to correct filename if needed (let ((generated (expand-file-name (concat base ".docx") (file-name-directory docx-out)))) (rename-file generated docx-out t)) (message "Exported DOCX to %s" docx-out))) ;; export + open helpers (defun ronny/org-export-html-to-exports-and-open () "Export current Org file to _exports/html and open it." (interactive) (let ((outfile (ronny/exports-path "html" ".html"))) (ronny/org-export-html-to-exports) (browse-url-of-file outfile))) ;; use the osx system to open files (defun ronny/open-file-in-macos (path) "Open PATH in the default macOS application." (interactive "fOpen file: ") (call-process "open" nil 0 nil (expand-file-name path))) ;; use osx to open (defun ronny/org-export-pdf-to-exports-and-open () "Export current Org file to _exports/pdf and open it." (interactive) (let ((outfile (ronny/exports-path "pdf" ".pdf"))) (ronny/org-export-pdf-to-exports) (ronny/open-file-in-macos outfile))) ;; Doom keybindings under SPC m e (map! :map org-mode-map :leader (:prefix ("m C" . "custom export") :desc "Export HTML" "h" #'ronny/org-export-html-to-exports :desc "Export PDF" "p" #'ronny/org-export-pdf-to-exports :desc "Export HTML open" "o" #'ronny/org-export-html-to-exports-and-open :desc "Export PDF open" "P" #'ronny/org-export-pdf-to-exports-and-open :desc "ODT export" "d" #'ronny/org-export-odt-to-exports :desc "DOCX export" "D" #'ronny/org-export-docx-to-exports))