diff --git a/README.org b/README.org index d2ee67b..2953357 100644 --- a/README.org +++ b/README.org @@ -7,7 +7,65 @@ #+HTML_HEAD: #+HTML_HEAD: - +*This repo is a fork of the original [[https://github.com/caiorss/org-wiki][org-wiki]] by caiorss.* The plan for this +fork is to extend the original org-wiki to make it the Emacs(-lisp) equivalent +of the great [[https://zim-wiki.org/][zim]] desktop wiki software (but even nicer). + +[[https://github.com/caiorss/org-wiki][org-wiki]] offers a nice starter "template" for the project. However, that package +is a little outdated and it requires an update to make it use more modern tools +like [[https://orgmode.org/worg/org-tutorials/org-publish-html-tutorial.html][org-publish]], [[https://github.com/alphapapa/org-ql][org-ql]]/[[https://github.com/alphapapa/org-rifle][org-rifle]], [[https://github.com/alphapapa/org-sidebar][org-sidebar]]/[[https://github.com/toshism/org-super-links][org-super-links]] etc. Also I +would prefer it uses Emacs lisp tools, like [[https://github.com/skeeto/skewer-mode][skewer-modee]] or [[https://github.com/skeeto/impatient-mode][impatient-mode]], to +serve website previews. + +In some happy bright future this package might become the engine for the wiki +part of the [[https://gitlab.com/dalanicolai/easy-thtml][easy-thtml]] package. The easy-thtml enables the possibility to make +full use of a css-framework (check out the [[https://github.com/juanjosegarciaripoll/org-thtml/blob/master/personal-site/index.org][index.org]] in its =personal-site= +directory). An example is provided by the [[https://gitlab.com/flonic/org-blog/-/blob/master/ox-bulma.el][ox-bulma]] exporter of which a very +early site preview can be found [[https://flonic.gitlab.io/org-blog/blog/emacs-transient-tutorial/index.html][here]]. + +** Motivation + Org-mode is an amazing personal management and note taking system. However, + its flexibility makes it a little overwhelming to decide on a good way to + structure the system. + +After researching different options, like [[https://www.orgroam.com/][org-roam]], [[org-brain]] etc., I concluded +that actually I would prefer a simple and straightforward design like that of +the [[https://zim-wiki.org/][zim]] desktop wiki software. Org actually provides a very similar design when +using single org files as equivalent to [[https://zim-wiki.org/manual/Help/Notebooks.html][zim notebooks]]. However using a single +org file per notebook has some drawbacks: + +*** Slow +Unfortunately org quickly becomes really slow (I have a single note file with +only 72 main headings and 413 total headings and it already takes more than 10 +seconds to just open it). This is one reason to break up the single file in +multiple files. + +*** Publishing with org-publish +I would love to share many of my notes and articles. However, to publish the +single note file with a nice website structure, it is again a good strategy to +break up the single note file in multiple files. In this way it can be made +compatible with [[https://orgmode.org/worg/org-tutorials/org-publish-html-tutorial.html][org-publish]] and [[https://juanjose.garciaripoll.com/blog/org-mode-html-templates/index.html][org-thtml]] (which makes it possible to create org +exporters for css-frameworks, like in my experiment [[https://gitlab.com/flonic/org-blog][here]] where I extended +[[https://juanjose.garciaripoll.com/blog/org-mode-html-templates/index.html][ox-thtml]] into the [[https://gitlab.com/flonic/org-blog/-/blob/master/ox-bulma.el][ox-bulma]] exporter, an (unfinished) example page can be found +[[https://flonic.gitlab.io/org-blog/blog/emacs-transient-tutorial/index.html][here]]. I guess in the end the =org-wiki= could replace the [[https://gitlab.com/dalanicolai/easy-thtml][easy-thtml]] package +(which is a very basic start to "port" the [[https://github.com/masasam/emacs-easy-hugo][easy-hugo]] package to =org-thtmtl=). + +*** Contribute/collaborate + Of course to fulfill all the goals is a lot of work, so I would be very + happy with any kind of contributors/collaborators. I am planning to keep a + TODO list in the [[https://github.com/dalanicolai/org-wiki/wiki][wiki section]] of this repo. + + +** Changelog (changes/additions w.r.t. original org-wiki) + - automatically create/sync index from existing wiki pages files (to leave the + structure of the index intact, the "index updater" which produces a + structure as found in the file system, will be replaced by an "index + checker" which uses =cl-set-difference= to find differences with files on + disk, but leaves the index structure intact) + - add deletion command + - add find page command using completion-read (compatible with most completion + frameworks like ivy, selectrum etc.) + * Org-wiki ** Overview diff --git a/org-wiki.el b/org-wiki.el index f0c8615..aa1708b 100644 --- a/org-wiki.el +++ b/org-wiki.el @@ -56,30 +56,28 @@ (defgroup org-wiki nil "Org-wiki Settings" - :group 'tools - ) + :group 'tools) (defcustom org-wiki-location-list '("~/org/wiki") - "List of org-wiki root directories" + "List of org-wiki root directories." :type '(repeat directory) - :group 'org-wiki - ) + :group 'org-wiki) (defvar org-wiki-location nil) (defcustom org-wiki-default-read-only nil - "If this variable is true all org-wiki pages will open as read-only by default. -You can toggle read-only mode with M-x read-only-mode or C-x C-q." + "Open all org-wiki pages as read-only by default. +If true all org-wiki pages will open as read-only by default. +You can toggle read-only mode with \\[read-only-mode]." :type 'boolean - :group 'org-wiki - ) + :group 'org-wiki) (defcustom org-wiki-close-root-switch t - "If this variable is true, all org-wiki pages are closed when root directory is switched. - (Default value: true)" + "Close all org-wiki pages when root directory is switched. +If true, all org-wiki pages are closed when root directory is switched. +\(Default value: true)" :type 'boolean - :group 'org-wiki - ) + :group 'org-wiki) @@ -88,22 +86,19 @@ You can toggle read-only mode with M-x read-only-mode or C-x C-q." (defcustom org-wiki-server-port "8000" "Default port to server org-wiki static files server." :type 'string - :group 'org-wiki - ) + :group 'org-wiki) (defcustom org-wiki-server-host "0.0.0.0" "Default address that the server listens to." :type 'string - :group 'org-wiki - ) + :group 'org-wiki) ;; ======== Async export settings ================ ;; (defcustom org-wiki-emacs-path "emacs" - "Path to Emacs executable. Default value 'emacs'." + "Path to Emacs executable. Default value 'Emacs'." :type 'file - :group 'org-wiki - ) + :group 'org-wiki) ;;; Path to init file like init.el used by function org-wiki-html-export ;; The user can set for a more lightweight file in order to speed up the @@ -112,23 +107,20 @@ You can toggle read-only mode with M-x read-only-mode or C-x C-q." (defcustom org-wiki-user-init-file (concat (file-name-as-directory user-emacs-directory) "init.el") "Path to init.el file used for asynchronous export." :type 'file - :group 'org-wiki - ) + :group 'org-wiki) ;; ====== Optional Clip.jar image pasting app =========== ;; (defcustom org-wiki-backup-location nil "Path to backup directory." :type 'directory - :group 'org-wiki - ) + :group 'org-wiki) ;; Optional Clip.jar image pasting app (defcustom org-wiki-clip-jar-path "~/bin/Clip.jar" "Path to Clip.jar utility to paste images from clipboard." :type 'file - :group 'org-wiki - ) + :group 'org-wiki) @@ -152,15 +144,13 @@ You can toggle read-only mode with M-x read-only-mode or C-x C-q." "\n\n" "- [[wiki:index][Index]]\n\n" "- Related: \n\n" - "* %n\n" - ) + "* %n\n") "Default template used to create org-wiki pages/files. - %n - is replaced by the page name. - %d - is replaced by current date in the format year-month-day." :type 'string - :group 'org-wiki - ) + :group 'org-wiki) ;; ********************** I N T E R N A L - F U N C T I O N S ************************* ;; ;; @@ -179,18 +169,16 @@ You can toggle read-only mode with M-x read-only-mode or C-x C-q." (defun org-wiki--get-buffers () "Return all org-wiki page buffers (.org) files in `org-wiki-location`." - (org-wiki--start-location) + (org-wiki--start-location) (cl-remove-if-not (lambda (p) (let* ((fp (buffer-file-name p)) - (fpath (if fp (expand-file-name fp) nil)) - ) + (fpath (if fp (expand-file-name fp) nil))) ;; path test if file exists (if fpath not nil) (and fpath - ;; test if buffer file is in wiki location + ;; test if buffer file is in wiki location (string-prefix-p (expand-file-name org-wiki-location) fpath) - ;; test if buffer file has extension .org - (string-suffix-p ".org" fpath) - ))) + ;; test if buffer file has extension .org + (string-suffix-p ".org" fpath)))) (buffer-list))) (defun org-wiki--normalize-path (path) @@ -215,12 +203,11 @@ ELISP> (file->org-wiki--page \"Spanish.org\") (defun org-wiki--replace-extension (filename extension) "Replace a FILENAME extension by an new EXTENSION. Example: -ELISP> (org-wiki/replace-extension \"file.org\" \"html\" ) +ELISP> (org-wiki/replace-extension \"file.org\" \"html\") \"file.html\"" (concat (car (split-string filename "\\.")) "." - extension - )) + extension)) (defun org-wiki--page->file (pagename) @@ -231,22 +218,23 @@ ELISP> (org-wiki--page->file \"Linux\") \"~/org/wiki/Linux.org\"" (concat (file-name-as-directory org-wiki-location) + (when (string= pagename "index") + "wiki-") pagename - ".org" - )) + ".org")) (defun org-wiki--current-page () "Get current org-wiki page's name bound to current buffer." (org-wiki--file->page (buffer-file-name))) (defun org-wiki--current-page-asset-dir () - "Get current org-wiki page's asset directory" + "Get current org-wiki page's asset directory." (interactive) (concat (file-name-as-directory org-wiki-location) (file-name-base (buffer-file-name)))) (defun org-wiki--current-page-asset-file (filename) - "Get current page's asset file path given its name. + "Get current page's asset FILENAME given its name. Example: If the current page is 'Smalltalk programming' ELISP> (org-wiki--current-page-asset-file \"manual.pdf\") @@ -256,7 +244,7 @@ ELISP>" filename)) (defun org-wiki--buffer-file-in-wiki-p () - "Return true if current buffer file name is inside wiki directory." + "Return t if current buffer file name is inside wiki directory." (file-exists-p (org-wiki--concat-path org-wiki-location @@ -271,8 +259,7 @@ ELISP>" "Convert a wiki PAGENAME to html file name." (concat (file-name-as-directory (expand-file-name org-wiki-location)) pagename - ".html" - )) + ".html")) (defun org-wiki--page-files (&optional abspath) "Return a list containing all files in the wiki directory. @@ -291,10 +278,12 @@ ELISP> (remove-if-not #'file->org-wiki/page (org-wiki/page-files)) (let ((b (file-name-base s))) (not (or (string-prefix-p ".#" b) - (string-suffix-p "~" b ) + (string-suffix-p "~" b) (string-prefix-p "#" b) (string-suffix-p "#" b) - )))) + ;; remove syncthing conflicts + (string-match-p org-wiki-index-file-basename b) + (string-match-p "sync-conflict" b))))) (directory-files org-wiki-location abspath "\\.org$"))) @@ -340,7 +329,7 @@ if it doesn't exist yet." (defun org-wiki--is-buffer-in (b) - "Check if buffer is an org-wiki buffer. + "Check if B is an org-wiki buffer. It returns true (non nil) if buffer directory is a subdirectory of org-wiki-location." (string-prefix-p @@ -352,8 +341,51 @@ org-wiki-location." ;; ;; @SECTION: Protocol +(defun org-wiki-goto-first-item () + (interactive) + (goto-char (point-min)) + (org-next-visible-heading 1) + (org-wiki-next-item)) + +(defun org-wiki--check-index () + (interactive) + (goto-char (point-min)) + (org-next-visible-heading 1) + (let (index-files) + (while (not (eobp)) + (forward-line) + (org-next-link) + (push + (expand-file-name + (org-wiki--page->file + (org-element-property :path (org-element-context)))) + index-files)) + (message "In index exclusively: %s\nOn disk exclusively: %s" + (mapconcat 'identity (cl-nset-difference + (print index-files) + (print (org-wiki--page-files t)) + :test #'equal) + ", ") + (mapconcat 'identity (cl-nset-difference + (org-wiki--page-files t) + index-files + :test #'equal) + ", ")))) + +(defun org-wiki--insert-index () + (goto-char (point-min)) + (org-next-visible-heading 1) + (forward-line) + (delete-region (point) (point-max)) + (dolist (x (org-wiki--page-files)) + (insert "- ") + (insert (org-make-link-string (concat "wiki:" (string-remove-suffix ".org" x)) + (string-remove-suffix ".org" x))) + (newline)) + (outline-previous-heading)) + (defun org-wiki--org-link (path desc backend) - "Creates an html org-wiki pages when exporting to html. + "Format an org-mode html-link for html export. Example: The hyperlink [[wiki:Linux][Dealing with Linux]] will be exported to Dealing with Linux" (cl-case backend @@ -367,12 +399,59 @@ will be exported to Dealing with Linux" Example: if PAGENAME is Linux it will return [[wiki:Linux][Linux]]" (format "[[wiki:%s][%s]]" pagename pagename)) +(defun org-wiki--contains-link (link-path file) + "Scans FILE for link to LINK-PATH. +Returns FILE-path when positive." + (with-temp-buffer + (insert-file-contents file) + (when (member link-path + (org-element-map + (org-element-parse-buffer) + 'link + (lambda (x) (org-element-property :path x)))) + file))) + +(defun org-wiki-backlink-files (link-path) + "Return list with files that contain link to LINK_PATH." + (interactive + (list (org-element-property :path (org-element-context)))) + "Use mapcan to remove `nil's" + (let ((backlink-files + (mapcan (lambda (file) + (when-let (x (org-wiki--contains-link + link-path + (concat (file-name-as-directory org-wiki-location) + file))) + (list x))) + (org-wiki--page-files)))) + (if (called-interactively-p) + (print backlink-files) + backlink-files))) + +(defun org-wiki-delete (pagename) + (interactive + (list (org-element-property :path (org-element-context)))) + (let ((file (org-wiki--page->file pagename)) + (assets-dir (org-wiki--assets-get-dir pagename))) + (let ((backlink-files (org-wiki-backlink-files pagename))) + (when + (y-or-n-p (concat (if (> (length backlink-files) 2) + "More than two files contain links to this file, " + (format "The file(s) %s link(s) to this file, " + (mapconcat 'identity backlink-files ", "))) + "continue deleting entry?")) + (delete-file file t) + (delete-directory assets-dir t t) + (let ((buffer-read-only)) + (kill-whole-line)))))) + (defun org-wiki--open-page (pagename) "Open or create new a org-wiki page (PAGENAME) by name. Example: (org-wiki--open-page \"Linux\") Will open the the wiki file Linux.org in `org-wiki-location`" - (let ((org-wiki-file (org-wiki--page->file pagename))) + (let* ((org-wiki-file (org-wiki--page->file pagename)) + (index (string= pagename org-wiki-index-file-basename))) (if (not (file-exists-p org-wiki-file)) ;; Action executed if file doesn't exist. (progn (find-file org-wiki-file) @@ -381,16 +460,28 @@ Will open the the wiki file Linux.org in ;; Save current page buffer (save-buffer) ;; Create assets directory - (org-wiki--assets-make-dir pagename)) + (org-wiki--assets-make-dir pagename) + (when index + (org-wiki--insert-index))) ;; Action executed if file exists. - (if org-wiki-default-read-only - ;; open file in read-only mode. - (progn (find-file org-wiki-file) - (read-only-mode 1)) - ;; open file in writable mode. - (find-file org-wiki-file)) - ))) + ;; (if org-wiki-default-read-only + ;; open file in read-only mode. + (let ((buffer-exists-p (get-buffer + (file-name-nondirectory org-wiki-file)))) + (if index + (find-file org-wiki-file) + (find-file-other-window org-wiki-file)) + (unless buffer-exists-p + (when index + (when (y-or-n-p "Update index?") + (org-wiki--insert-index))) + (read-only-mode 1)))))) + ;; open file in writable mode. + ;; (find-file org-wiki-file) + ;; (when index + ;; (when (y-or-n-p "Update index?") + ;; (org-wiki--insert-index)))))))) (defun org-wiki--assets-get-file (pagename filename) @@ -443,9 +534,8 @@ Running in Mac OSX invokes open" "proc" nil ;; Command - "cmd" "/C" "start" "" (expand-file-name filename)) - - ))) ;; End of org-wiki/xdg-open + "cmd" "/C" "start" "" (expand-file-name filename))))) +;; End of org-wiki/xdg-open (defun org-wiki--protocol-open-assets-with-sys (link) @@ -455,21 +545,19 @@ points to the file /Blueprint/box1.dwg." (let* ((a (split-string link ";")) (pagename (car a)) - (filename (cadr a)) - ) + (filename (cadr a))) (org-wiki-xdg-open (org-wiki--assets-get-file pagename filename)))) -;; @DONE: Implement html exporting to org-wiki asset files +;; @DONE: Implement html exporting of org-wiki asset files ;; (defun org-wiki--asset-link (path desc backend) - "Creates an html org-wiki pages html exporting." - (let* ((a (split-string path ";")) + "Format org-wiki asset links for html export." + (let* ((a (split-string path";")) (page (car a)) (asset (cadr a)) - (file-path (concat page "/" asset)) - ) + (file-path (concat page "/" asset))) (cl-case backend (html (format "%s" @@ -484,22 +572,21 @@ points to the file /Blueprint/box1.dwg." ;; wiki: or [[wiki:][]] (org-add-link-type "wiki" #'org-wiki--open-page - #'org-wiki--org-link ) + #'org-wiki--org-link) ;; Hyperlinks to asset files that are opened with system ;; applications such as spreadsheets. ;; ;; wiki-asset-sys:< - (org-add-link-type "wiki-asset-sys" - #'org-wiki--protocol-open-assets-with-sys - #'org-wiki--asset-link))) + (org-link-set-parameters "wiki-asset-sys" + :follow #'org-wiki--protocol-open-assets-with-sys + :export #'org-wiki--asset-link))) (defun org-wiki--helm-selection (callback) "Open a helm menu to select the wiki page and invokes the CALLBACK function." (helm :sources `(( (name . "Wiki Pages") (candidates . ,(delete-dups (org-wiki--page-list))) - (action . ,callback) - )))) + (action . ,callback))))) (defun org-wiki--asset-page-files (pagename) @@ -522,25 +609,22 @@ file name at current point. > (org-wiki--asset-helm-selection (lambda (file) (insert file))) freebsdref1.pdf" - (helm :sources `(( - (name . "Wiki Pages") - (candidates . ,(org-wiki--asset-page-files - (org-wiki--current-page))) - (action . (lambda (file) - (,callback (org-wiki--current-page-asset-file file)) - )) - )))) + (helm :sources `(((name . "Wiki Pages") + (candidates . ,(org-wiki--asset-page-files + (org-wiki--current-page))) + (action . (lambda (file) + (,callback (org-wiki--current-page-asset-file file)))))))) (defun org-wiki--asset-download-hof (callback) "Higher order function to download a file. Callback is a function with this signature: - (callback ) + (CALLBACK ) How this function works: 1. Ask the user for the URL suggesting the URL extracted from the clipboard. -2. Ask the user for the file name to be downloaded suggesting the filename extracted from -the URL. +2. Ask the user for the file name to be downloaded suggesting the filename +extracted from the URL. 3. Calls the callback function passing the current page name and the file name. If the URL is: http://www.myurl.com/Manual1.pdf, the current page is Unix and @@ -579,7 +663,7 @@ point: 'Unix/Manual.pdf'." (command-apropos "org-wiki-")) (defun org-wiki-switch-root () - "Switch org-wiki root directory" + "Switch org-wiki root directory." (interactive) (helm :sources `((name . "Org-wiki root dir") @@ -595,8 +679,7 @@ point: 'Unix/Manual.pdf'." ;; Go to index page (org-wiki-index) ;; Inform user about new directory - (message (format "Org-wiki root dir set to: %s" p)) - ))))) + (message (format "Org-wiki root dir set to: %s" p))))))) (defun org-wiki-index () "Open the index page: /index.org. @@ -648,8 +731,7 @@ Example: [[wiki-asset-sys:Linux;LinuxManual.pdf]]" (insert (format "[[wiki-asset-sys:%s;%s][%s]]" (file-name-base (org-wiki--current-page-asset-dir)) (file-name-nondirectory file) - (read-string "Description: " (file-name-nondirectory file)) - ))))) + (read-string "Description: " (file-name-nondirectory file))))))) (defun org-wiki-asset-insert-file () "Insert link file:/ to asset file of current page at point. @@ -662,8 +744,7 @@ Emacs like source codes. It will insert a link like this (save-excursion (insert (org-make-link-string (concat "file:" file) - (file-name-nondirectory file) - )))))) + (file-name-nondirectory file))))))) (defun org-wiki-asset-insert-image () @@ -676,8 +757,7 @@ in this way: [[file:Linux/logo.png][file:Linux/logo.png/]]." (save-excursion (insert (org-make-link-string (concat "file:" file) - (concat "file:" file) - )))))) + (concat "file:" file))))))) @@ -697,8 +777,7 @@ in this way: [[file:Linux/logo.png][file:Linux/logo.png/]]." (with-temp-buffer (insert-file-contents file) (buffer-substring-no-properties (point-min) (point-max))))) - (insert "\n#+END_SRC") - )))) + (insert "\n#+END_SRC"))))) (defun org-wiki-asset-find-file () @@ -713,7 +792,7 @@ file 'extendingClasses-number1.gst' it will open the file below with Emacs. (org-wiki--asset-helm-selection #'find-file)) (defun org-wiki-asset-find-sys () - "Open a menu to select an asset file of current page and open it with system's app. + "Open menu to select asset file of current page and open it with system's app. Example: If the current page is 'Smalltalk programming' and the user select the file 'numerical-methods-in-smalltalk.pdf' it will be opened with the default system's application like Foxit PDF or @@ -722,9 +801,10 @@ Okular reader." (org-wiki--asset-helm-selection #'org-wiki-xdg-open)) (defun org-wiki-asset-create () - "Prompts the user for a file name that doesn't exist yet and insert it at point. -Unlike the commands `org-wiki-asset-insert` or ` org-wiki-asset-insert-file` this command -asks the user for a file that doesn't exist yet and inserts a hyperlink to it at point. + "Prompt the user for a filename that doesn't exist yet and insert it at point. +Unlike the commands `org-wiki-asset-insert` or `org-wiki-asset-insert-file` this +command asks the user for a file that doesn't exist yet and inserts a hyperlink +to it at point. It is useful to add links to scripts that will be stored in the page directory. @@ -741,8 +821,7 @@ this file:Linux/scriptDemoQT.py . (insert (org-make-link-string (concat "file:" (org-wiki--current-page-asset-file filename)) - filename - ))))) + filename))))) (defun org-wiki-asset-download-insert1 () @@ -762,7 +841,16 @@ to cancel the download." (interactive) (org-wiki--asset-download-hof (lambda (pagename output-file) - (save-excursion (insert (format "file:%s/%s" pagename output-file )))))) + (save-excursion (insert (format "file:%s/%s" pagename output-file)))))) + +;;;###autoload +(defun org-wiki-find-page () + "Browser the wiki files using helm." + (interactive) + (pop-to-buffer (find-file-noselect + (org-wiki--page->file + (completing-read "Open wiki page" + (delete-dups (org-wiki--page-list))))))) (defun org-wiki-helm () "Browser the wiki files using helm." @@ -775,8 +863,7 @@ to cancel the download." (interactive) (org-wiki--helm-selection (lambda (pagename) (find-file-read-only - (org-wiki--page->file pagename) - )))) + (org-wiki--page->file pagename))))) (defun org-wiki-helm-frame () "Browser the wiki files using helm and opens it in a new frame." @@ -784,8 +871,7 @@ to cancel the download." (org-wiki--helm-selection (lambda (act) (with-selected-frame (make-frame) (set-frame-name (concat "Org-wiki: " act)) - (org-wiki--open-page act) - )))) + (org-wiki--open-page act))))) (defun org-wiki-switch () @@ -795,11 +881,9 @@ to cancel the download." (name . "Wiki Pages") (candidates . ,(mapcar (lambda (b) (cons (org-wiki--file->page (buffer-file-name b)) - b - )) + b)) (org-wiki--get-buffers))) - (action . switch-to-buffer) - )))) + (action . switch-to-buffer))))) ;; @TODO: Implement org-wiki/helm-html ;; @@ -811,8 +895,7 @@ to cancel the download." (candidates . ,(delete-dups (org-wiki--page-list))) - (action . org-wiki--open-page) - )))) + (action . org-wiki--open-page))))) (defun org-wiki-close () "Close all opened wiki pages buffer and save them." @@ -837,7 +920,7 @@ to cancel the download." (with-current-buffer b (when (and (org-wiki--is-buffer-in b) (equal major-mode 'image-mode)) - (kill-this-buffer)))) + (kill-this-buffer)))) (buffer-list)) (message "All wiki images closed. Ok.")) @@ -847,13 +930,21 @@ to cancel the download." (org-wiki--helm-selection (lambda (page) (insert (org-wiki--make-link page))))) -(defun org-wiki-insert-new () +(defun org-wiki-insert-new (arg) "Create a new org-wiki and insert a link to it at point." - (interactive) - (let ((page-name (read-string "Page: "))) - (save-excursion (insert (org-make-link-string (concat "wiki:" page-name) - page-name - ))))) + (interactive "P") + (let ((page-name (read-string "Page: ")) + (buffer-read-only nil)) + (save-excursion + (if arg + (goto-char (point-max)) + (beginning-of-line)) + (insert "- ") + (insert (org-make-link-string (concat "wiki:" page-name) + page-name)) + (newline)) + (org-next-link) + (org-open-at-point))) (defun org-wiki-new () "Create a new wiki page and open it without inserting a link." @@ -875,7 +966,7 @@ to cancel the download." (browse-url (org-wiki--replace-extension (buffer-file-name) "html"))) (defun org-wiki-search () - "Search all wiki pages that contains a pattern (regexp or name)." + "Search all wiki pages that contain a pattern (regexp or name)." (interactive) (rgrep (read-string "org-wiki - Search for: ") "*.org" @@ -917,19 +1008,18 @@ to cancel the download." (defun org-wiki-export-with (org-exporter) "Export all pages to a given format. See full doc. ORG-EXPORTER is a function that exports an org-mode page to a specific format like html. -It can be for instance: +It can be for instance: -- org-html-publish-to-thml +- org-html-publish-to-thml - org-latex-publish-to-pdf - org-latex-publish-to-latex -WARN: This is a synchronous function and can freeze Emacs. Emacs will freeze while +WARN: This is a synchronous function and can freeze Emacs. Emacs will freeze while the exporting doesn't finish. Type C-g to abort the execution." (interactive) (let ((org-html-htmlize-output-type 'css) (org-html-htmlize-font-prefix "org-") - (pub-plist (org-wiki-make-org-publish-plist org-exporter)) - ) + (pub-plist (org-wiki-make-org-publish-plist org-exporter))) (org-publish pub-plist t))) @@ -938,8 +1028,7 @@ the exporting doesn't finish. Type C-g to abort the execution." (interactive) (let ((org-html-htmlize-output-type 'css) (org-html-htmlize-font-prefix "org-") - (pub-plist (org-wiki-make-org-publish-plist 'org-html-publish-to-html)) - ) + (pub-plist (org-wiki-make-org-publish-plist 'org-html-publish-to-html))) (org-publish pub-plist t))) (defun org-wiki-export-html () @@ -951,10 +1040,8 @@ Note: This function doesn't freeze Emacs since it starts another Emacs process." "--batch" "-l" ,org-wiki-user-init-file "-f" "org-wiki-export-html-sync" - "--kill" - ) - " " - ))) + "--kill") + " "))) (defun org-wiki-make-menu () "Optional command to build an utility menu." @@ -980,8 +1067,7 @@ Note: This function doesn't freeze Emacs since it starts another Emacs process." ["Html export" nil] ["Open index page (html) in the browser \nM-x org-wiki-index-html" (org-wiki-index-html)] ["Export all pages to html \nM-x org-wiki-export-html" (org-wiki-export-html)] - ["Help - Show all org-wiki commands \nM-x org-wiki-help" (org-wiki-help)] - ) + ["Help - Show all org-wiki commands \nM-x org-wiki-help" (org-wiki-help)]) ["---" nil] ("Page Commands" ["Browse current page asset directory.\nM-x org-wiki-asset-dired" @@ -989,7 +1075,7 @@ Note: This function doesn't freeze Emacs since it starts another Emacs process." ["Browse current page asset directory with system's file manager.\nM-x org-wiki-asset-open" (org-wiki-asset-open)] - ["Insert a link to a wiki page \nM-x org-wiki-insert" (org-wiki-insert)] + ["Insert a link to a wiki page \nM-x org-wiki-insert-link" (org-wiki-insert-link)] ["Insert a link of type wiki-asset-sys at point.\nM-x org-wiki-asset-insert" (org-wiki-asset-insert)] ["Insert a link of type file:/ at point.\nM-x org-wiki-asset-insert-file" @@ -1000,21 +1086,18 @@ Note: This function doesn't freeze Emacs since it starts another Emacs process." ] ["Download an asset file and insert a link at point of type file:/.\nM-x org-wiki-asset-download-insert2" - (org-wiki-asset-download-insert2)] - - ) - ["---" nil] - ("Org-mode" + (org-wiki-asset-download-insert2)]) + ["---" nil] + ("Org-mode" ["Filter headings \nM-x helm-org-in-buffer-headings" (helm-org-in-buffer-headings)] ["Hem occur \nM-x helm-occur" (helm-occur)] ["Toggle Read only \nM-x read-only-mode" (read-only-mode 'toggle)] ["Toggle Images \nM-x org-toggle-inline-images" (org-toggle-inline-images)] - ["Toggle Link display \nM-x org-toggle-link-display" (org-toggle-link-display)] - )))) + ["Toggle Link display \nM-x org-toggle-link-display" (org-toggle-link-display)])))) ;; -;; Despite this function was implemented as a interface to +;; Despite this function was implemented as a interface to ;; Python3 simple http server, it can be refactored to work ;; with another more powerful http server such as Nginx. ;; @@ -1023,7 +1106,7 @@ Note: This function doesn't freeze Emacs since it starts another Emacs process." Note: This command requires Python3 installed." (interactive) (let ( - ;; Process name + ;; Process name (pname "org-wiki-server") ;; Buffer name - Display process output (stdout) (bname "*org-wiki-server*") @@ -1034,7 +1117,7 @@ Note: This command requires Python3 installed." (sit-for 0.1) (switch-to-buffer bname) (save-excursion ;; Save cursor position - (insert "Server started ...\n\n") + (insert "Server started ...\n\n") (message "\nServer started ...\n") ;; Show machine network cards' IP addresses. @@ -1043,10 +1126,10 @@ Note: This command requires Python3 installed." (gnu/linux (insert (shell-command-to-string "ifconfig"))) ;;; Free BSD OS (gnu/kfreebsd (insert (shell-command-to-string "ifconfig"))) - ;; Mac OSX - (Not tested ) + ;; Mac OSX - (Not tested) (darwin (insert (shell-command-to-string "ifconfig"))) ;; Windows 7, 8, 10 - Kernel NT - (windows-nt (insert (shell-command-to-string "ipconfig"))))) + (windows-nt (insert (shell-command-to-string "ipconfig"))))) (start-process pname bname "python3" @@ -1054,21 +1137,20 @@ Note: This command requires Python3 installed." "http.server" "--bind" org-wiki-server-host - org-wiki-server-port) - (when (y-or-n-p "Open server in browser ?") - (browse-url (format "http://localhost:%s" org-wiki-server-port)))) + org-wiki-server-port) + (when (y-or-n-p "Open server in browser ? ") + (browse-url (format "http://localhost:%s" org-wiki-server-port)))) (progn (switch-to-buffer bname) (kill-process (get-process pname)) - (message "Server stopped.") - )))) + (message "Server stopped."))))) -(defun org-wiki-paste-image () +(defun org-wiki-paste-image () "Paste a image asking the user for the file name." (interactive) (let* ((dir (file-name-as-directory (file-name-base (buffer-file-name)))) - (image-name (read-string "Image name: " ))) + (image-name (read-string "Image name: "))) (org-wiki--assets-make-dir dir) (insert "#+CAPTION: ") (save-excursion @@ -1086,10 +1168,8 @@ Note: This command requires Python3 installed." ,(expand-file-name org-wiki-clip-jar-path) "--name" ,(concat "\"" image-name "\"") - ,(concat "\"" dir "\"") - ) - " " - ))))))))) + ,(concat "\"" dir "\"")) + " "))))))))) (defun org-wiki-paste-image-uuid () "Paste a image with automatic generated name (uuid)." @@ -1115,8 +1195,7 @@ Note: This command requires Python3 installed." "--uuid" ,(concat "\"" dir "\"")) - " " - ))))))))) + " "))))))))) ;; Custom Minor Mode @@ -1125,7 +1204,7 @@ Note: This command requires Python3 installed." ;; The initial value - Set to 1 to enable by default nil ;; The indicator for the mode line. - nil + nil ;; The minor mode keymap `( ;; Commands to Open Index page: @@ -1134,14 +1213,14 @@ Note: This command requires Python3 installed." (,(kbd "bbi") . org-wiki-index-html) ;; ==== Commands to browse pages ========== - (,(kbd "hh") . org-wiki-helm ) - (,(kbd "hj") . org-wiki-switch ) + (,(kbd "hh") . org-wiki-helm) + (,(kbd "hj") . org-wiki-switch) (,(kbd "hr") . org-wiki-helm-read-only) (,(kbd "hf") . org-wiki-helm-frame) (,(kbd "kk") . org-wiki-close) ;; ==== Commands to browse directories ===== - (,(kbd "dw") . org-wiki-dired ) + (,(kbd "dw") . org-wiki-dired) (,(kbd "do") . org-wiki-open) ;; ==== Install Menu ======================= @@ -1157,15 +1236,13 @@ Note: This command requires Python3 installed." (,(kbd "tty") . (lambda () (interactive) (tool-bar-mode 'toggle) - (menu-bar-mode 'toggle) - )) + (menu-bar-mode 'toggle))) (,(kbd "ttb") . (lambda () (interactive) (tool-bar-mode 'toggle))) (,(kbd "ttm") . (lambda () (interactive) (menu-bar-mode 'toggle))) - (,(kbd "q") . (lambda () (interactive) (kill-buffer))) - ) - ;; Make mode local to buffer rather than global + (,(kbd "q") . (lambda () (interactive) (kill-buffer)))) + ;; Make mode local to buffer rather than global ;; :global t ) @@ -1192,16 +1269,13 @@ Note: This command requires Python3 installed." (find-dired org-wiki-location (mapconcat #'identity '( - "-not -path '*/.git*'" ;; Exclude .git Directory + "-not -path '*/.git*'" ;; Exclude .git Directory "-and -not -name '.#*'" ;; Exclude temporary files starting with # "-and -not -name '#*'" "-and -not -name '*#'" "-and -not -name '*~' " ;; Exclude ending with ~ (tilde) - "-and -not -name '*.html' " ;; Exclude html files - ) - - " " - ))) + "-and -not -name '*.html' ") ;; Exclude html files + " "))) (defun org-wiki-website () "Open org-wiki github repository." @@ -1224,8 +1298,7 @@ Note: This command requires Python3 installed." (text2 (replace-regexp-in-string "%d" (format-time-string "%Y-%m-%d") - text1 - ))) + text1))) ;; Got to top of file (goto-char (point-min)) (insert text2)))) @@ -1274,10 +1347,30 @@ Toggle [tty] - Toggle Emacs toolbar and menu [ttb] - Toggle Emacs toolbar [ttm] - Toggle Emacs menu bar -" - )) +")) (read-only-mode)) +(defhydra hydra-org-wiki () +;; " +;; ^Navigate^ ^Edit^ ^Actions^ ^Search +;; ^^^^^^^^----------------------------------------------------------------- +;; _m_: mark _d_: delete _x_: execute _R_: re-isearch +;; _s_: save _U_: unmark up _b_: bury _I_: isearch +;; _d_: delete ^ ^ _g_: refresh _O_: multi-occur +;; _D_: delete up ^ ^ _T_: files only: % -28`Buffer-menu-files-only +;; _~_: modified +;; " + ("j" org-next-link "next") + ("k" org-previous-link "previous") + ("d" org-wiki-delete "delete") + ;; ("g" revert-buffer) + ;; ("c" nil "cancel") + ;; ("v" Buffer-menu-select "select" :color blue) + ;; ("o" Buffer-menu-other-window "other-window" :color blue) + ("q" quit-window "quit" :color blue)) + +(define-key Buffer-menu-mode-map "." 'hydra-buffer-menu/body) + ;; =========== Copy Path Commands ============= ;; @@ -1295,7 +1388,7 @@ Toggle "Copy org-wiki html index page to clipboard." (interactive) (let ((msg (expand-file-name (concat (file-name-as-directory org-wiki-location) - "index.html" )))) + "index.html")))) (with-temp-buffer (insert msg) (message (format "Copied to clipboard: %s" msg)) @@ -1346,8 +1439,7 @@ Toggle (switch-to-buffer "*org-wiki-backup*") (rename-file zipfile org-wiki-backup-location t) (message "Backup done. Ok.") - (insert "\nBackup done. Ok. Run M-x org-wiki-backup-dir to open backup directory.") - )))))) + (insert "\nBackup done. Ok. Run M-x org-wiki-backup-dir to open backup directory."))))))) (defun org-wiki-backup-dir () "Open org-wiki backup directory in dired mode." @@ -1364,33 +1456,33 @@ Toggle (defun org-wiki-nav () - "Navigate through org-mode headings. Alias to helm-org-in-buffer-headings." + "Navigate through `org-mode' headings. Alias to `helm-org-in-buffer-headings'." (interactive) (helm-org-in-buffer-headings)) (defun org-wiki-occur () - "Search current buffer with helm-occur. Alias to helm-occur." + "Search current buffer with `helm-occur'. Alias to `helm-occur'." (interactive) (helm-occur)) (defun org-wiki-toggle-images () - "Toggle inline images. Alias to M-x org-toggle-inline-images." + "Toggle inline images. Alias to \\[org-toggle-inline-images]." (interactive) (org-toggle-inline-images)) (defun org-wiki-toggle-link () - "Toggle link display. Alias to M-x org-toggle-link-display" + "Toggle link display. Alias to \\[org-toggle-link-display]." (interactive) (org-toggle-link-display)) (defun org-wiki-latex () - "Display latex formulas. Alias to M-x org-preview-latex-fragment" + "Display latex formulas. Alias to \\[org-preview-latex-fragment]." (interactive) (org-preview-latex-fragment)) (defun org-wiki-insert-latex () - "Insert a latex template at point" + "Insert a latex template at point." (interactive) (helm :sources `((name . "Latex Templates") @@ -1398,8 +1490,7 @@ Toggle (lambda (p) (cons (concat (car p) " = " (cdr p)) (cdr p))) - org-wiki-latex-templates - )) + org-wiki-latex-templates)) (action . insert)))) (defun org-wiki-insert-symbol () @@ -1411,12 +1502,11 @@ Toggle (lambda (p) (cons (concat (car p) " = " (cdr p)) (cdr p))) - org-wiki-symbol-list - )) + org-wiki-symbol-list)) (action . insert)))) (defun org-wiki-insert-block () - "Insert org-mode blocks such as Latex equation, code block, quotes, tables and etc." + "Insert `org-mode' blocks such as Latex equation, code block, quotes, tables and etc." (interactive) (helm :sources `((name . "Org-mode code block") @@ -1427,7 +1517,7 @@ Toggle ;; ========= org-wiki Internal databases =========== ;; ;; Variable containing useful math, physics, currencies and greek letters used by function -;; org-wiki-insert-symbol +;; org-wiki-insert-symbol (defvar org-wiki-symbol-list '( ("alpha" . "α") @@ -1436,7 +1526,7 @@ Toggle ("Gamma" ."Γ") ("delta" . "δ") ("Delta" . "Δ") - ("episilon" ."ε") + ("episilon" ."ε") ("zeta" ."ζ") ("eta" ."η") ("theta" ."θ") @@ -1457,17 +1547,17 @@ Toggle ("Phi" ."Φ") ("psi" ."Ψ") ("omega" ."ω") - ("Omega" ."Ω") + ("Omega" ."Ω") ("Multiplication sign" . "×") ("Multiplication dot (sdot)" . "⋅") ("Division sign" . "÷") - + ;;; Mathematical Symbols for calculus ("Square root sqrt" . "√") ("Cubic root cbrt" . "∛") - ("Fourth root" . "∜") - + ("Fourth root" . "∜") + ("Infinity" . "∞") ("summation" . "Σ") ("product - big PI" . "Π") @@ -1485,7 +1575,7 @@ Toggle ("Laplace transform" . "ℒ") ("Fourier transform" . "ℱ") - ;; Symbols for set algebra + ;; Symbols for set algebra ("Empty set" . "∅") ("Set membership" . "∈") ("Universal quantifier" . "∀") @@ -1497,7 +1587,7 @@ Toggle ("Logic - Logical OR" . "∨") - ("Real numbers" . "ℝ") + ("Real numbers" . "ℝ") ;; Misc Symbols ("Per mile" . "‰") @@ -1548,11 +1638,10 @@ Toggle ("Currency Euro" . "€") ("Currency Yen, Yuan, Reminbi (China)" . "¥") ("Currency Won" . "₩") - ("Currency Russian Ruble" . "₽") + ("Currency Russian Ruble" . "₽") ("Currency Lira" . "₤") ("Currency Bitcoin" . "₿") - ("Currency Indian Rupee" . "₹") - )) + ("Currency Indian Rupee" . "₹"))) (defvar org-wiki-template-blocks '( @@ -1570,10 +1659,9 @@ Toggle ("R code block" . "#+BEGIN_SRC R \n\n#+END_SRC") ("Elisp code block" . "#+BEGIN_SRC elisp \n\n#+END_SRC") ("C++ code block" . "#+BEGIN_SRC cpp \n\n#+END_SRC") - ("Scala code block" . "#+BEGIN_SRC scala \n\n#+END_SRC") - )) + ("Scala code block" . "#+BEGIN_SRC scala \n\n#+END_SRC"))) -;; Latex templates used by user command M-x org-wiki-insert-latex +;; Latex templates used by user command M-x org-wiki-insert-latex (defvar org-wiki-latex-templates '( ("Latex equation block " . "\\begin{equation}\n\n\\end{equation}") @@ -1586,11 +1674,11 @@ Toggle ("Calculus Integral - ∫ from a to b" . "\\int_{a}^{b}") ("Calculus Infinity - ∞" . "\\infty") ("Calculus Gradient, nabla - ∇" . "\\nabla") - ("Calculus Derivate of f df/dx" . "\\frac{df}{dx}" ) - ("Calculus Second Derivate of f d^2f/dx^2" . "\\frac{d^2f}{dx^2}" ) - ("Calculus Derivate operation d/dx p(x)" . "\\frac{d}{dx} p(x)" ) - ("Calculus Second Derivate operation d^2/dx^2 p(x)" . "\\frac{d^2}{dx^2} p(x)" ) - ("Calculus Partial derivate - ∂" . "\\partial") + ("Calculus Derivate of f df/dx" . "\\frac{df}{dx}") + ("Calculus Second Derivate of f d^2f/dx^2" . "\\frac{d^2f}{dx^2}") + ("Calculus Derivate operation d/dx p(x)" . "\\frac{d}{dx} p(x)") + ("Calculus Second Derivate operation d^2/dx^2 p(x)" . "\\frac{d^2}{dx^2} p(x)") + ("Calculus Partial derivate - ∂" . "\\partial") ("Calculus Partial derivate fraction ∂x/∂t" . "\\frac{\\partial x}{\\partial y}") ("Calculus Second Partial derivate fraction ∂2x/∂t2" . "\\frac{\\partial^2 x}{\\partial y^2}") @@ -1601,7 +1689,7 @@ Toggle ("Operator - times x" . "\\times") ("Operator - div %" . "\\div") ("Operator - Approximately ~=" . "\\prox") - ("Operator - Proportional to ∝" . "\\propto") + ("Operator - Proportional to ∝" . "\\propto") ("Escape - $" . "\\textdollar") ("Escape - Underline - _ " . "\\_") @@ -1623,7 +1711,7 @@ Toggle ("Accent - tilde - ã, ĩ - tilde over symbol" . "\\tilde{}") ("Accent - dot (derivate) symbol" . "\\dot{}") ("Accent - double dot (double derivate) symbol" . "\\ddot{}") - ("Accent - arrow over symbol, vector" . "\\vec{}") + ("Accent - arrow over symbol, vector" . "\\vec{}") ;; Set notation ("Sets - N Set of Natural Numbers" . "\\N") @@ -1642,7 +1730,7 @@ Toggle ("Greek α - lower alpha" . "\\alpha") ("Greek β - lower beta" . "\\beta") ("Greek σ - lower sigma" . "\\sigma") - ("Greek Σ - upper sigma" . "\\Sigma") + ("Greek Σ - upper sigma" . "\\Sigma") ("Greek γ - lower gamma" . "\\gamma") ("Greek Γ - upper gamma" . "\\Gamma") ("Greek δ - lower delta" . "\\delta") @@ -1654,21 +1742,20 @@ Toggle ("Greek ζ - zeta" . "\\zeta") ("Greek η - eta" . "\\eta") ("Greek μ - mu" . "\\mu") - ("Greek ρ - rho" . "\\rho") + ("Greek ρ - rho" . "\\rho") ("Greek φ - lower phi" . "\\phi") - ("Greek Φ - upper phi" . "\\Phi") - ("Greek ω - lower omega" . "\\omega") + ("Greek Φ - upper phi" . "\\Phi") + ("Greek ω - lower omega" . "\\omega") ("Greek Ω - upper omega" . "\\Omega") - ("Greek Ψ - psi" . "\\psi") + ("Greek Ψ - psi" . "\\psi") ("Greek τ - tau" . "\\tau") ("Greek ι - lower iota" . "\\iota") ("Greek ξ - lower xi" . "\\xi") - ("Greek Ξ - upper xi" . "\\xi") + ("Greek Ξ - upper xi" . "\\xi") ("Symbol -> Right arrow" . "\\rightarrow") ("Symbol <- Left arrow" . "\\leftarrow") ("Symbol Up arrow" . "\\uparrow") - ("Symbol Down arrow" . "\\downarrow") - )) + ("Symbol Down arrow" . "\\downarrow"))) (provide 'org-wiki)