Skip to content
Snippets Groups Projects
Commit 5f60fb16 authored by Daniele Nicolodi's avatar Daniele Nicolodi
Browse files

ol-hclnotes: Import

parents
Branches master
No related tags found
No related merge requests found
#+TITLE: Emacs org-mode support for links to HCL Notes documents
This small package provides functionality to store and follow org-mode links to HCL Notes documents. It adds a new =hclnotes= link type and provides the =org-hclnotes-insert-link= function to synthesize an org-mode link from an HCL Notes "Document Link" in the clipboard, obtained selecting "Copy as Document Link" from the right-click menu in the HCL Notes application.
;;; ol-hclnotes.el - Support for links to HCL Notes documents in Org mode -*- lexical-binding: t -*-
(require 'org)
(org-link-set-parameters "hclnotes" :follow #'org-hclnotes-open)
(defun org-hclnotes-open (path _)
;; Do not display "Wrote ..." messages in the minibuffer.
(let ((inhibit-message t))
;; Create a temporary file with the link data.
(let ((ndl-file (make-temp-file "org-link-" nil ".ndl" path)))
(make-process
:name "hcl-notes"
:command (list "rundll32" "url.dll,FileProtocolHandler" ndl-file)))))
(defun org-hclnotes-insert-link (arg)
(interactive "P" arg)
(let (link description)
(with-temp-buffer
(yank)
(beginning-of-buffer)
(search-forward " - " nil t)
(setq description (buffer-substring-no-properties (point) (point-at-eol)))
(forward-line 1)
(if (not (looking-at "<NDL>\\(.\\|\n\\)+</NDL>"))
(message "Not an HCL Notes document link")
(let ((start (point)))
;; Strip newlines.
(while (re-search-forward "[\n\r]" nil t)
(replace-match ""))
(goto-char start)
;; Remove unnecessary HINT tag.
(when (re-search-forward "<HINT>.+</HINT>")
(replace-match ""))
;; Remove unnecessary REM tag.
(when (re-search-forward "<REM>.+</REM>")
(replace-match ""))
(setq link (buffer-substring-no-properties start (point-max)))
(message link))))
(when link
(let ((description (if arg description (read-string "Description: " description))))
(insert (format "[[hclnotes:%s][%s]]" link description))))))
(provide 'ol-hclnotes)
;;; ol-hclnotes.el end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment