emacs-sword
Table of Contents
1. Package Header
this is the package header
==:
;;; emacs-sword.el --- a package to aid with studies of the Bible ;; Copyright (C) 2022 William Malander ;; Author: William Malander <william@malanderengineering.com> ;; Keywords: lisp ;; Version: 2.0 ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see <http://www.gnu.org/licenses/>. ;;; Commentary: ;; The Sword of the Lord with a decided Lisp. ;; ;; This is a package written to replace e-sword for linux and emacs users. ;; Changelog: ;; ;; 2.0: ;; Added official support for Treemacs. ;; The following will only happen if you have treemacs installed: ;; Will automatically create a treemacs workspace if there isnt one already. ;; C-S-b t will open the Emacs-sword workspace. ;; 1.9.3: ;; Changed resource downloader to handle .zip files ;; 1.9.2: ;; Fixed an issue when finding a single verse that is in parenthesis printing the verse number instead of the verse ;; eww-download should be back after you quit the resource downloader ;; 1.9.1: ;; fixed missing function call ;; 1.9: ;; Added Bible book abbreviations. They are usable in place of the whole book name everywhere. ;; C-S-b v a now opens a buffer with all the abbreviations. ;; Abbreviations are fully customisable, you can replace, remove, or add new abbreviations. ;; 1.8.2: ;; Changed keybindings in emacs-sword-resource-downloader to be easier. ;; 1.8.1: ;; Added a comment to start of word search immediatley and standard. ;; 1.8: ;; Added immediate prefix and search ;; 1.7.4: ;; Changed the key bindings to be more intuative. ;; Names prefix keys. ;; 1.7.3: ;; Added functions to visit Bible and dictionary directories. ;; Changed key-bindings to use C-S-b v for visit prefix ;; 1.7.2: ;; Allowed audio function to stack file to end of book with -> ;; 1.7.1: ;; Fixed downloads not ending where they should. ;; 1.7: ;; Added Resource Downloader and other functions related. ;; Added Resource Repository variable. ;; 1.6: ;; Added resources and directory. ;; You can link to any header in a resource. ;; You can convert a two column table into a list with listify. ;; 1.5.4: ;; Changed Find Verse from using src block to using verse block, so links work and it makes sense. ;; 1.5.3: ;; If Word Search does not find any verses it will now tell you so. ;; Goto Defenition now works like every other function. ;; 1.5.2: ;; Changed the Word Search backend to support regexp. ;;; Code:
2. Variables
Here are all the variables. They are all customizable, so no need to mess about with them here
==:
(defgroup emacs-sword nil "Customize Emacs Sword" :group 'emacs) (defcustom Dictionary-Directory "" "Directory (Relative to Emacs Sheath) where the dictionaries are stored" :type 'string :group 'emacs-sword) (defcustom Bible-Directory "" "Directory (Relative to Emacs Sheath) where the Bibles are stored" :type 'string :group 'emacs-sword) (defcustom Greek "strongsgreek.org" "Greek dictionary" :type 'string :group 'emacs-sword) (defcustom Hebrew "strongshebrew.org" "Hebrew dictionary" :type 'string :group 'emacs-sword) (defcustom Bibles '("KJV_10SLPV.org") "List of Bibles" :type '(repeat string) :group 'emacs-sword) (defcustom emacs-sheath "~/emacs-sword/" "Emacs Sword home directory" :type 'string :group 'emacs-sword) (setq org-babel-exp-code-template (concat "\n==:\n" org-babel-exp-code-template)) (defcustom player "vlc" "The command for playing audio." :type 'string :group 'emacs-sword) (defcustom Audio-Directory "audio/" "Directory where audio files are stored relative to Emacs Sheath" :type 'string :group 'emacs-sword) (defcustom Resource-Directory "" "Directory (Relative to Emacs Sheath) where the resources are stored" :type 'string :group 'emacs-sword) (defcustom Resources '("") "List of resources NOTE: NO SPACES ARE SUPPORTED!!!" :type '(repeat string) :group 'emacs-sword) (defcustom Resource-Repository "malanderengineering.com/packages/repo/" "URL where the downloadable resources are stored" :type 'string :group 'emacs-sword) (defcustom Abbreviations '( ("Gen" . "Genesis") ("Exo" . "Exodus") ("Lev" . "Leviticus") ("Num" . "Numbers") ("Deu" . "Deuteronomy") ("Jos" . "Joshua") ("Jdg" . "Judges") ("Rth" . "Ruth") ("1Sa" . "Samuel 1") ("2Sa" . "Samuel 2") ("1Ki" . "Kings 1") ("2Ki" . "Kings 2") ("1Ch" . "Chronicles 1") ("2Ch" . "Chronicles 2") ("Ezr" . "Ezra") ("Neh" . "Nehemiah") ("Est" . "Ester") ("Job" . "Job") ("Psa" . "Psalms") ("Pro" . "Proverbs") ("Ecc" . "Ecclesiastes") ("Son" . "Song of Solomon") ("Isa" . "Isaiah") ("Jer" . "Jeremiah") ("Lam" . "Lamentations") ("Eze" . "Ezekiel") ("Dan" . "Daniel") ("Hos" . "Hosea") ("Joe" . "Joel") ("Amo" . "Amos") ("Oba" . "Obadiah") ("Jon" . "Jonah") ("Mic" . "Micah") ("Nah" . "Nahum") ("Hab" . "Habakkuk") ("Zep" . "Zephaniah") ("Hag" . "Haggai") ("Zec" . "Zechariah") ("Mal" . "Malachi") ("Mat" . "Matthew") ("Mar" . "Mark") ("Luk" . "Luke") ("Joh" . "John") ("Act" . "Acts") ("Rom" . "Romans") ("1Co" . "Corinthians 1") ("2Co" . "Corinthians 2") ("Gal" . "Galatians") ("Eph" . "Ephesians") ("Php" . "Philippians") ("Col" . "Colossians") ("1Th" . "Thessalonians 1") ("2Th" . "Thessalonians 2") ("1Ti" . "Timothy 1") ("2Ti" . "Timothy 2") ("Tit" . "Titus") ("Phm" . "Philemon") ("Heb" . "Hebrews") ("Jas" . "James") ("1Pe" . "Peter 1") ("2Pe" . "Peter 2") ("1Jn" . "John 1") ("2Jn" . "John 2") ("3Jn" . "John 3") ("Jud" . "Jude") ("Rev" . "Revelation") ) "Alist of book abbreviations" :type '(alist :key-type (symbol :tag "Key") :value-type (string :tag "Value")) :group 'emacs-sword)
3. Functions
3.1. Bible Related Functions
3.1.1. Find Verse
This function finds the verse reference in the previous list (eg. (John 3:16)), and pastes it in a source block. the syntax is (BOOKssCHAPTER:VERSE) where BOOK the the book, s is space, CHAPTER is chapter, and VERSE is verse. The command to run this function is C-S-b f (or Ctrl-Shift-b f) or you could call it with M-x emacs-sword-find-verse (where M is Alt).
==:
(defun emacs-sword-find-verse () "This function finds the verse reference in the previous list (eg. (John 3:16)), and pastes it in a source block. the syntax is (BOOKssCHAPTER:VERSE) where BOOK the the book, s is space, CHAPTER is chapter, and VERSE is verse. The command to run this function is C-S-b f (or Ctrl-Shift-b f) or you could call it with M-x emacs-sword-find-verse (where M is Alt)." (interactive) (let ((output "") (verse (save-excursion (search-backward ")")(or (thing-at-point 'list t) (concat (thing-at-point 'sexp t) ")")))) (book "") (chapter "") (verse-num "") (line-bounds nil) (multiple nil) (Bible (concat emacs-sheath Bible-Directory (elt Bibles (- (read-number (concat (format "Choose a Bible: %s" Bibles) " Bible Number ")) 1))))) (message "Let #1") (with-current-buffer (or (get-file-buffer Bible) (find-file-noselect Bible)) (message "Change Buffer to %s" Bible) (save-excursion (message "move point") (goto-char (point-min)) (get-buffer-create "kjv-search") (with-current-buffer "kjv-search" (message "Change Buffer to kjv-search") (goto-char (point-min)) (insert verse) (goto-char (point-min)) (message "Reference inserted in temp buffer") (let ((search-result (search-forward "-" nil t))) (if search-result (progn (save-excursion (message "go to end?") (let ((rest (search-forward ">" nil t))) (if rest (setq multiple ">") (progn (message "%s" (number-at-point)) (setq multiple (number-at-point)) (message "%d" multiple) (message "%d" multiple)))))))) (goto-char (point-min)) (setq book (progn (re-search-forward "[1-3]?[A-z]+\\s-?[0-9]?") (match-string 0)) chapter (progn (goto-char (point-min)) (re-search-forward "[0-9]+:" nil t) (substring (match-string 0) 0 -1)) verse-num (progn (goto-char (point-min)) (re-search-forward ":[0-9]*" nil t) (substring (match-string 0) 1))) (setq book (emacs-sword--check-abbrev (string-trim-right book))) (message "set all search params") (message "multiple == %s" multiple) (kill-current-buffer)) (search-forward (string-trim-right (concat "** " book)) nil t) (message "book: %s" book) (search-forward (concat "Chapter " chapter) nil t) (message "chapter: %s" chapter) (search-forward (concat "(" verse-num ")") nil t) (message "verse: %s" verse-num) (message "%s" (point)) (message "%s" (current-buffer)) (setq output "\n") (if multiple (progn (if (equal multiple ">") (save-excursion (message "Checking Chapter Length") (or (search-forward "*** Chapter" nil t) (goto-char (point-max))) (re-search-backward "[0-9]\)" nil t) (goto-char (+ 1 (point))) (message "%s" (number-at-point)) (setq multiple (- (number-at-point) (number-at-point) (number-at-point))) (message "multiple == %d" multiple))) (progn (dotimes (count (+ (- (string-to-number (concat "-" verse-num)) multiple) 0)) (setq output (concat output (thing-at-point 'line t))) (forward-line 1) (message output) (message "%d" count))) (setq output (concat output (thing-at-point 'line t)))) (setq output (concat output (thing-at-point 'line t)))))) (save-excursion (progn(search-backward ")") (beginning-of-line) (thing-at-point 'list) (search-forward ")") (kill-line 0) (insert (concat "#+NAME: " (string-trim-right book) " " chapter ":" verse-num (if multiple (format "%s" multiple)) "\n#+begin_verse ")) (insert output) (insert "#+end_verse") (unless multiple (progn (re-search-backward "([0-9]") (setq line-bounds (point)) (search-forward ")")) (delete-region line-bounds (point))) (message "pasted %s" verse)))))
3.1.2. Link Verse
This function finds a verse in the previous array (eg. [John 3:16]) and make a link to it in your Bible of choice. the syntax is [BOOKssCHAPTER:VERSE] where BOOK the the book, s is space, CHAPTER is chapter, and VERSE is verse. The command to run this function is C-S-b l b (or Ctrl-Shift-b l b) or you could call it with M-x emacs-sword-link-verse (where M is Alt).
==:
(defun emacs-sword-link-verse () "This function finds a verse in the previous array (eg. [John 3:16]) and make a link to it in your Bible of choice. the syntax is [BOOKssCHAPTER:VERSE] where BOOK the the book, s is space, CHAPTER is chapter, and VERSE is verse. The command to run this function is C-S-b l b (or Ctrl-Shift-b l b) or you could call it with M-x emacs-sword-link-verse (where M is Alt)." (interactive) (let ((output "") (verse (save-excursion (search-backward "]")(search-forward "]")(thing-at-point 'sexp t))) (book "") (chapter "") (verse-num "") (Bible (concat emacs-sheath Bible-Directory (elt Bibles (- (read-number (concat (format "Choose a Bible: %s" Bibles) " Bible Number ")) 1))))) (message "Let #1") (with-current-buffer (or (get-file-buffer Bible) (find-file-noselect Bible)) (message "Change Buffer to %s" Bible) (save-excursion (message "move point") (goto-char (point-min)) (get-buffer-create "kjv-search") (with-current-buffer "kjv-search" (message "Change Buffer to kjv-search") (goto-char (point-min)) (insert verse) (goto-char (point-min)) (setq book (progn (re-search-forward "[A-z]+\\s-?[0-9]?") (substring (match-string 0) 1)) chapter (progn (goto-char (point-min)) (re-search-forward "[0-9]+:") (substring (match-string 0) 0 -1)) verse-num (progn (goto-char (point-min)) (re-search-forward ":[0-9]*") (substring (match-string 0) 1))) (setq book (emacs-sword--check-abbrev (string-trim-right book))) (message "set all search params") (kill-current-buffer)) (search-forward (string-trim-right (concat "** " book))) (message "book: %s" book) (search-forward (concat "Chapter " chapter)) (message "chapter: %s" chapter) (search-forward (concat "(" verse-num ")")) (message "verse: %s" verse-num) (message "%s" (point)) (message "%s" (current-buffer)) (setq output (concat "[[file:" Bible "::" (number-to-string (line-number-at-pos)) "]" verse "]" )) )) (save-excursion (let ((bound1 nil) (bound2 nil)) (search-backward "[") (setq bound1 (point)) (thing-at-point 'sexp) (search-forward "]") (setq bound2 (point)) (delete-region bound1 bound2) (insert output)))))
3.1.3. Word Search
This function searches the Bible of choice for WORD, where word is your word of choice, and prints all verses where WORD is found in a buffer. The command to run this function is C-S-b s (or Ctrl-Shift-b s) or you could call it with M-x emacs-sword-word-search (where M is Alt).
==:
(defun emacs-sword-word-search (word) "This function searches the Bible of choice for WORD, where word is your word of choice, and prints all verses where WORD is found in a buffer. The command to run this function is C-S-b s (or Ctrl-Shift-b s) or you could call it with M-x emacs-sword-word-search (where M is Alt)." (interactive "sWhich word to search? ") (let ((verse "") (chapter "") (book "") (pointer 1) (Bible (concat emacs-sheath Bible-Directory (elt Bibles (- (read-number (concat (format "Choose a Bible: %s" Bibles) " Bible Number ")) 1))))) (if (get-buffer "Word Search") (kill-buffer "Word Search")) (get-buffer-create "Word Search") (with-current-buffer "Word Search" (org-mode) (insert (concat "# Search String: '" word "'")) (message Bible) (display-buffer (current-buffer)) (with-current-buffer (or (get-file-buffer Bible) (find-file-noselect Bible)) (message (buffer-file-name)) (goto-char (point-min)) (while (re-search-forward word nil t) (save-excursion (message "search") (setq verse (thing-at-point 'line t) pointer (number-to-string (line-number-at-pos)) chapter (progn (re-search-backward "***\sChapter") (thing-at-point 'line t)) book (progn (org-up-heading-safe) (thing-at-point 'line t))) (with-current-buffer "Word Search" (message "print") (insert (concat "\n" (progn (if (equal book (progn (save-excursion (org-up-heading-safe) (thing-at-point 'line t)))) "" book)))) (insert (concat (progn (if (equal chapter (progn (save-excursion (org-back-to-heading) (thing-at-point 'line t)))) "" chapter)) verse "[[file:" Bible "::" pointer "][go to verse]]")) (delete-duplicate-lines (point-at-bol -4) (point)))))) (if (equal verse "") (insert "No Verses Found.")))))
3.1.4. Word Search Immediately
This function searches the Bible for your word of choice, and prints all verses where the word is found in a drawer. The command to run this function is C-S-b i s (or Ctrl-Shift-b i s) or you could call it with M-x emacs-sword-word-search-immediately (where M is Alt).
==:
(defun emacs-sword-word-search-immediately (word) (interactive "sWhich word to search? ") (let ((verse "") (chapter "") (book "") (pointer 1) (buff (buffer-name)) (Bible (concat emacs-sheath Bible-Directory (elt Bibles (- (read-number (concat (format "Choose a Bible: %s" Bibles) " Bible Number ")) 1))))) (message Bible) (display-buffer (current-buffer)) (insert (concat "\n:WordSearch:\n# Search String: '" word "'")) (with-current-buffer (or (get-file-buffer Bible) (find-file-noselect Bible)) (message (buffer-file-name)) (goto-char (point-min)) (while (re-search-forward word nil t) (save-excursion (message "search") (setq verse (thing-at-point 'line t) pointer (number-to-string (line-number-at-pos)) chapter (progn (re-search-backward "***\sChapter") (thing-at-point 'line t)) book (progn (org-up-heading-safe) (thing-at-point 'line t)))) (with-current-buffer buff (message "print") (insert (concat "\n" (progn (if (equal book (progn (save-excursion (org-up-heading-safe) (thing-at-point 'line t)))) "" (s-replace-regexp "\\** \\([ -z]*\\)" "- \\1 ::" book))))) (insert (concat (progn (if (equal chapter (progn (save-excursion (org-back-to-heading) (thing-at-point 'line t)))) "" (s-replace-regexp "\\** \\([ -z]*\\)" " - \\1 ::" chapter))) " " verse " [[file:" Bible "::" pointer "][go to verse]]")) (delete-duplicate-lines (point-at-bol -4) (point))))) (insert "\n:end:") (if (equal verse "") (insert "No Verses Found."))))
3.1.5. Audio Playing
This is a function for playing audio. To use, press 'C-S-b a' after a list with the format of (BOOKssCHAPTER) where BOOK is the book you want, s is space, and CHAPTER is the chapter you want to start on.
==:
(defun emacs-sword-play-audio () "This is a function for playing audio To use, press C-S-b a after a list with the format of (BOOKssCHAPTER) where BOOK is the book you want, s is space, and CHAPTER is the chapter you want to start on." (interactive) (let ((output "") (verse (save-excursion (search-backward ")")(or (thing-at-point 'list) (concat (thing-at-point 'sexp) ")")))) (book "") (chapter "") (multiple "")) (message "Let #1") (with-temp-buffer (message "Change Buffer to search") (goto-char (point-min)) (insert verse) (goto-char (point-min)) (message "Reference inserted in temp buffer") (setq book (progn (re-search-forward "[0-9]?\\s-?[A-z]+\\s-?[0-9]?") (match-string 0)) chapter (progn (re-search-forward "[0-9]+") (match-string 0)) multiple (if (equal ?- (following-char)) ">") default-directory (substring (shell-command-to-string (concat "/bin/echo " (expand-file-name (concat emacs-sheath Audio-Directory "*-\"" (string-trim-right book) "\"/")))) 0 -1)) (message "set all search params") (message multiple) (message default-directory) (setq output (concat "\"" book (if (equal (length chapter) 1) "0") chapter ".mp3\"")) (if (equal multiple ">") (progn (message "multiple") (setq chapter (number-to-string (+ 1 (string-to-number chapter)))) (message chapter) (while (file-exists-p (concat "" book (if (equal (length chapter) 1) "0") chapter ".mp3")) (setq output (concat output " " (concat "\"" book (if (equal (length chapter) 1) "0") chapter ".mp3\"")) chapter (number-to-string (+ 1 (string-to-number chapter)))) (message output)))) (message (concat player " " output)) (start-process-shell-command "emacs-sword-audio" nil (concat player " " output )))))
3.1.6. Book Abbreviation Expasion
checks if book is an abbreviation, if so, expands to full lenght
==:
(defun emacs-sword--check-abbrev (book) "checks if book is an abbreviation, if so, expands book to full length." (message book) (if (eq (length book) 3) (progn (message "Expanding book abbreviation...") (setq book (cdr (assoc book Abbreviations))) (message "done") (message book)) (progn (message "book not an abbeviation. Moving on...") (message book))))
3.1.7. Abbreviation List
==:
(defun emacs-sword-visit-abbrev () "lists all abbreviations and what they abbreviate in an alist" (interactive) (if (get-buffer "abbrev list") (kill-buffer "abbrev list")) (get-buffer-create "abbrev list") (with-current-buffer "abbrev list" (display-buffer (current-buffer)) (insert (format "%s" Abbreviations)) (goto-char (point-min)) (while (re-search-forward ")" nil t) (replace-match ")\n"))))
3.2. Resource and Dictionary Functions
3.2.1. Got To Definition
This function finds a Strong's Number in the previous list (eg. (g1)) and opens it in another window. The syntax is (DN) where D is h or g (h for hebrew and g for greek), and N is number The command to run this function is C-S-b g (or Ctrl-Shift-b g) or you could call it with M-x emacs-sword-goto-def (where M is Alt).
==:
(defun emacs-sword-goto-def () "This function finds a Strong's Number in the previous list (eg. (g1)) and opens it in another window. The syntax is (DN) where D is h or g (h for hebrew and g for greek), and N is number The command to run this function is C-S-b g (or Ctrl-Shift-b g) or you could call it with M-x emacs-sword-goto-def (where M is Alt)." (interactive) (let ((dictionary "") (id "") (command (save-excursion (search-backward ")") (thing-at-point 'list t)))) (get-buffer-create "kjv-search") (with-current-buffer "kjv-search" (message "Change Buffer to kjv-search") (goto-char (point-min)) (insert command) (goto-char (point-min)) (message "set dictionary...") (setq dictionary (progn (re-search-forward "h\\|g") (cond ((string= (match-string 0) "h") (concat emacs-sheath Hebrew)) ((string= (match-string 0) "g") (concat emacs-sheath Greek)))) id (progn (goto-char (point-min)) (re-search-forward "[0-9]+") (concat "(" (match-string 0) ")"))) (message "set all search params") (kill-current-buffer)) (message "%s" dictionary) (message "%s" id) (set-buffer (or (get-file-buffer dictionary) (find-file-noselect dictionary))) (goto-char (point-min)) (search-forward (concat "** " id)) (display-buffer (current-buffer)) (message "done")))
3.2.2. Link Resource
This function is for linking a resource. The syntax is [REFERNECE] where REFERENCE is the header (sans *s) you want to link. You can run this function with C-S-b l r.
==:
(defun emacs-sword-link-resource (desc) "This function is for linking a resource. The syntax is [REFERNECE] where REFERENCE is the header (sans *s) you want to link. You can run this function with C-S-b l r." (interactive "sWhat is the link decription?(default: [Reference]) ") (let ((output "") (resource (save-excursion (search-backward "]")(search-forward "]")(thing-at-point 'sexp t))) (chapter "") (book (concat emacs-sheath Resource-Directory (elt Resources (- (read-number (concat (format "Choose a Resource: %s" Resources) " Resource Number ")) 1))))) (message "Let #1") (with-current-buffer (or (get-file-buffer book) (find-file-noselect book)) (message "Change Buffer to %s" book) (save-excursion (message "move point") (goto-char (point-min)) (get-buffer-create "search") (with-current-buffer "search" (message "Change Buffer to search") (goto-char (point-min)) (insert resource) (goto-char (point-min)) (setq chapter (progn (goto-char (point-min)) (re-search-forward "\\[.+") (substring (match-string 0) 1 -1))) (message "set all search params") (if desc (setq desc chapter)) (message desc) (kill-current-buffer)) (re-search-forward (concat "\\*+\s" chapter)) (message "chapter: %s" chapter) (message "%s" (point)) (message "%s" (current-buffer)) (setq output (concat "[[file:" book "::" (number-to-string (line-number-at-pos)) "][" desc "]]" )) )) (save-excursion (let ((bound1 nil) (bound2 nil)) (search-backward "[") (setq bound1 (point)) (thing-at-point 'sexp) (search-forward "]") (setq bound2 (point)) (delete-region bound1 bound2) (insert output)))))
3.2.3. Visit Resources
Open the resource directory in a dired buffer. The key-binding for this is C-S-b r v
==:
(defun emacs-sword-visit-resources () (interactive) (dired (concat emacs-sheath Resource-Directory))) (defun emacs-sword-visit-dictionaries () (interactive) (dired (concat emacs-sheath Dictionary-Directory))) (defun emacs-sword-visit-bibles () (interactive) (dired (concat emacs-sheath Bible-Directory)))
3.2.4. Download Resources
You can download resources from MalanderEngineering.com or any other url you decide to use
==:
(defun emacs-sword-resource-downloader (url) (interactive "sPlease enter the url of the resource you want to download. if blank, you can see the resources at Resource-Repository: ") (message url) (if (> (length url) 1) (with-temp-buffer (setq-local def-dir default-directory default-directory (concat emacs-sheath Resource-Directory)) (shell-command (concat "wget '" url "'") t) (shell-command "unzip *.zip" t)) (progn (eww Resource-Repository) (switch-to-buffer "*eww*") (local-set-key (kbd "d") 'emacs-sword--download) (local-set-key (kbd "q") 'emacs-sword--kill-eww)))) (defun emacs-sword--kill-eww () (interactive) (local-set-key (kbd "d") 'eww-download) (kill-buffer "*eww*") (with-temp-buffer (setq-local def-dir default-directory default-directory (concat emacs-sheath Resource-Directory)) (shell-command "unzip *.zip" t) (shell-command "rm *.zip" t)))
3.2.5. download
simple fork of eww-download
==:
(defun emacs-sword--download () "simple fork of `eww-download'. Use link at point if there is one, else the current page's URL." (interactive) (access-file (concat emacs-sheath Resource-Directory) "Download failed") (let ((url (or (get-text-property (point) 'shr-url) (eww-current-url)))) (if (not url) (message "No URL under point") (url-retrieve url 'emacs-sword--download-callback (list url))))) (defun emacs-sword--download-callback (status url) (unless (plist-get status :error) (let* ((obj (url-generic-parse-url url)) (path (directory-file-name (car (url-path-and-query obj)))) (file (eww-make-unique-file-name (eww-decode-url-file-name (file-name-nondirectory path)) (concat emacs-sheath Resource-Directory)))) (goto-char (point-min)) (re-search-forward "\r?\n\r?\n") (let ((coding-system-for-write 'no-conversion)) (write-region (point) (point-max) file)) (message "Saved %s" file))))
3.3. Preperation and Initilisation
3.3.1. Emacs Sword Initialisation
This function generates some Bibles and Dictionaries once.
==:
(defun emacs-sword-init () (if (file-directory-p emacs-sheath) (message "Files found") (with-temp-buffer ;(make-directory emacs-sheath) ;(setq-local def-dir default-directory ; default-directory emacs-sheath) (shell-command "wget https://malanderengineering.com/packages/repo/emacs-sword.zip" t) (shell-command "unzip emacs-sword.zip" t) (shell-command (concat "mv emacs-sword" emacs-sheath) t) (shell-command "rm emacs-sword.zip" t))))
3.3.2. Customise Emacs Sword
This function opens the emacs-sword customization. The command to run this function is C-S-b c (or Ctrl-Shift-b c) or you could call it with M-x emacs-sword-customize (where M is Alt).
==:
(defun emacs-sword-customize () "This function opens the emacs-sword customization. The command to run this function is C-S-b c (or Ctrl-Shift-b c) or you could call it with M-x emacs-sword-customize (where M is Alt)." (interactive) (customize-group-other-window 'emacs-sword))
3.3.3. Prepare KJV+
this function is used for preparing KJV+ it is already complete, so you dont need it.
==:
(defun prepare-kjv+ () (interactive) (let ((id 1) (place (point))) (save-excursion (query-replace-regexp "(1)" "*** Chapter \n(1)") ) (save-excursion (while (search-forward "*** Chapter" nil t) (insert (concat " " (number-to-string id))) (setq id (+ id 1)))) (save-excursion (query-replace-regexp "H\\([0-9]+\\)" "[[file:strongshebrew.org::*(\\1)][\\1]]"))))
3.3.4. Reload KJV+ Numbers
This function corrects the links in KJV+. whenever you change your emacs-sword customization is it a good idea to run this command. The command to run this function is C-S-b r r (or Ctrl-Shift-b r r) or you could call it with M-x emacs-sword-reload-KJV+-numbers (where M is Alt).
==:
(defun emacs-sword-reload-KJV+-numbers () "This function corrects the links in KJV+. whenever you change your emacs-sword custom variables is it a good idea to run this command. The command to run this function is C-S-b r r (or Ctrl-Shift-b r r) or you could call it with M-x emacs-sword-reload-KJV+-numbers (where M is Alt)." (interactive) (let ((Bible (concat emacs-sheath Bible-Directory "KJV+.org"))) (with-current-buffer (or (get-file-buffer Bible) (find-file-noselect Bible)) (replace-regexp "file:.+?strong" (concat "file:" emacs-sheath Dictionary-Directory "strong")))))
3.4. Listify
This function makes a table into a list. You must use two column tables The keybinding is C-S-b t
==:
(defun emacs-sword-listify (table pre) "This function makes a table into a list. You must use two column tables The keybinding is C-S-b t" (interactive "nHow many rows (excluding key and --- based rows) are in the table? \nnHow many lines are key or --- based? ") (if (eq pre 0) (message "not killing lines") (dotimes (i (+ 1 pre)) (kill-line))) (let ((start (point)) (end (save-excursion (search-forward "\n" nil nil (+ 1 table))))) (replace-regexp "|\s+\\([,-z]+\\)\s+|\s+\\([,-z\s]+\\)\s+|" "-\s=\\1=\n\t\\2" nil start end)))
3.5. UI
3.5.1. Treemacs-sword init
This function checks if treemacs is availible, if so, makes an emacs sword workspace
==:
(if (require 'treemacs nil 'noerror) (defun emacs-sword--treemacs-sword () (if (string-search emacs-sheath (format "%s" (treemacs-workspaces))) (message "workspace exists...") (with-temp-buffer (treemacs-edit-workspaces) (goto-char (point-max)) (insert (concat "* Emacs Sword\n** Emacs-Sword\n- path :: " emacs-sheath)) (treemacs-finish-edit))))) (emacs-sword--treemacs-sword)
3.5.2. Emacs sword Treemacs
This function will open a treemacs buffer with the Emacs Sword workspace. Run by pressing C-S-b t.
==:
(defun emacs-sword-treemacs () (interactive) (treemacs-do-switch-workspace "Emacs Sword") (treemacs)))
4. Key Binding
These are the key bindings for emacs-sword. Do not alter unless you know what you are doing. If you do alter, please change the documentation accordingly
4.1. Bindings
==:
(define-prefix-command 'emacs-sword-map) (global-set-key (kbd "C-S-b") emacs-sword-map) ;prefix begin (define-prefix-command 'emacs-sword-link) (define-key emacs-sword-map (kbd "l") 'emacs-sword-link) (define-prefix-command 'emacs-sword-visit) (define-key emacs-sword-map (kbd "v") 'emacs-sword-visit) (define-prefix-command 'emacs-sword-resource-manipulation) (define-key emacs-sword-map (kbd "r") 'emacs-sword-resource-manipulation) (define-prefix-command 'emacs-sword-immediately) (define-key emacs-sword-map (kbd "i") 'emacs-sword-immediately) ;prefix end (define-key emacs-sword-map (kbd "f") 'emacs-sword-find-verse) (define-key emacs-sword-map (kbd "l v") 'emacs-sword-link-verse) (define-key emacs-sword-map (kbd "g") 'emacs-sword-goto-def) (define-key emacs-sword-map (kbd "c") 'emacs-sword-customize) (define-key emacs-sword-map (kbd "r r") 'emacs-sword-reload-KJV+-numbers) (define-key emacs-sword-map (kbd "s") 'emacs-sword-word-search) (define-key emacs-sword-map (kbd "i s") 'emacs-sword-word-search-immediately) (define-key emacs-sword-map (kbd "a") 'emacs-sword-play-audio) (define-key emacs-sword-map (kbd "l r") 'emacs-sword-link-resource) (if (require 'treemacs nil 'noerror) (define-key emacs-sword-map (kbd "t") 'emacs-sword-treemacs)) (define-key emacs-sword-map (kbd ";") 'emacs-sword-listify) (define-key emacs-sword-map (kbd "v r") 'emacs-sword-visit-resources) (define-key emacs-sword-map (kbd "v d") 'emacs-sword-visit-dictionaries) (define-key emacs-sword-map (kbd "v b") 'emacs-sword-visit-bibles) (define-key emacs-sword-map (kbd "v a") 'emacs-sword-visit-abbrev) (define-key emacs-sword-map (kbd "r d") 'emacs-sword-resource-downloader)
5. Package footer
this is a footer for the package
==:
(provide 'emacs-sword) ;;; emacs-sword.el ends here