需求:
- 之前记笔记的方式为安装文件夹组织笔记形式,一个文件夹内是同一个主题的笔记,但是有时候笔记多了发现管理比较混乱,不是很方便回头看;
2 基于1, 实现一个overview的content 目录的文件,方便管理,主要是按主题搜索;
- 最近双向链接比较好用,后来发现主要是能直观的按照图片展示;
实现:
-
直接暴力的在文件末尾插入引用的link;
-
将文件 和 引用关系维护在 0-roam-overview.txt文件中;(alias txt直接使用org-mode)
-
当需要查看引用关系时,使用org-bable 利用dot (graphviz)生成图片,另外一个好处是可以拿生成的图片用与更高层的引用;
已有简单的功能:
-
插入一个新建文件,在新文件buffer中使用creat-single-file;
-
在文件中插入新建文件,并且当前文件引用新建文件;(我一般笔记每一个都比较小,按照文件的粒度比较合适)
-
1,2都是在同一个目录中的引用,当需要引用其他目录时,直接手动输入文件相对路径;
结果:
- 文件夹文件:
- 文件中的link,
-
overview file
-
图片关系
PTW写了一下Elisp,发现vim中的exec()函数直接执行命令很好用,菜鸡不晓得Emacs有没有对应的实现方式;
- 很挫的code
问题:不支持中文文件名以及 user为中文,graphviz和emacs没有配置,不支持中文,主要是因为菜,能用就可以
;;TODO if need any other scence, v-roam-insert shall as base api ;;
(defun v-roam-creat-single-file()
(interactive)
;; 1. creat a new file ,and use this command puts file link to overview file
;; isolation file, without any connect
(let* ((vv-roam-cur-file-name (file-name-nondirectory buffer-file-name)))
;; refresh roam overview file
(v-roam-overview-refresh t vv-roam-cur-file-name "")
))
(defun v-roam-creat-insert()
(interactive)
(let* ((vv-roam-cur-file-name (file-name-nondirectory buffer-file-name))
(vv-roam-link-file-name (read-string "input the reference note name, if no,type N:"))
(vv-roam-ref-link (format"roam ref note: [[file:%s]]" vv-roam-link-file-name))
(vv-roam-back-link (format"roam back note: [[file:%s]]" vv-roam-cur-file-name)))
;; insert reference link @ the end of file name
(goto-char (point-max))
(newline 1)
(forward-line)
(insert vv-roam-ref-link)
;; insert back link @ the end of file name
(if (equal "y" (read-char "need insert back link? if yes, type \"y\":"))
(progn
(find-file vv-roam-link-file-name)
(goto-char (point-max))
(newline 1)
(forward-line)
(insert vv-roam-back-link)))
;; refresh roam overview file
(v-roam-overview-refresh nil vv-roam-cur-file-name vv-roam-link-file-name)
))
(defun v-roam-insert-otherdir()
(interactive)
(let* ((vv-roam-cur-file-name (file-name-nondirectory buffer-file-name))
;;(vv-roam-link-file-name (read-file-name "input the reference note name:"))
;; mannual input relative path, for use @different device
(vv-roam-link-file-name (read-string "input the reference note name:"))
(vv-roam-ref-link (format"roam ref note: [[file:%s]]" vv-roam-link-file-name))
(vv-roam-back-link (format"roam back note: [[file:%s]]" vv-roam-cur-file-name)))
;; insert reference link @ the end of file name
(goto-char (point-max))
(newline 1)
(forward-line)
(insert vv-roam-ref-link)
;; insert back link @ the end of file name
(if (equal "y" (read-char "need insert back link?:"))
(progn
(find-file vv-roam-link-file-name)
(goto-char (point-max))
(newline 1)
(forward-line)
(insert vv-roam-back-link)))
;; refresh roam overview file
(v-roam-overview-refresh nil vv-roam-cur-file-name vv-roam-link-file-name)
))
;;
(defun v-roam-overview-refresh(vv-roam-create-single-file vv-roam-cur-file vv-roam-link-file)
(if (not (file-exists-p "0-roam-overview.org"))
(progn
(find-file "0-roam-overview.org")
(goto-char (point-min))
(insert "* all-notes-list")
(newline)
(forward-line)
(insert "* roam-relationship")
(newline)
(insert "#+BEGIN_SRC dot :file 0-roam-overview.png :cmdline -Kdot -Tpng")
(newline)
(insert "digraph G {")
(newline)
(insert "//roam-connect-start")
(newline)
(insert "}")
(newline)
(insert "#+END_SRC")
))
;; put file input overview file list
(find-file "0-roam-overview.org")
(goto-char (point-min))
(if (not (re-search-forward (format "\\[\\[file:%s\\]\\]" vv-roam-cur-file) (point-max) t 1))
(progn
(goto-char (point-min))
(search-forward "* all-notes-list" (point-max) t)
(newline 1)
(insert (format "[[file:%s]]" vv-roam-cur-file))))
(if (equal nil vv-roam-create-single-file)
(progn
(goto-char (point-min))
(if (not (re-search-forward (format "\\[\\[file:%s\\]\\]" vv-roam-link-file) (point-max) t 1))
(progn
(goto-char (point-min))
(search-forward "* all-notes-list" (point-max) t)
(newline 1)
(insert (format "[[file:%s]]" vv-roam-link-file))))
;; insert roam file connect
(goto-char (point-min))
(if (search-forward "roam-connect-start" (point-max) t 1)
(progn
(newline)
(insert (format " \"%s\" -> \"%s\";" vv-roam-cur-file vv-roam-link-file)))))
(progn
;; insert roam file connect
(goto-char (point-min))
(if (search-forward "roam-connect-start" (point-max) t 1)
(progn
(newline)
(insert (format " \"%s\";" vv-roam-cur-file)))))
) ;;end if
(setq buffer-save-without-query t)
(save-some-buffers)
(setq buffer-save-without-query nil)
) ;;end defun