Coder Social home page Coder Social logo

obsidian.el's Introduction

Obsidian Notes for Emacs

https://melpa.org/packages/obsidian-badge.svg https://stable.melpa.org/packages/obsidian-badge.svg

Emacs front-end for Obsidian Notes.

Table of Contents

Installation

Obsidian.el is available from MELPA or MELPA Stable and can be installed with:

M-x package-install RET obsidian RET

Put this in your init.el:

(require 'obsidian)
(obsidian-specify-path "~/MY_OBSIDIAN_FOLDER")
;; If you want a different directory of `obsidian-capture':
(setq obsidian-inbox-directory "Inbox")

;; Define obsidian-mode bindings
(add-hook
 'obsidian-mode-hook
 (lambda ()
   ;; Replace standard command with Obsidian.el's in obsidian vault:
   (local-set-key (kbd "C-c C-o") 'obsidian-follow-link-at-point)

   ;; Use either `obsidian-insert-wikilink' or `obsidian-insert-link':
   (local-set-key (kbd "C-c C-l") 'obsidian-insert-wikilink)

   ;; Following backlinks
   (local-set-key (kbd "C-c C-b") 'obsidian-backlink-jump)))

;; Optionally you can also bind `obsidian-jump' and `obsidian-capture'
;; replace "YOUR_BINDING" with the key of your choice:
(global-set-key (kbd "YOUR_BINDING") 'obsidian-jump)
(global-set-key (kbd "YOUR_BINDING") 'obsidian-capture)

;; Activate detection of Obsidian vault
(global-obsidian-mode t)

Or using use-package:

(use-package obsidian
  :ensure t
  :demand t
  :config
  (obsidian-specify-path "~/MY_OBSIDIAN_FOLDER")
  (global-obsidian-mode t)
  :custom
  ;; This directory will be used for `obsidian-capture' if set.
  (obsidian-inbox-directory "Inbox")
  :bind (:map obsidian-mode-map
  ;; Replace C-c C-o with Obsidian.el's implementation. It's ok to use another key binding.
  ("C-c C-o" . obsidian-follow-link-at-point)
  ;; Jump to backlinks
  ("C-c C-b" . obsidian-backlink-jump)
  ;; If you prefer you can use `obsidian-insert-link'
  ("C-c C-l" . obsidian-insert-wikilink)))

Optionally you can specify obsidian-inbox-directory, it will be used by obsidian-capture to store new notes into. If you don’t set it the root folder of your Obsidian vault will be used.

About Obsidian.el

I wanted to work with Obsidian Notes using Emacs. Obviously you already can open your Obsidian folder and start editing markdown files with Emacs. But I want to improve that and split the responsibilities between Emacs and Obsidian the way it makes sense for an Emacs user.

What should we keep doing in Obsidian?

  • Sync
  • Mobile client (of course, and that’s where Obsidian beats anything else in Emacs)
  • Complex exploring (graph views etc)
  • All the things done with complex plugins

What should be possible to do in Emacs?

Obsidian.el must empower us to stay in Emacs for things that make sense in Emacs:

  • [X] Creating and editing notes with convenient autocomplete for tags and links (nothing will ever compare to Emacs in terms of editing power)
  • [X] Jumping between notes
  • [X] Searching all notes
  • [X] Finding all notes with a tag
  • [X] Following backlinks
  • [ ] Viewing backlinks in a separate list

When all of the above is ready we will almost never need the Obsidian app on desktop, but will still be able to use it on mobile or when specifically needed.

How does obsidian.el work?

obsidian-mode

When you require obsidian.el via use-package or in other ways (see snippet above), you have to specify the root folder of your Obsidian Notes vault. If global-obsidian-mode is enabled and if you specified the root folder, each time you open a markdown buffer it checks, if that file is part of your Obsidian Notes vault. If it is obsidian-mode minor mode is activated for this buffer.

company-mode completion

./resources/tag-completion.png

Once the obsidian-mode is activated obsidian.el scans all markdown files in the vault for tags and links (links still WIP), and stores these lists in it’s global variables. It also adds company-mode backends to suggest links and tags for completion.

Hydra menu

When Hydra is installed, obsidian-hydra will be defined such that it can be used for bindings:

(bind-key (kbd "C-c M-o") 'obsidian-hydra/body 'obsidian-mode-map)

./resources/hydra-menu.png

Manual re-scan

You can update the lists of tags, links etc. manually if it’s lagging for some reason by running an interactive command:

M-x obsidian-update RET

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. In the install example above this command is bound to C-c C-o in obsidian-mode.

M-x obsidian-follow-link-at-point RET

Note that the Obsidian app replaces spaces with %20 when inserting markdown links, and doesn’t do that when inserting wiki links. Obsidian.el follows this convention to maximize compatibility:

Markdown link with spaces: [2-sub with spaces and буквы](subdir/2-sub%20with%20spaces%20and%20буквы.md)

Wikilink with spaces: [[Subdir/2-sub with spaces and буквы]]

Both these types of links are correctly handled by obsidian-follow-link-at-point.

Following backlinks

You can quickly jump to backlinks to current file using obsidian-backlink-jump

M-x obsidian-backlink-jump RET

Multiple matches

Obsidian doesn’t insert relative path by default, only does it when there are multiple files with the same name. obsidian-follow-link-at-point handles this correctly. Every time you follow a link it checks, if there’s only one match for the filename linked. If there’s just one it simply opens that file. If there’s more than one it prompts you to select which file to open.

Inserting links

./resources/insert-link.png

There are two commands to insert links obsidian-insert-link and obsidian-insert-wikilink, you can choose one depending on your preferred link format:

Inserts a link in Markdown format

Example: [Link description](path/to/file.md)

M-x obsidian-insert-link RET

Note, that when you insert a link to file that has spaces in it’s name, like “facts about inserting links.md”, Obsidian app would html-format the spaces, meaning the link will look like

[facts](facts%20about%20inserting%20links.md)

Obsidian.el follows this convention and does the same when inserting markdown links. obsidian-follow-link-at-point handles this correctly.

Insert a link in wikilink format

Example: [[path/fo/file.md|Link description]]

M-x obsidian-insert-wikilink RET

Jumping between notes

Quickly jump between notes using obsidian-jump

M-x obsidian-jump RET

Aliases

If you have YAML front matter in your note, Obsidian.el will find aliases in it and add them to the obsidian-jump selection. Both aliases and alias keys are supported.

Capturing new note

Use obsidian-capture. If you specified obsidian-inbox-directory, it will create new notes in this directory. Otherwise in your Obsidian vault root directory:

M-x obsidian-capture RET

Searching notes

Use obsidian-search to look for a string or a regular expression:

M-x obsidian-search RET query RET

Finding all notes with a tag

Use obsidian-tag-find to list all notes that contain a tag. Let’s you choose a tag from list of all tags:

M-x obsidian-tag-find RET

Move note to another folder

Use obsidian-move-file to move current note to another folder:

M-x obsidian-move-file RET

Development tasks

  • [X] Specify Obsidian folder and save it in variables
  • [X] Enumerate files in the Obsidian folder and save a list
  • [X] Run the scan when entering obsidian-mode
  • [X] Functions to scan notes for tags
  • [X] Get full list of all tags
  • [X] company-backend with tags
  • [X] commands to insert links in markdown and wikilink
  • [X] Capture command to create a new note in Obsidian folder
  • [X] Obsidian minor for matching .md files
  • [X] Jumping between notes
  • [X] Following links
  • [X] Following backlinks

Why obsidian.el and not…

Obsidian App itself, Athens Research or any other great app?

Easy. When on desktop they are simply not Emacs. Not even Obsidian itself. Emacs beats anything else for things that it is built for. But you know this already, otherwise you wouldn’t be here.

Org-roam or any other great Emacs libraries?

The answer is mostly the same for all of them. Mobile support. Or rather — NO mobile support. I don’t buy into the story that “you don’t really need your PKM system on mobile”, and “serious work is done only on desktop” etc. These are just excuses for the impossibility of building a full-fledged mobile version of Emacs.

So there were two ways to go about it: build a mobile app for something like org-roam (which would be cool, but is above my front-end skills) or build a light-weight Emacs client for something like Obsidian. I chose the simpler task.

Contributing

PRs and issues are very welcome. In order to develop locally you need to install eldev. After that you can run make commands, in particular make test and make lint to make sure that your code will pass all MELPA checks.

Gratitude

  • The work on Obsidian.el was made considerably easier and definitely more fun thanks to the great work of Magnar Sveen and his packages dash.el and s.el. Thank you for making Elisp almost as convenient as Clojure!
  • During the development of Obsidian.el I have learned and copied from the code of the amazing org-roam package. Thank you!

obsidian.el's People

Contributors

gabriel-francischini avatar krydos avatar licht1stein avatar mastro35 avatar netromdk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.