Skip to content

Commit

Permalink
Code cleanup, removing dead code and renaming public/private function…
Browse files Browse the repository at this point in the history
…s as appropriate
  • Loading branch information
jayemar committed Dec 5, 2024
1 parent c9ad809 commit d95aade
Show file tree
Hide file tree
Showing 3 changed files with 264 additions and 286 deletions.
39 changes: 17 additions & 22 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Obsidian Notes does not need to be installed to make use of the full functionali

* Table of Contents :toc:
- [[#why-obsidianel][Why obsidian.el]]
- [[#what-should-we-keep-doing-in-obsidian][What should we keep doing in Obsidian?]]
- [[#what-should-we-keep-doing-in-obsidian-blorg][What should we keep doing in Obsidian blorg?]]
- [[#what-should-be-possible-to-do-in-emacs][What should be possible to do in Emacs?]]
- [[#why-obsidianel-and-not][Why obsidian.el and not...]]
- [[#installation][Installation]]
Expand All @@ -28,7 +28,6 @@ Obsidian Notes does not need to be installed to make use of the full functionali
- [[#front-matter][Front Matter]]
- [[#templates][Templates]]
- [[#markdown-mode-functionality][markdown-mode functionality]]
- [[#markdown-toc][markdown-toc]]
- [[#versioning][Versioning]]
- [[#architecture-of-obsidianel][Architecture of obsidian.el]]
- [[#data-structures][Data structures]]
Expand Down Expand Up @@ -78,7 +77,7 @@ Obsidian.el is available from [[https://melpa.org][MELPA]] or [[https://stable.m

You'll then want to enable ~obsidian-mode~ as well as the optional ~obsidian-backlinks-mode~ if you'd like to use the backlinks panel.

Below is an example configuration that can be used in your ~init.el~ file. Note the use of ~setopt~ (as opposed to ~setq~)for setting these values. This ensures that all required initialization will occur after these values are set.
Below is an example configuration that can be used in your ~init.el~ file. Note the use of ~setopt~ (as opposed to ~setq~) for setting these values; this ensures that all required initialization will occur after these values are set.

#+begin_src elisp
(require 'obsidian)
Expand Down Expand Up @@ -209,7 +208,7 @@ If you have a link but decide that you'd like to remove it while keeping the lin
#+end_src

** Following links
Obsidian.el implements a custom command ~obsidian-follow-link-at-point~ which correctly follows markdown and wiki links generated by the Obsidian App, as well as backlinks and markdown-toc links created in obsidian.el. In the installation example above, this command is bound to ~C-c C-o~ in ~obsidian-mode~.
Obsidian.el implements a custom command ~obsidian-follow-link-at-point~ which correctly follows markdown and wiki links generated by the Obsidian App, as well as backlinks from the backlinks panel. In the installation example above, this command is bound to ~C-c C-o~.

#+begin_src
M-x obsidian-follow-link-at-point RET
Expand Down Expand Up @@ -299,7 +298,7 @@ You can also simply type in a tag and obsidian.el and it will be recognized by o
*** company-mode completion
[[./resources/tag-completion.png]]

Obsidian.el also adds a [[http://company-mode.github.io/][company-mode]] backend to suggest tags for completion. This can be triggered with ~obsidian-tags-backend~.
Obsidian.el also adds a [[http://company-mode.github.io/][company-mode]] backend to suggest tags for completion. This can be triggered with ~obsidian--tags-backend~.

** Searching for a tag
Use ~obsidian-find-tag~ to list all notes that contain a tag and select one to open.
Expand Down Expand Up @@ -380,10 +379,6 @@ obsidian.el builds upon [[https://jblevins.org/projects/markdown-mode/][markdown
- markdown-previous-link :: move point to previous link in note (M-p by default)
- markdown-toggle-markup-hiding :: hide markdown formatting to view raw text

** markdown-toc

Obsidian.el recognized ~markdown-toc~ as a way to generate a table of contents for a note file.

* Versioning
The project uses [[https://github.com/ptaoussanis/encore/blob/master/BREAK-VERSIONING.md][break versioning]], meaning that upgrading from 1.0.x to 1.0.y will always be safe, upgrading from 1.x.x to 1.y.x might break something small, and upgrade from x.x.x to y.x.x will break almost everything.

Expand Down Expand Up @@ -417,21 +412,21 @@ Function that rebuilds both ~obsidian-vault-cache~ and ~obsidian--aliases-map~.

This is a relatively heavy operation so ideally would only called at startup by ~after-init-hook~. All relevant information is retrieved with a single reading of the files on disk with an associated single call to ~with-temp-buffer~.

The rough pseudo-code for this function looks like this:
The pseudo-code for this function roughly looks like this:
- directory-files-recursively
- obsidian--add-file
- obsidian--update-file-metadata
- obsidian--find-tags-in-string
- obsidian--find-aliases-in-string
- obsidian--find-links
- obsidian-add-file
- obsidian-update-file-metadata
- obsidian-find-tags-in-string
- obsidian-find-aliases-in-string
- obsidian-find-links

*** obsidian-update
Compares the list of currently cached files against the files on disk, removing any files from cache that no longer exist and adding files that exist on disk but not in the cache.

Will call ~obsidian-rescan-cache~ if that function has not yet been run, but it should be run on startup.

*** obsidian--add-file
One of the two main internal functions along with ~obsidian--remove-file~.
*** obsidian-add-file
One of the two main internal functions along with ~obsidian-remove-file~.

File will be added to the cache if it's not already there, the tags list and alias list for that file will be updated, and finally the aliases list will be synced with the obsidian--aliases-map.

Expand All @@ -440,16 +435,16 @@ File will be added to the cache if it's not already there, the tags list and ali
3. update aliases for file
4. sync list of aliases with ~obsidian--aliases-map~

*** obsidian--remove-file
One of the two main internal functions along with ~obsidian--add-file~.
*** obsidian-remove-file
One of the two main internal functions along with ~obsidian-add-file~.

1. Remove aliases for file from ~obsidian--aliases-map~
2. Remove file record from ~obsidian-vault-cache~

*** obsidian--update-on-save
Function meant to be added as a hook to ~after-save-hook~.
Function added to ~after-save-hook~ to update file metadata after saving.

Checks to see if the saved file is an obsidian file, and if so, the record in the vault cache for the file is updated with a call to ~obsidian--add-file~.
Checks to see if the saved file is an obsidian file, and if so, the record in the vault cache for the file is updated with a call to ~obsidian-add-file~.

** Cache update timer
All of the file and metadata updates should be handled by the functions and hooks of =obsidian.el= when a file is saved or moved. However, if a file is add or deleted out of band of =obsidian.el= by some other process, we need a way to include the information in our caches.
Expand All @@ -468,7 +463,7 @@ PRs and issues are very welcome. In order to develop locally you need to install

Take a look at the open [[https://github.com/licht1stein/obsidian.el/issues][issues]] if you're looking for a way to contribute.

If updating this README file, note that the table of contents is generate with the package ~toc-org~.
If updating this README file, note that the table of contents is generate with the package ~toc-org~, specifically the function ~toc-org-insert-toc~.

* Gratitude
- The work on Obsidian.el was made considerably easier and definitely more fun thanks to the great work of [[https://github.com/magnars][Magnar Sveen]] and his packages [[https://github.com/magnars/dash.el][dash.el]] and [[https://github.com/magnars/s.el][s.el]]. Thank you for making Elisp almost as convenient as Clojure!
Expand Down
Loading

0 comments on commit d95aade

Please sign in to comment.