My Mayor Mode Config

My personal Emacs Config, 2021-07-05T11:00:00+02:00

Major modes

calendar

(require 'german-holidays)
(setq calendar-holidays holiday-german-NI-holidays)

(setq calendar-date-style 'iso)
(setq calendar-day-abbrev-array ["So" "Mo" "Di" "Mi" "Do" "Fr" "Sa"])
(setq calendar-day-header-array ["So" "Mo" "Di" "Mi" "Do" "Fr" "Sa"])
(setq calendar-day-name-array
         ["Sonntag" "Montag" "Dienstag" "Mittwoch" "Donnerstag" "Freitag" "Samstag"])
(setq calendar-iso-date-display-form
         '((format "%s-%.2d-%.2d" year
                           (string-to-number month)
                           (string-to-number day))))
(setq calendar-iso-month-header
         '(propertize
           (format "%d-%s" year
                           (calendar-month-name month))
           'font-lock-face 'calendar-month-header))
(setq calendar-mark-diary-entries-flag t)
(setq calendar-month-name-array
         ["Januar" "Februar" "M\303\244rz" "April" "Mai" "Juni" "Juli" "August" "September" "Oktober" "November" "Dezember"])
(setq calendar-standard-time-zone-name "CEST")
(setq calendar-time-display-form
         '(24-hours ":" minutes
                                (if time-zone " (")
                                time-zone
                                (if time-zone ")")))
(setq calendar-view-diary-initially-flag t)
(setq calendar-week-start-day 1)
(setq plstore-cache-passphrase-for-symmetric-encrytion t)

Calibre

This package integrates calibre (using calibredb ) into emacs.

  1. Powerful ebook dashboard.
  2. Manage ebooks, actually not only ebooks!
  3. Fetch metadata from online sources incl. automatic detection of ISBN for pdf and djvu files (automatic detection of ISBN requires pdf-tools and djvu package for pdf and djvu files respectively)
  4. Manage Ebooks’ libraries and virtual libraries.
  5. Customized Metadata: Tag, comment, highlight, favorite, archive etc.
  6. Quick search, filter, make actions on items with ivy and helm.
  7. Org-ref support.
