[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/org-remark 166d3c8a82 4/6: feat: Modules and org-remark
From: |
ELPA Syncer |
Subject: |
[elpa] externals/org-remark 166d3c8a82 4/6: feat: Modules and org-remark-eww module |
Date: |
Fri, 23 Dec 2022 10:57:56 -0500 (EST) |
branch: externals/org-remark
commit 166d3c8a8255d995c55f57ae650934eadc5172e2
Author: Noboru Ota <me@nobiot.com>
Commit: Noboru Ota <me@nobiot.com>
feat: Modules and org-remark-eww module
---
org-remark-eww.el | 54 +++++++++++++++++++++++++++++
org-remark-global-tracking.el | 80 ++++++++++++++++++++++++++++++++-----------
org-remark.el | 5 +++
3 files changed, 119 insertions(+), 20 deletions(-)
diff --git a/org-remark-eww.el b/org-remark-eww.el
new file mode 100644
index 0000000000..552412d25b
--- /dev/null
+++ b/org-remark-eww.el
@@ -0,0 +1,54 @@
+;;; org-remark-eww.el --- Enable Org-remark for EWW -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2021-2022 Free Software Foundation, Inc.
+
+;; Author: Vedang Manerikar <ved.manerikar@gmail.com>
+;; Noboru Ota <me@nobiot.com>
+;; URL: https://github.com/nobiot/org-remark
+;; Created: 23 December 2022
+;; Last modified: 23 December 2022
+;; Package-Requires: ((emacs "27.1") (org "9.4"))
+;; Keywords: org-mode, annotation, note-taking, marginal-notes, wp
+
+;; This file is not part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+;; This file is part of org-remark.
+
+;; This feature to support for EWW was originally added by Vedang
+;; Manerika with commit 5e4b27ar feat: Support taking annotations in eww
+;; buffers. nobit has refactored it as a separate file.
+
+;;; Code:
+
+(require 'eww)
+;; Silence compiler
+(defvar org-remark-global-tracking-mode)
+
+(defun org-remark-eww-global-tracking-mode ()
+ (if org-remark-global-tracking-mode
+ (add-hook 'eww-after-render-hook #'org-remark-auto-on)
+ (remove-hook 'eww-after-render-hook #'org-remark-auto-on))
+ (add-to-list 'org-remark-source-find-file-name-functions
+ #'org-remark-eww-find-file-name))
+
+(defun org-remark-eww-find-file-name ()
+ (if (eq major-mode 'eww-mode)
+ (let ((url-parsed (url-generic-parse-url (eww-current-url))))
+ (concat (url-host url-parsed) (url-filename url-parsed)))))
+
+(provide 'org-remark-eww)
+;;; org-remark-eww.el ends here
diff --git a/org-remark-global-tracking.el b/org-remark-global-tracking.el
index 129b03a794..68a2426cb6 100644
--- a/org-remark-global-tracking.el
+++ b/org-remark-global-tracking.el
@@ -66,15 +66,60 @@ readable, the function automatically activates
`org-remark'."
:lighter " ormk-auto"
:global t
:group 'org-remark
- (cond
- (org-remark-global-tracking-mode
- ;; Activate
- (progn (add-hook 'find-file-hook #'org-remark-auto-on)
- (add-hook 'eww-after-render-hook #'org-remark-auto-on)))
- (t
- ;; Deactivate
- (remove-hook 'find-file-hook #'org-remark-auto-on))))
+ (if org-remark-global-tracking-mode
+ ;; Enable
+ (add-hook 'find-file-hook #'org-remark-auto-on)
+ ;; Disable
+ (remove-hook 'find-file-hook #'org-remark-auto-on)))
+
+;;; Modules
+;; This needs to be defined after the minor mode as the hook needs to
+;; have been defined.
+
+;; Note the sequence of symbol definition in the modules section is
+;; significant. The hook needs to be defined before the module set
+;; function.
+(defcustom org-remark-source-find-file-name-functions '(buffer-name)
+ "Abnormal hook called to find the source file name.
+Each one is called with argument until a non-nil value is
+returned.
+
+Org-remark runs this hook when the buffer in question does not
+visit a file; this is why the `buffer-file-name' cannot be used
+and a special function is required for each context. Each
+module (`org-remark-modules') is supposed to provide and set an
+appropriate function to this hook.
+
+Assume that the current buffer is the source buffer when the function is
+called, which can be used to find the file name."
+ :group 'org-remark
+ :type
+ '(repeat function))
+
+(defun org-remark-modules-set (symbol value)
+ "Enable the modules set in user option `org-remark-modules'.
+Set SYMBOL and VALUE for `org-remark-modules'."
+ (set symbol value)
+ (dolist (module value)
+ (let ((feat (intern (concat "org-remark-" (symbol-name module))))
+ (fn (intern (concat "org-remark-"
+ (symbol-name module)
+ "-global-tracking-mode"))))
+ (require feat)
+ (when (functionp fn)
+ ;; As minor mode would have been already activated, run the
+ ;; function once and then set the hook
+ (funcall fn)
+ (add-hook 'org-remark-global-tracking-mode-hook fn)))))
+
+(defcustom org-remark-modules (list 'eww)
+ "List of modules enabled for Org-remark."
+ :group 'org-remark
+ :set #'org-remark-modules-set
+ :type
+ '(set (const :tag "Org-remark in EWW" eww)))
+;;; Functions
(defun org-remark-notes-file-name-function ()
"Return a marginal notes file name for the current buffer.
@@ -94,10 +139,12 @@ suffix to the file name without the extension."
(expand-file-name "marginalia.org" user-emacs-directory)))
(defalias
- 'org-remark-notes-file-path-function 'org-remark-notes-file-name-function)
+ 'org-remark-notes-file-path-function
+ 'org-remark-notes-file-name-function)
(make-obsolete
- 'org-remark-notes-file-path-function 'org-remark-notes-file-name-function
"0.2.0" )
+ 'org-remark-notes-file-path-function
+ 'org-remark-notes-file-name-function "0.2.0" )
;;;; Private Functions
@@ -125,16 +172,9 @@ This function is meant to be added to `find-file-hook' by
Returns the filename for the source buffer. We use this filename
to identify the source buffer in all operations related to
marginal notes."
- (let ((filename buffer-file-name))
- (unless filename
- (if (eq major-mode 'eww-mode)
- (let ((url-parsed (url-generic-parse-url (eww-current-url))))
- (setq filename
- (concat (url-host url-parsed) (url-filename url-parsed))))
- ;; TODO Abstract this and move the EWW specific one
- ;; If not, return the buffer's name as is
- ;; EWW, Info, etc. may need their respective handler.
- (setq filename (buffer-name))))
+ (let ((filename (or buffer-file-name
+ (run-hook-with-args-until-success
+ 'org-remark-source-find-file-name-functions))))
filename))
(provide 'org-remark-global-tracking)
diff --git a/org-remark.el b/org-remark.el
index 43307b77c0..66b73b0fa1 100644
--- a/org-remark.el
+++ b/org-remark.el
@@ -1080,6 +1080,11 @@ Case 1. Both start and end of an overlay are identical
region. A typical cause of this case is when you delete a
region that contains a highlight overlay.
+ This also happens when EWW reloads the buffer or
+ re-renders any part of the buffer. This is because it
+ removes overlays on re-render by calling
+ `remove-overlays'.
+
Case 2. The overlay points to no buffer
This case happens when overlay is deleted by
- [elpa] externals/org-remark updated (618d603939 -> 31b4971b97), ELPA Syncer, 2022/12/23
- [elpa] externals/org-remark 166d3c8a82 4/6: feat: Modules and org-remark-eww module,
ELPA Syncer <=
- [elpa] externals/org-remark aadd65def5 5/6: fix: Slience compilation warning, ELPA Syncer, 2022/12/23
- [elpa] externals/org-remark b46deaee0d 2/6: docs: replace TODO comment in source, ELPA Syncer, 2022/12/23
- [elpa] externals/org-remark 20d33d995d 1/6: feat: extend support for non-file-visiting buffer, ELPA Syncer, 2022/12/23
- [elpa] externals/org-remark 48907778f4 3/6: fix :org-remark-link: prop for EWW, ELPA Syncer, 2022/12/23
- [elpa] externals/org-remark 31b4971b97 6/6: feat(module): create link to source other than file:, ELPA Syncer, 2022/12/23