Setup a personal wiki in Emacs Org-mode

▼魔方 西西 提交于 2019-12-03 02:28:17

Having only one note file is, in my opinion, more flexible and compatible. It tends, however, to get slow for even moderatly sized files. Multiple small files are quick, but they need more effort to set up, and they only work within that setup.

Single File Solution

To speed things up, consider setting org-startup-with-latex-preview to nil (or add #+STARTUP: nolatexpreview to your file).

Tags not only get messy when used for keywords, using them also gets rather slow as your file grows. I've played around with some custom functions, but now avoid tags most of the time. Instead I use flat hierarchies, categories and otherwise rely on occur and org-occur (e.g. M-x org-occur begin_proof).

Multiple Files

The org syntax for linking to other files is rather simple: [[./this idea.org][this idea]]. If that is too much hassle, it should be easy to write a function that replaces the active region with an appropriate link.

If you want to link [[this idea]] to a file "this idea.org", you could add a function to org-open-at-point-functions and handle it yourself.

As for tags, you don't tag a file itself, but rather a single top level headline. This of course means that all your troubles with tags a back as well. Again, I would recommend not using tags. Just make sure the file contains the right keywords at the right places and use occur and friends.

Edit: An Example `org-open-at-point-function'

If you want to search for a fuzzy link in all files in a directory instead of only the current buffer, you can do this by using the org-open-at-point-functions hook. Here is an example:

(defvar my-link-search-directory "/my/notes/directory/")

(defun my-open-link-function ()
  "Open link, interpreting it a the name of a headline."
  (let* ((el (org-element-context))
         (type (first el))
         (link-type (plist-get (cadr el) :type))
         (path (let ((path-1 (plist-get (cadr el) :path)))
                 (when (stringp path-1)
                   (org-link-unescape path-1)))))
    (when (and (eql type 'link)
               path
               (string= link-type "fuzzy"))
      (let* ((path (regexp-quote path))
             (result
                 (delq nil
                       (org-map-entries
                        (lambda ()
                          (when (string-match
                                 path
                                 (org-get-heading))
                            (list (buffer-file-name) (point))))
                        nil
                        ;; Here we set the scope.
                        ;; 'agenda would search in all agenda files.
                        ;; We want a list of all org files in `my-link-search-directory'.
                        (directory-files
                         my-link-search-directory
                         t "[.]org\\'")))))
        (when result
          (when (> (length result) 1)
            (message "Warning: multiple search results for %s" path))
          (let ((file (caar result))
                (pos (cadar result)))
            (find-file file)
            (goto-char pos)))))))


(add-hook 
 'org-open-at-point-functions
 'my-open-link-function)

Note that I haven't tested this much.

Actually, I would recommend against using this unless you really need it. While making fancy extensions is tempting, keeping your notes as simple as possible is preferably. If you have everything in one file, you could edit your notes with notepad or google docs or whatever, should you ever need to.

I'm using a simplistic code for a wiki. Because that's what a wiki is for me: a quick way to categorize things. The structure is a following:

  • each subject has its own org file
  • each topic of subject has its own heading
  • all org files are in single directory
  • you can jump to file, or create a new file with helm

That's it. I've found to need to link anything to anything, jump-to-subject functionality is more than enough. Here's how this looks:

And once within a subject, I can jump across topics with worf. Here's how this looks:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!