(require 'calibredb)
(setq calibredb-root-dir "~/data/ebooks/calibre")
(setq calibredb-db-dir (expand-file-name "metadata.db" calibredb-root-dir))
(setq calibredb-library-alist '(("~/data/ebooks/calibre")))
(setq calibredb-id-width 5)

Customize

The code block defines a function my/timer-cursor-to-row3-col1 that moves the cursor to row 3, column 1 after a 0.3-second delay when Custom-mode is activated. So, the cursor is moved into the search field at activation. This is achieved by adding the function to the Custom-mode-hook, ensuring it runs whenever Custom-mode starts.

(defun my/timer-cursor-to-row3-col1 ()
  (interactive)
    (run-at-time "0.3 sec" nil
                 (lambda ()
                     (move-to-column 0)
                     (goto-line 3)
                     )))

(add-hook 'Custom-mode-hook #'my/timer-cursor-to-row3-col1)

diary

(add-hook 'diary-list-entries-hook 'diary-sort-entries t)
(add-hook 'diary-list-entries-hook 'diary-include-other-diary-files)
(add-hook 'diary-mark-entries-hook 'diary-mark-included-diary-files)

Dired

Dired is the main mode for Emacs file-manager operations. The name “Dired” stands for “directory editor”.

A single Dired buffer can display the contents of a single directory, or it can include listings of one or more sub-directories. A Dired buffer can alternatively display an arbitrary set of files and directories, from any file systems.

A Dired buffer can display a filtered subset of directory contents, and it can show either just file names or additional file details.

All the operations you expect from a typical file-manager application are available in Dired, plus some that are specific to Emacs.

You can use ‘C-x C-q’ to make a Dired buffer editable. This enters WDired mode (writable Dired). For example, you can use this to bulk-rename files, or to change file ownerships and privileges.

You can operate on multiple files after marking them. The usual mark is ‘*’, but the mark used for deletion is ‘D’. ‘D’ marks are also called flags, and the operation of marking with ‘D’ is also called flagging .

You visit a directory in Dired mode using key bindings ‘C-x d’, ‘C-x 4 d’, and ‘C-x 5 d’ .

The menu bar is helpful for learning operations and key bindings. As always, ‘C-h m’ provides information on the mode. Consult the Emacs manual ( ‘C-h r’) for more info – choose Dired under Advanced Features. You can also read about Dired online.)

(require 'wdired)
(setq dired-listing-switches "-hAl --group-directories-first --time-style=long-iso")
(setq dired-omit-files "^\\.?#\\|^\\.$\\|^\\.\\.$\\|^\\..*$")
(setq dired-use-ls-dired t)
(defun drops/dired-move-files (target-dir)
  "Move marked files in Dired to TARGET-DIR.
If no files are marked, move the file at point instead."
  (interactive "DMove file(s) to directory: ")
  (let ((full-target (expand-file-name target-dir))
        (files (dired-get-marked-files nil nil)))
    (unless files
      (setq files (list (dired-get-file-for-visit))))
    (unless (file-directory-p full-target)
      (make-directory full-target t))
    (dolist (file files)
      (let ((target (expand-file-name (file-name-nondirectory file) full-target)))
        (rename-file file target 1)
        (message "Moved: %s -> %s" file target)))
    (revert-buffer)))

Dired-dwim

💡 How it works:

  • Checks if you’re inside a Projectile project (projectile-project-p).
  • If yes → runs projectile-dired, opening Dired in the project root.
  • If no → falls back to plain dired in the current directory.

This is normally bound to F6.

(defun my/dired-dwim ()
  "Open Dired at the Projectile project root if available, otherwise in `default-directory`."
  (interactive)
  (if (and (fboundp 'projectile-project-root)
           (projectile-project-p))
      (projectile-dired)
    (dired default-directory)))
(defun my/dired-move-to (target-dir)
  "Move marked files or directories in Dired to TARGET-DIR.
Falls rename-file über Dateisystemgrenzen hinweg fehlschlägt,
wird stattdessen kopiert und das Original gelöscht."
  (let ((files (dired-get-marked-files)))
    (dolist (file files)
      (let* ((target (expand-file-name (file-name-nondirectory file) target-dir)))
        (condition-case err
            (dired-rename-file file target t)
          (file-error
           (message "rename-file fehlgeschlagen, versuche Copy/Delete: %s" (cadr err))
           (if (file-directory-p file)
               (copy-directory file target t t t)
             (copy-file file target t))
           (delete-file file t)))))
    (revert-buffer)))

Calming Mouse Interaction in Dired

Single-click on a file or directory will move the point to it, making it the implicit target for any subsequent Dired command.

Left double-click on file or directory will open it.

(add-hook
 'dired-mode-hook
 (lambda ()
   (setq-local mouse-1-click-follows-link 'double)))
(defun my/dired-mouse-toggle-mark ()
  "Toggle mark of a Dired item via mouse."
  (interactive)
  (unless (use-region-p)
    (mouse-set-point last-input-event)
    (if (char-equal (char-after (line-beginning-position)) dired-marker-char)
        (call-interactively #'dired-unmark)
      (call-interactively #'dired-mark))))

(keymap-set dired-mode-map "M-<mouse-1>" #'my/dired-mouse-toggle-mark)

eww

Eww (the Emacs Web Wowser) is a Web browser written in elisp and based on shr.el.

(require 'eww)
(setq eww-search-prefix "https://duckduckgo.com/?kae=b&kl=de-de&kad=de_DE&kp=-1&kw=w&kak=-1&kah=de-de&kn=-1&kaj=m&kam=osm&kv=-1&kao=-1&kd=-1&kc=-1&kac=-1&k1=-1&kk=-1&kz=-1&q=")

Eww is included in Emacs 24.4 and later.

ElFeed

Elfeed is an extensible web feed reader for Emacs, supporting both Atom and RSS. It requires Emacs 24.3 and is available for download from MELPA or el-get. Elfeed was inspired by notmuch.

For a longer overview,

Elpy

Elpy is an Emacs package to bring powerful Python editing to Emacs. It combines and configures a number of other packages, both written in Emacs Lisp as well as Python. Elpy is fully documented at Readthedocs.

 (add-hook 'python-mode-hook 'hs-minor-mode)

ePub

nov.el provides a major mode for reading EPUB documents.

Features:

  • Basic navigation (jump to TOC, previous/next chapter)
  • Remembering and restoring the last read position
  • Jump to next chapter when scrolling beyond end
  • Storing and following Org links to EPUB files
  • Renders EPUB2 (.ncx) and EPUB3 (<nav>) TOCs
  • Hyperlinks to internal and external targets
  • Supports textual and image documents
  • Info-style history navigation
  • View source of document files
  • Info-style incremental search
  • Metadata display
  • Image rescaling
(require 'nov)
(add-to-list 'auto-mode-alist '("\\.epub\\'" . nov-mode))
(setq nov-text-width t)
(add-hook 'nov-mode-hook 'visual-line-mode)
(add-hook 'nov-mode-hook 'visual-fill-column-mode)

ERC

ERC is an IRC client. It is included in Emacs as of version 22.3

(setq erc-autojoin-mode t)
(setq erc-autojoin-timing 'ident)
(setq erc-button-mode t)
(setq erc-fill-mode t)
(setq erc-hide-list '("QUIT"))
(setq erc-irccontrols-mode t)
(setq erc-join-buffer 'buffer)
(setq erc-list-mode t)
(setq erc-match-mode t)
(setq erc-menu-mode t)
(setq erc-modules
 '(autojoin button completion fill irccontrols list match menu move-to-prompt netsplit networks noncommands readonly ring services stamp))
(setq erc-move-to-prompt-mode t)
(setq erc-netsplit-mode t)
(setq erc-networks-alist
   '((4-irc "4-irc.com")
         (A5KNet "a5knet.com")
         (Zurna "zurna.net")))
(setq erc-networks-mode t)
(setq erc-nick "DrOps")
(setq erc-nick-uniquifier "s")
(setq erc-noncommands-mode t)
(setq erc-pcomplete-mode t)
(setq erc-prompt-for-nickserv-password nil)
(setq erc-prompt-for-password nil)
(setq erc-readonly-mode t)
(setq erc-ring-mode t)
(setq erc-server "irc.libera.chat")
(setq erc-server-alist
   '(("4-irc: Random server" 4-irc "4-irc.com" 6667)
         ("A5KNet: Random server" A5KNet "irc.a5knet.com"
          ((6660 6669)))
         ("Zurna: Random server" Zurna "irc.zurna.net" 6667)))
(setq erc-services-mode t)
(setq erc-speedbar-sort-users-type 'alphabetical)
(setq erc-stamp-mode t)
(setq erc-system-name "plaindrops.de")
(setq erc-track-minor-mode t)
(setq erc-track-mode t)
(setq erc-user-full-name "Andy Drop")

Ledger

Ledger is a command-line accounting tool by JohnWiegley, it provides a double-entry accounting ledger. The input file is a very simple text file.

You can get it from here: https://github.com/ledger/ledger-mode

Ledger comes with a ledger-mode and a function to add new entries. Here is an alternate entry function. The accounts are in German. All accounts for my expenses start with “Ausgaben:”. All accounts for my capital start with “Vermögen:” (basically I can take money from my cash reserves, or from one of my bank accounts).

(require 'compile)
(add-to-list 'compilation-error-regexp-alist-alist '(ledger "\"\\([A-Za-z0-9\\./]+\\)\", line \\([0-9]+\\)" 1 2))
(add-to-list 'compilation-error-regexp-alist 'ledger)


  (require 'ledger-mode)
  (setq ledger-default-date-format "%Y-%m-%d")
  (setq ledger-schedule-file "~/fin/schedule.ledger")
  (setq ledger-accounts-file "~/fin/accounts.ledger")
  (setq ledger-clear-whole-transactions t)

  (setq ledger-post-account-alignment-column 2)
  (setq ledger-post-amount-alignment-at :decimal)
  (setq ledger-post-amount-alignment-column 58)

  (setq ledger-reconcile-default-date-format "%Y-%m-%d")
  (setq ledger-reconcile-default-commodity "€")

  (setq ledger-report-auto-width t)
  (setq ledger-report-use-strict t)

  (add-hook 'ledger-mode-hook
              (lambda ()
                (setq-local tab-always-indent 'complete)
                (setq-local completion-cycle-threshold t)
                (setq-local ledger-complete-in-steps t)))

  (setq ledger-schedule-look-forward 7)
  (setq ledger-schedule-week-days
          '(("Mo" 1)
            ("Di" 2)
            ("Mi" 3)
            ("Do" 4)
            ("Fr" 5)
            ("Sa" 6)
            ("So" 0)))
  (setq ledger-reports
          '(("Hauszahlungen" "ledger reg Hauszahlung")
            ("Bestand Bausparen" "ledger bal Bausparen:")
            ("Bausparkasse M07 Sparkonto" "ledger reg M07h")
            ("Benzin" "ledger reg Budget:Benzin")
            ("Bestand" "ledger bal --depth 2 Haben Soll")
            ("Bestand Bargeld" "ledger [[ledger-mode-flags]] -f %(ledger-file) bal Bargeld")
            ("Bestand Giro" "ledger bal giro")
            ("Bestand Kreditkarte" "ledger [[ledger-mode-flags]] -f %(ledger-file) bal Kreditkarte")
            ("Budget Leben M07" "ledger reg \"Budget:A:Leben M07\"")
            ("Equity Report" "ledger equity")
            ("Freies Gehalt" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger reg Liquid and @Firma")
            ("Privatschulden" "ledger reg Privat")
            ("Steuer- Telefonrechnungen" "ledger reg -p \"last year\" Telefon:Festnetz")
            ("Steuer-Haftpflicht" "ledger reg -p \"last year\" Versicherungen:Haftpflicht")
            ("Steuer-KFZ-Haftpflicht" "ledger reg -p \"last year\" Ausgaben:Mobilität:Auto:Versicherungen")
            ("Steuer-Kaminkehrer" "ledger reg -p \"last year\" Kaminkehrer")
            ("Steuer-Lebensversicherung" "ledger reg -p \"last year\" Ausgaben:Versicherungen:Leben")
            ("Steuer-Unfallversicherung" "ledger reg -p \"last year\" Ausgaben:Versicherungen:Unfall")
            ("Steuer-Versicherungen" "ledger reg -p \"last year\" Telefon:Festnetz")
            ("Steuern-Rente" "ledger reg -p \"last year\" Einnahmen:Rente:Andy")
            ("Verlauf Barclay" "ledger reg Kreditkarte")
            ("Verlauf Bargeld" "ledger [[ledger-mode-flags]] -f %(ledger-file) reg Bargeld")
            ("Verlauf Bausparen" "ledger reg Bausparen:M0")
            ("Verlauf Gas" "ledger reg Budget:A:Gas")
            ("Verlauf Girokonto" "ledger reg Giro")
            ("Verlauf Haftpflicht" "ledger reg Budget:A:Haftpflicht")
            ("Verlauf Kreditkarte" "ledger [[ledger-mode-flags]] -f %(ledger-file) reg Kreditkarte")
            ("Verlauf M07" "ledger reg Bausparen:M07")
            ("Verlauf M07h" "ledger reg Haben:Bausparen:M07")
            ("Verlauf M08" "ledger reg Bausparen:M08")
            ("Verlauf M08h" "ledger reg Haben:Bausparen:M08")
            ("Verlauf M08s" "ledger reg Soll:Bausparen:M08")
            ("Verlauf M09" "ledger reg Bausparen:M09")
            ("Verlauf M09h" "ledger reg Haben:Bausparen:M09")
            ("Verlauf Zinsen" "ledger reg Ausgaben:Finanzen:Zinsen")
            ("Verlauf" "ledger reg Haben Soll")
            ("Verlauf-Barclaycard" "ledger [[ledger-mode-flags]] -f ~/fin/drops.ledger reg Soll:Kreditkarte")
            ("Verlauf-Bargeld" "ledger [[ledger-mode-flags]] -f %(ledger-file) reg Bargeld")
            ("account" "%(binary) -f %(ledger-file) reg %(account)")
            ("budget" "%(binary) budget -f %(ledger-file) ")
            ("payee" "%(binary) -f %(ledger-file) reg @%(payee)")
            ("reg Budget:Leben" "ledger reg Budget:Leben ")
            ("reg M07" "ledger reg M07h")
            ("reg reminder" "ledger reg reminder")))

(add-hook 'ledger-report-mode-hook 'compilation-minor-mode)
;; Check if system is Microsoft Windows
(defun my-system-type-is-windows ()
         "Return true if system is Windows-based (at least up to Win7)"
         (string-equal system-type "windows-nt")
         )

;; Check if system is GNU/Linux
(defun my-system-type-is-linux ()
         "Return true if system is GNU/Linux-based"
         (string-equal system-type "gnu/linux")
         )

Mail

(org-link-set-parameters "cbthunderlink" :follow #'org-cbthunderlink-open)
(defun org-cbthunderlink-open (path)
(start-process "cbthunderlink" nil "/home/andy/.local/bin/cbthunderbird/cb_thunderlink"  (concat "cbthunderlink:"  path)))

Org-mode

Org-mode is an Emacs mode for note keeping, project planning, TODO lists and authoring. It is included from Emacs 22.1 onward as default.

Org Babel

Org Babel is a component of Emacs Org Mode that enables literate programming and reproducible workflows. It allows you to write source code blocks in multiple languages (Python, Emacs Lisp, Shell, etc.) directly inside Org documents. You can execute code, capture results, and export outputs alongside text, tables, or notes. Org Babel supports language-specific header arguments, tangling (extracting code to files), and bidirectional integration with Org properties. It’s ideal for combining documentation, analysis, and programming in a single, shareable Org file, turning notes into executable, reproducible reports.

(setq org-babel-load-languages '((emacs-lisp . t) (plantuml . t) (gnuplot . t) (python . t)))
(setq org-babel-python-command "python3")

(org-babel-do-load-languages 'org-babel-load-languages org-babel-load-languages)

Org Social

(setq org-social-file "/home/andy/blog/plaindrops/files/social.org")
(setq org-social-relay "https://relay.org-social.org/")
(setq org-social-my-public-url "https://plaindrops.de/social.org")
  • gnuplot
    ;; load gnuplot mode
    (require 'gnuplot)
    (require 'ob-gnuplot)
    

Org CalDAV

Org CalDAV is an Emacs Org Mode extension that enables synchronization between Org files and CalDAV servers (e.g., Nextcloud, Google Calendar). It allows Org Mode to push and pull events, supporting bidirectional syncing, multiple calendars, and configurable inbox files for unmatched events. Org CalDAV integrates with Org’s scheduling and todo system, making your Org files a full-featured calendar client. It supports automatic or manual synchronization, fine-grained control over which changes are applied, and exporting results quietly. This makes Org CalDAV ideal for users who want to manage calendars entirely within Emacs while staying synchronized with external CalDAV services.

(setq org-caldav-calendar-id "personal")
(setq org-caldav-calendars '((:calendar-id "personal" :inbox "~/org/calendar.org")))
(setq org-caldav-files '("~/org/calendar.org" "~/org/ops.org"))
(setq org-caldav-inbox "~/org/calendar.org")
(setq org-caldav-show-sync-results nil)
(setq org-caldav-sync-changes-to-org 'all)
(setq org-caldav-sync-direction 'twoway)
(setq org-caldav-url
      "https://nextcloud.plaindrops.de/remote.php/dav/calendars/andy")
(setq org-closed-keep-when-no-todo t)
(setq org-crypt-disable-auto-save t)
(setq org-deadline-past-days 21)
(setq org-deadline-warning-days 1)
(setq org-directory "~/org")
(setq org-edna-mode t)
(setq org-edna-use-inheritance t)
(setq org-ellipsis nil)
(setq org-enforce-todo-dependencies t)
(setq org-export-use-babel nil)
(setq org-hide-block-startup t)
(setq org-hide-emphasis-markers t)
(setq org-hide-leading-stars t)
(setq org-html-html5-fancy t)
(setq org-html-toplevel-hlevel 3)
(setq org-icalendar-combined-agenda-file "/tmp/org-caldav-GvSoW8")
(setq org-icalendar-include-todo 'all)
(setq org-icalendar-store-UID t)
(setq org-icalendar-timezone "Europe/Berlin")
(setq org-icalendar-use-deadline '(todo-due))
(setq org-icalendar-use-scheduled '(event-if-not-todo todo-start))
(setq org-image-actual-width 640)
(setq org-journal-date-format "%Y-%m-%d (%A)")
(setq org-journal-dir "~/org/journal/")
(setq org-journal-file-format "Journal-%Y")
(setq org-link-frame-setup
      '((vm . vm-visit-folder-other-frame)
        (vm-imap . vm-visit-imap-folder-other-frame)
        (gnus . org-gnus-no-new-news)
        (file . find-file)
        (wl . wl-other-frame)))
(setq org-link-from-user-regexp "\\<andy\\>")
(setq org-log-done 'time)
(setq org-plantuml-jar-path "/usr/share/plantuml/plantuml.jar")

Org Refile

Org Refile is a feature in Emacs Org Mode that allows you to move or copy headings (entries) between Org files or within a file efficiently. It uses a completion system to quickly select target locations, supporting nested headings, tags, and priorities. Refiling helps keep your Org files organized, for example by moving tasks from an inbox file to project-specific files. It can be configured to limit targets, use caching, or follow outline paths, making it a powerful tool for managing large, structured Org documents and streamlining task organization.

(setq org-refile-allow-creating-parent-nodes 'confirm)
(setq org-refile-use-outline-path nil)
(setq org-refile-use-cache t)
(setq org-refile-targets
      '(("~/org/rezepte.org" :maxlevel . 2)
        ("~/org/links.org" :maxlevel . 4)
        ("~/org/ops.org" :level . 1)
        ("~/org/lyrics.org" :level . 1)
        ;;(ndk/org-refile-candidates :maxlevel . 3)
        ))
(setq org-src-block-faces '(("*" fixed-pitch)))

The following function is explained here

(defun drops/link-heading-with-own-id ()
  "Replace an Org mode heading at point
   with a linked version using its own ID,
   preserving the heading level
   and creating one if it does not already exist."
  (interactive)
  (org-back-to-heading)
  (let* ((heading-level (org-outline-level))
           (heading-start (point))
           (heading-end (line-end-position))
           (heading (nth 4 (org-heading-components)))
           (id (org-entry-get nil "CUSTOM_ID")))
    (if (not id)
          (progn
            (setq id (concat "id-" (md5 heading)))
            (org-set-property "CUSTOM_ID" id)))
    (delete-region heading-start heading-end)
    (insert (format "%s [[#%s][%s]]"
                      (make-string heading-level ?*)
                      id heading)))
  )
(with-eval-after-load 'org
 ;; Add a new emphasis for small text using =s=
 (add-to-list 'org-emphasis-alist
              '("s" ;; Use =s= to mark small text
                (:export-html "<small>" "</small>"
                              :export-latex "{\\small " "}"))))

Org Agenda

Org Agenda is a powerful Emacs Org Mode tool for viewing and managing tasks, schedules, and deadlines across one or multiple Org files. It provides customizable views such as daily/weekly agendas, TODO lists, and tag-based searches. Org Agenda integrates with Org’s scheduling, deadlines, and priorities, allowing quick navigation, task completion, and bulk modifications. It supports filtering, grouping, and sorting, and can display entries from multiple files in a unified interface. This makes Org Agenda ideal for time management, task tracking, and planning, giving Emacs users a comprehensive overview of their commitments and workflow.

(setq org-agenda-files
 '("~/org/ops.org" "~/org/birthday-calendar.org" "~/org/calendar.org" "~/org/Haushalt.org" ))

(setq org-agenda-category-icon-alist '(("todo" "org/icons/todo16.png" nil nil :ascent\ center)))


(setq org-agenda-span 'fortnight)
(setq org-agenda-time-grid
      '((daily today)
        (800 1000 1200 1400 1600 1800 2000)
        "......" "----------------"))
(setq org-agenda-window-setup 'reorganize-frame)

(setq org-agenda-include-diary t)
(setq org-agenda-loop-over-headlines-in-active-region nil)
(setq org-agenda-restore-windows-after-quit t)
(setq org-agenda-show-future-repeats nil)
(setq org-agenda-skip-deadline-prewarning-if-scheduled t)
(setq org-agenda-skip-scheduled-if-deadline-is-shown 'not-today)
(setq org-agenda-skip-scheduled-if-done t)
(setq org-agenda-skip-timestamp-if-deadline-is-shown t)
(setq org-agenda-skip-timestamp-if-done t)
(setq org-agenda-span 10)
(setq org-agenda-start-on-weekday nil)
(setq org-agenda-tags-todo-honor-ignore-options t)
(setq org-agenda-time-leading-zero t)
(setq org-agenda-todo-ignore-scheduled 'future)
(setq org-agenda-window-setup 'current-window)
 (setq org-agenda-custom-commands
        '(("n" "Agenda and all TODOs"
           ((tags "GTD=\"t\"+TODO=\"NEXT\""
                          ((org-agenda-overriding-header "Next Actions")))
                (stuck "" nil)
                (tags-todo "GTD<>\"t\"+CATEGORY<>\"Haushalt\""
                                   ((org-agenda-overriding-header "Sonstige ToDo")))
                (tags-todo "CATEGORY=\"Haushalt\"+SCHEDULED<=\"<+2d>\""
                                   ((org-agenda-overriding-header "Haushalt")))
                (agenda "" nil))
           nil
           ("~/org/agenda.txt" "~/org/agenda.html"))))
(setq org-icalendar-combined-agenda-file "/tmp/org-caldav-wtBkYE")
(setq org-outline-path-complete-in-steps t)

Org Capture

Capture lets you quickly store notes with little interruption of your work flow. Org’s method for capturing new items is heavily inspired by John Wiegley’s excellent Remember package.

(require 'org-protocol)

The following customization sets a default target file for notes.

(setq org-default-notes-file (concat org-directory "/ops.org"))
(setq org-capture-templates '(
                              ("g" "Gutschein" table-line (file+headline "~/org/nummern.org" "Gutscheine")
                               "| %? | Thema | Nummer | 10\342\202\254 | Mindestbestellwert | 2020-12-31 |")

                              ("Q" "Quotelink" entry (file+headline "~/wiki/20221010T232442--zitate__quotes.org" "Inbox")
                               "** %i
:PROPERTIES:
:TITLE: %:description:
:URL: %:link
:SAVED: %<%Y-%m-%d>
:END:

,,,#+BEGIN_QUOTE
%i
[[%:link][%:description]]
,,,#+END_QUOTE

" :immediate-finish t)
                              ("p" "Project" entry(file+headline "~/org/ops.org" "Projects")
                               "* [/] %?%:description :project:")

                              ("t" "ToDo" entry (file+headline "~/org/ops.org" "--- ToDo's ---")
                               "* %?" :empty-lines 1)
  • Capture's for journaling.
         ("j" "Journal")
         ("jj" "Log" plain (file+olp+datetree "~/org/journal.org" "Log")
          "     %?"
       :empty-lines 1 :time-prompt t)
    
         ("jt" "Traum Log" entry (file+olp+datetree "~/org/journal.org" "Log")
          "***** Traum
    
          %?"
        :empty-lines 1)
    
    
    ("jp" "Phasen" entry (file+headline "~/org/journal.org" "Phasen")
     ""  :empty-lines 1)
    ("jw" "Wendepunkte"  entry (file+headline "~/org/journal.org" "Wendepunkte" )
     "":empty-lines 1)
    ("jn" "The Now"  entry (file+headline "~/org/journal.org" "Now" )
     "":empty-lines 1)   
    
  • Captures for Finance
    ("b" "Barclay Buchung" plain (file "~/fin/drops.ledger")
     "%<%Y-%m-%d>   %?
      Ausgaben:Haushalt:Sonstiges                            %x
      Soll:Kreditkarte                                      -%x
      Budget:Kreditkarte                                     %x
      Giro
    
    " :empty-lines 1)
    ("f" "Finanzen in Ledger" plain (file "~/org/finanzen.ledger")
     "%(shell-command-to-string (format \"ledger xact %s %s\" (substring \"%:date\" 1 11) \"%:description\"))                                    " :immediate-finish t :empty-lines 1)
    ))
    

Crypt

If you just want to encrypt the text of an entry, but not the headline, or properties you can use org-crypt. In order to use org-crypt you need to add something like the following to your .emacs:

  (require 'org-crypt)
  ;; GPG key to use for encryption
  ;; Either the Key ID or set to nil to use symmetric encryption.
  (setq org-crypt-key "CABFD3324FD3279F63070228F58A421AE336FFBD")
  (setq epa-pinentry-mode 'loopback)

Entries with a :crypt: tag will be automatically be encrypted when you save the file.

  (org-crypt-use-before-save-magic)

Preventing tag inheritance stops you having encrypted text inside encrypted text.

  (setq org-tags-exclude-from-inheritance (quote ("crypt")))
  • Emacs Backup Files - a Warning.

    With org-crypt, if you have autosave turned on and decrypt the entries, the autosave file will contain the entries in plain text. For this reason your should disable autosave for encrypted files.

      (setq org-crypt-disable-auto-save t)
    

    Now any text below a headline that has a :crypt: tag will be automatically be encrypted when the file is saved. If you want to use a different tag just customize the org-crypt-tag-matcher setting. To decrypt the text just call M-x org-decrypt-entry and the encrypted text where the point is will be replaced with the plain text. If you use this feature a lot, you will probably want to bind M-x org-decrypt-entry to a key.

Download

https://github.com/abo-abo/org-download

  (require 'org-download)

  ;; Drag-and-drop to `dired`
  (add-hook 'dired-mode-hook 'org-download-enable)
  (add-hook 'org-mode-hook 'org-download-enable)
 (setq org-download-abbreviate-filename-function 'expand-file-name)
 (setq org-download-heading-lvl nil)
 (setq org-download-image-attr-list '(""))
 (setq org-download-method 'directory)         ;; save dragged images to a directory
 (setq org-download-image-dir "~/wiki/images") ;; directory name for saved images
 (setq org-download-image-html-width 640)
 (setq org-download-image-org-width 320)
 (setq org-download-screenshot-method "scrot -s %s")
 (setq org-download-image-dir "images")        
 (setq org-download-link-format "[[file:%s]]")  ;; how to insert the link
 (setq org-edna-mode t)
 (setq org-edna-use-inheritance t)
 (setq org-ellipsis " ▼")
 (setq org-enforce-todo-dependencies t)
 (setq org-export-use-babel nil)
 (setq org-export-with-toc 2)
 (setq org-hide-block-startup t)
 (setq org-hide-emphasis-markers t)
 (setq org-hide-leading-stars t)
 (setq org-html-html5-fancy t)
 (setq org-html-toplevel-hlevel 3)
 (setq org-icalendar-combined-agenda-file "/tmp/org-caldav-wtBkYE")
 (setq org-icalendar-include-todo 'all)
 (setq org-icalendar-store-UID t)
 (setq org-icalendar-timezone "Europe/Berlin")
 (setq org-image-actual-width 480)
 (setq org-indirect-buffer-display 'current-window)
 (setq org-link-from-user-regexp "\\<andy\\>")
 (setq org-log-done 'time)
 (setq org-refile-allow-creating-parent-nodes 'confirm)
 (setq org-refile-targets
       '(("~/org/rezepte.org" :maxlevel . 2)
         ("~/org/links.org" :maxlevel . 4)
         ("~/org/ops.org" :level . 1)
         ("~/org/lyrics.org" :level . 1)))
 (setq org-refile-use-outline-path nil)
 (setq org-roam-db-autosync-mode t)
 (setq org-roam-directory "/home/andy/wiki")
 (setq org-src-block-faces 'nil)
 (setq org-support-shift-select 'always)
 (setq org-tags-column -64)
 (setq org-todo-keywords
       '((sequence "proj(p)" "TODO(t)" "wait(w)" "NEXT(n)" "|" "DONE(d)" "stop(s)" "forw(f)")))
 (setq org-todo-repeat-to-state "NEXT")
 (setq org-use-property-inheritance '("GTD"))
 (setq org-use-speed-commands t)

Linking

  • Custom GPT Links in Emacs Org Mode

    The custom links are designed to point to a hypothetical URL in the format:

    https://chatgpt.com/c/%3CGUID%3E

    where GUID is the unique identifier created for the link. This setup allows you to easily insert and manage GPT-related links directly in your Org documents, open them in your browser, and export them cleanly to HTML or other formats.

    The code below provides:

    • Functions to follow and export the links.
    • Registration of the "gpt" custom link type with Org Mode.
    (defun my/org-gpt-open (path)
      "Open a GPT custom link with PATH as GUID."
      (browse-url (format "https://chatgpt.com/c/%s" path)))
    
    (defun my/org-gpt-export (path _desc _format)
      "Export GPT links as HTML links."
      (format "<a href=\"https://chatgpt.com/c/%s\">GPT Chat</a>" path))
    
    ;; Register the custom link type
    (org-link-set-parameters
     "gpt"
     :follow #'my/org-gpt-open
     :export #'my/org-gpt-export
     :help-echo "Open GPT chat session")
    
  • GeoLink
      (load (concat user-emacs-directory "lisp/org-geolink.el"))
      (require 'org-geolink)
    
    • Emacs Backup Files - a Warning.

      With org-crypt, if you have autosave turned on and decrypt the entries, the autosave file will contain the entries in plain text. For this reason your should disable autosave for encrypted files.

        (setq org-crypt-disable-auto-save t)
      

      Now any text below a headline that has a :crypt: tag will be automatically be encrypted when the file is saved. If you want to use a different tag just customize the org-crypt-tag-matcher setting. To decrypt the text just call M-x org-decrypt-entry and the encrypted text where the point is will be replaced with the plain text. If you use this feature a lot, you will probably want to bind M-x org-decrypt-entry to a key.

  • Youtube

    Youtube links in org-mode, see https://emacs.stackexchange.com/questions/38098/org-mode-custom-youtube-link-syntax

    After installing and loading this library in emacs you can use links with the format

    yt:<video-id>

    or

    [yt:<video-id>][description]

    in your org-mode document. If you display inline-images in org-mode the link is replaced by the image for the video downloaded from youtube. When you click on the link or on the image the video-url is opened in the browser.

     (load (concat user-emacs-directory "lisp/org-yt.el"))
     (require 'org-yt)
    

PDFview

Out of the box, org-mode doesn't know about pdf-tools. However, you can add support for opening org links to pdf files with org-pdfview, which is available as a package on MELPA. Once it's installed, you can activate it with the following code in your .emacs:

 (eval-after-load 'org '(require 'org-pdfview))

 (add-to-list 'org-file-apps 
              '("\\.pdf\\'" . (lambda (file link)
                                      (org-pdfview-open link))))

Doing this will provide a new completion target for adding links via C-c C-l, pdfview:, with support for jumping to specific pages.

Startup

   (setq org-startup-align-all-tables t)
   (setq org-startup-folded 'content)
   (setq org-startup-with-inline-images t)

   (setq org-stuck-projects '("Project=\"t\"" ("NEXT") nil ""))
   (setq org-support-shift-select t)
   (setq org-tags-column -64)
   (setq org-tags-exclude-from-inheritance '("crypt"))
   (setq org-todo-keywords   '((sequence "proj(p)" "TODO(t)" "wait(w)" "NEXT(n)" "|" "DONE(d)" "stop(s)" "forw(f)")))
   (setq org-todo-repeat-to-state "NEXT")
   (setq org-use-property-inheritance '("GTD"))
  (setq org-babel-python-command "python3")
  (setq org-blank-before-new-entry '((heading . t) (plain-list-item . t)))
  (setq org-closed-keep-when-no-todo t)
  (setq org-confirm-babel-evaluate nil)
  (setq org-deadline-past-days 21)
  (setq org-deadline-warning-days 1)

Special-Block-Extras

An Org mode block is a region of text surrounded by #+BEGIN_𝒳 … #+END_𝒳; they serve various purposes as summarised in the table below. However, we shall use such blocks to execute arbitrary code on their contents .

Name Description
example Format text verbatim, leaving markup as is
src Format source code
center Centre text
quote Format text as a quotation —ignore line breaks
verse Every line is appended with a line break
tiny Render text in a small font; likewise footnotesize
comment Completely omit the text from export
  • They can be folded and unfolded in Emacs by pressing TAB in the #+BEGIN line.
  • The contents of blocks can be highlighted as if they were of language ℒ such as org, html, latex, haskell, lisp, python, … by writing #+BEGIN_𝒳 ℒ on the starting line, where 𝒳 is the name of the block type.
  • Verbatim environments src and example may be followed by switch -n to display line numbers for their contents.
 ;;(require 'org-special-block-extras)

Ready-Player

(require 'ready-player)
(setq ready-player-mode +1)
(setq ready-player-my-media-collection-location "/home/andy/aud/music")

Terminal

I use the Fish shell, which isn't POSIX-compatible. To avoid issues with Emacs subprocesses that expect a POSIX shell, I tell Emacs to use Bash internally when my login shell is Fish.

(when (string-match-p "fish" (or (getenv "SHELL") ""))
  (setq shell-file-name "/bin/bash"))

I want Emacs to inherit the same environment variables as my Fish shell, so I use exec-path-from-shell to import PATH and other settings.

(require 'exec-path-from-shell)
(exec-path-from-shell-initialize)

In vterm, I prefer to use Fish interactively. This way, my terminal sessions inside Emacs behave just like in my regular shell.

(setq vterm-shell "fish")

Killing the buffer makes 100% sense to me, actually it annoys me that it stays alive.

(add-hook 'vterm-exit-functions
          (lambda (_ _)
            (let* ((buffer (current-buffer))
                   (window (get-buffer-window buffer)))
              (when (not (one-window-p))
                (delete-window window))
              (kill-buffer buffer))))

Shell-Here

Open a shell buffer in (or relative to) default-directory, e.g. whatever directory the current buffer is in. If you have projectile or find-file-in-project installed, you can also move around relative to the root of the current project.

I use Emacs shell buffers for everything, and shell-here is great for getting where you need to quickly. Projectile / FFIP integration makes it very easy to manage multiple shells and maintain your path / history / scrollback when switching between projects.

(require 'cl-lib)

(defun shell-at-dir (dir)
  "Open a shell at DIR.
If a shell buffer visiting DIR already exists, show that one."
  (interactive (list default-directory))
  (let ((buf (car (cl-remove-if-not
                   (lambda (it)
                     (with-current-buffer it
                       (and (derived-mode-p 'shell-mode)
                            (equal default-directory dir))))
                   (buffer-list)))))
    (if buf
        (switch-to-buffer buf)
      (shell (generate-new-buffer-name "*shell*")))))

Treemacs

  (require 'treemacs)
       (setq treemacs-collapse-dirs 3)
       (setq treemacs-filewatch-mode t)
       (setq treemacs-follow-mode t)
       (setq treemacs-fringe-indicator-mode t)
       (setq treemacs-git-mode t)
       (setq treemacs-project-follow-cleanup t)
       (setq treemacs-select-when-already-in-treemacs 'next-or-back)
       (setq treemacs-is-never-other-window t)
       (setq treemacs-missing-project-action 'keep)

;; Treemacs beim Start von Emacs automatisch öffnen
(add-hook 'after-init-hook
          (lambda ()
            (treemacs)))