Skip to content

Commit

Permalink
Reindent code
Browse files Browse the repository at this point in the history
Fix indentation and flatten the progn in bog-mode.
  • Loading branch information
basil-conto committed Jun 25, 2020
1 parent 6184e74 commit 30fc844
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 69 deletions.
110 changes: 56 additions & 54 deletions bog-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -240,22 +240,22 @@ some text and <point><citekey>"

(ert-deftest bog-citekeys-in-buffer ()
(should (equal '("abc1900def" "ghi1950jkl" "mno2000pqr")
(bog-tests-with-temp-text
"
(bog-tests-with-temp-text
"
* abc1900def
ghi1950jkl
* mno2000pqr
* mno2000pqr"
(sort (bog-citekeys-in-buffer) #'string-lessp)))))
(sort (bog-citekeys-in-buffer) #'string-lessp)))))

(ert-deftest bog-heading-citekeys-in-buffer ()
(should (equal '("abc1900def" "mno2000pqr")
(bog-tests-with-temp-text
"
(bog-tests-with-temp-text
"
* abc1900def
ghi1950jkl
* mno2000pqr"
(bog-heading-citekeys-in-buffer)))))
(bog-heading-citekeys-in-buffer)))))

(ert-deftest bog-next-non-heading-citekey/default-arg ()
(let ((citekey "name2010word"))
Expand Down Expand Up @@ -352,69 +352,71 @@ other2000key <citekey>"

(ert-deftest bog-all-file-citekeys ()
(bog-tests-with-temp-dir
(let ((bog-file-directory (expand-file-name "citekey-files")))
(make-directory bog-file-directory)
(let ((default-directory bog-file-directory))
(make-directory "key2000butdir"))
(write-region "" nil (expand-file-name "nokey.pdf" bog-file-directory))
(write-region "" nil (expand-file-name "one2010key.pdf" bog-file-directory))
(write-region "" nil (expand-file-name "two1980key.txt" bog-file-directory))
(should (equal (bog-all-file-citekeys)
'("one2010key" "two1980key"))))))
(let ((bog-file-directory (expand-file-name "citekey-files")))
(make-directory bog-file-directory)
(let ((default-directory bog-file-directory))
(make-directory "key2000butdir"))
(write-region "" nil (expand-file-name "nokey.pdf" bog-file-directory))
(write-region "" nil (expand-file-name "one2010key.pdf"
bog-file-directory))
(write-region "" nil (expand-file-name "two1980key.txt"
bog-file-directory))
(should (equal (bog-all-file-citekeys)
'("one2010key" "two1980key"))))))

(ert-deftest bog-rename-staged-file-to-citekey/one-file ()
(bog-tests-with-temp-dir
(let ((bog-stage-directory (expand-file-name "stage"))
(bog-file-directory (expand-file-name "citekey-files"))
(citekey "name2010word"))
(make-directory bog-stage-directory)
(make-directory bog-file-directory)
(write-region "" nil (expand-file-name "one.pdf" bog-stage-directory))
(bog-tests-with-temp-text
"
(let ((bog-stage-directory (expand-file-name "stage"))
(bog-file-directory (expand-file-name "citekey-files"))
(citekey "name2010word"))
(make-directory bog-stage-directory)
(make-directory bog-file-directory)
(write-region "" nil (expand-file-name "one.pdf" bog-stage-directory))
(bog-tests-with-temp-text
"
* top level
** <point><citekey>
some text"
(bog-rename-staged-file-to-citekey))
(should (file-exists-p (expand-file-name
(concat citekey ".pdf") bog-file-directory)))
(should-not (file-exists-p (expand-file-name
"one.pdf" bog-stage-directory))))))
(bog-rename-staged-file-to-citekey))
(should (file-exists-p (expand-file-name
(concat citekey ".pdf") bog-file-directory)))
(should-not (file-exists-p (expand-file-name
"one.pdf" bog-stage-directory))))))

(ert-deftest bog-rename-staged-file-to-citekey/one-file-subdir ()
(bog-tests-with-temp-dir
(let ((bog-stage-directory (expand-file-name "stage"))
(bog-file-directory (expand-file-name "citekey-files"))
(citekey "name2010word")
(bog-subdirectory-group 2))
(make-directory bog-stage-directory)
(make-directory bog-file-directory)
(write-region "" nil (expand-file-name "one.pdf" bog-stage-directory))
(bog-tests-with-temp-text
"
(let ((bog-stage-directory (expand-file-name "stage"))
(bog-file-directory (expand-file-name "citekey-files"))
(citekey "name2010word")
(bog-subdirectory-group 2))
(make-directory bog-stage-directory)
(make-directory bog-file-directory)
(write-region "" nil (expand-file-name "one.pdf" bog-stage-directory))
(bog-tests-with-temp-text
"
* top level
** <point><citekey>
some text"
(bog-rename-staged-file-to-citekey))
(should (file-exists-p (expand-file-name
(concat "2010/" citekey ".pdf") bog-file-directory)))
(should-not (file-exists-p (expand-file-name
"one.pdf" bog-stage-directory))))))
(bog-rename-staged-file-to-citekey))
(should (file-exists-p (expand-file-name (concat "2010/" citekey ".pdf")
bog-file-directory)))
(should-not (file-exists-p (expand-file-name
"one.pdf" bog-stage-directory))))))

(ert-deftest bog-file-citekeys/multiple-variants ()
(bog-tests-with-temp-dir
(let* ((bog-file-directory (expand-file-name "citekey-files"))
(citekey "name2010word")
(variants (list (concat citekey ".pdf")
(concat citekey ".txt")
(concat citekey "_0.pdf")
(concat citekey "-supplement.pdf")))
files-found)
(make-directory bog-file-directory)
(dolist (var variants)
(write-region "" nil (expand-file-name var bog-file-directory)))
(setq files-found (bog-citekey-files citekey))
(should (= (length files-found) 4)))))
(let* ((bog-file-directory (expand-file-name "citekey-files"))
(citekey "name2010word")
(variants (list (concat citekey ".pdf")
(concat citekey ".txt")
(concat citekey "_0.pdf")
(concat citekey "-supplement.pdf")))
files-found)
(make-directory bog-file-directory)
(dolist (var variants)
(write-region "" nil (expand-file-name var bog-file-directory)))
(setq files-found (bog-citekey-files citekey))
(should (= (length files-found) 4)))))


;;; BibTeX functions
Expand Down
29 changes: 14 additions & 15 deletions bog.el
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ If the citekey prompt is slow to appear, consider enabling the
(citekey (bog-citekey-from-point-or-all-headings no-context))
(marker (with-current-buffer (or (buffer-base-buffer)
(current-buffer))
(bog--find-citekey-heading-in-notes citekey))))
(bog--find-citekey-heading-in-notes citekey))))
(if marker
(with-current-buffer (marker-buffer marker)
(org-with-wide-buffer
Expand Down Expand Up @@ -1433,20 +1433,19 @@ if ARG is omitted or nil.
\\{bog-mode-map}"
:lighter " Bog"
(progn
(cond
(bog-mode
(if (derived-mode-p 'org-mode)
(add-hook 'org-font-lock-hook #'bog-fontify-non-heading-citekeys)
(font-lock-add-keywords nil bog-citekey-font-lock-keywords)))
(t
(if (derived-mode-p 'org-mode)
(remove-hook 'org-font-lock-hook #'bog-fontify-non-heading-citekeys)
(font-lock-remove-keywords nil bog-citekey-font-lock-keywords))
(when (bound-and-true-p bog-view-mode)
(bog-view-mode -1))))
(when font-lock-mode
(funcall bog-font-lock-function))))
(cond
(bog-mode
(if (derived-mode-p 'org-mode)
(add-hook 'org-font-lock-hook #'bog-fontify-non-heading-citekeys)
(font-lock-add-keywords nil bog-citekey-font-lock-keywords)))
(t
(if (derived-mode-p 'org-mode)
(remove-hook 'org-font-lock-hook #'bog-fontify-non-heading-citekeys)
(font-lock-remove-keywords nil bog-citekey-font-lock-keywords))
(when (bound-and-true-p bog-view-mode)
(bog-view-mode -1))))
(when font-lock-mode
(funcall bog-font-lock-function)))


;;; View minor mode
Expand Down

0 comments on commit 30fc844

Please sign in to comment.