emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/greader e71863ebf6: greader.el: «greader-continuous-mo


From: ELPA Syncer
Subject: [elpa] externals/greader e71863ebf6: greader.el: «greader-continuous-mode' functionality added.
Date: Sat, 11 Nov 2023 03:57:58 -0500 (EST)

branch: externals/greader
commit e71863ebf6497fef1e7dbeef5b3b9bf75ddeeae2
Author: Michelangelo Rodriguez <michelangelo.rodriguez@gmail.com>
Commit: Michelangelo Rodriguez <michelangelo.rodriguez@gmail.com>

    greader.el: «greader-continuous-mode' functionality added.
    
    This minor-mode is for greader to automatically scroll in
    some special types of buffers, like `info-mode' or external package
    `nov-mode'.
    For further details see the mode documentation.
    
    In this version of the feature there is still a problem:
    When using info-mode, the `greader-continuous-guess-function' function
    correctly deduces the function to call for scrolling,
    however it happens that in some specific pages in the manuals, the
    function `Info-scroll-up' generates an "end-of-buffer" error. The cause
    of this bizarre behavior is still unknown to me.
---
 greader.el | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 91 insertions(+)

diff --git a/greader.el b/greader.el
index 4d2caca67a..3faf3fae02 100644
--- a/greader.el
+++ b/greader.el
@@ -1490,5 +1490,96 @@ the element, configure the `greader-enriched-tag' 
variable."
     (remove-hook 'greader-after-get-sentence-functions
                 #'greader-scrap-links)))
 
+;;greader-continuous-mode
+;; In this mode, greader will try to "guess" the function in the
+;; current major mode that allows you to scroll the page
+;; next one.
+;;To do this, it assumes that, usually, the command to switch to
+;; next page or section in a buffer is associated with the space key.
+;; However, it will be possible to specify via the variable
+;; customizable `greader-continuous-modes' functions associated with
+;; particular major modes.
+(defcustom greader-continuous-modes
+  (if (package-installed-p 'nov)
+      (progn
+       (require 'nov)
+       '((nov-mode . nov-next-document)))
+    ())
+  "Alist mapping major modes to functions for greader-continuous
+guessing."
+  :type '(alist :key-type (symbol :tag "mode-name") 
+                :value-type (function :tag "Scroll function")))
+
+(defcustom greader-continuous-excluded-modes ()
+  "Alist mapping major modes to functions for greader-continuous guessing."
+  :type '(list (symbol :tag "modes")))
+
+(defcustom greader-continuous-key "SPC"
+  "The key or key sequence from which the scroll function is to be derived."
+  :type 'string)
+
+(defun greader-continuous-guess-function ()
+  "Guess the function for greader-continuous mode based on 
GREADER-CONTINUOUS-KEY.
+If GREADER-CONTINUOUS-KEY is nil, checks against 
`greader-continuous-excluded-modes'
+and `greader-continuous-modes' to determine the appropriate function."
+  (cond
+   ((member major-mode greader-continuous-excluded-modes)
+    ;; If the current major mode is excluded, return nil.
+    nil)
+   ((assoc major-mode greader-continuous-modes)
+    ;; If the current major mode is included, return the associated function.
+    (cdr (assoc major-mode greader-continuous-modes)))
+   ;; If a key sequence is provided, get the corresponding command.
+   (greader-continuous-key
+    (let ((command (key-binding (kbd greader-continuous-key))))
+      ;; Return nil if the command is `self-insert-command',
+      ;; otherwise return the command itself.
+      (unless (eq command 'self-insert-command)
+        command)))
+   (t
+    ;; If the major mode is not mentioned in any list, return nil.
+    nil)))
+
+;; The following is the function that will be added to
+;; `greader-before-finish-functions', just in case
+;; `greader-continuous-mode' is enabled.
+(defun greader-continuous-call-function ()
+  "Call the function returned by `greader-continuous-guess-key'.
+If the `greader-continuous-guess-key` function returns nil, then
+this function will return nil, otherwise it returns t. It also handles
+any errors that occur during the execution of the command or
+the reading process, returning nil in such cases."
+  (condition-case nil
+      ;; The condition-case block here is to handle any errors
+      ;; that might occur in any part of the following code.
+      (let ((command (greader-continuous-guess-function)))
+        ;; Check if a valid command is returned.
+        (when command
+          ;; Calls the function returned by greader-continuous-guess-function.
+          (funcall command)
+          (greader-read))
+        t)  ; Returns t if no error occurs.
+    ((debug error) nil)))  ; Returns nil in case of an error.
+
+;; greader-continuous-mode
+;; This minor-mode will take care of adding to the hook
+;; `greader-before-finish-functions' the function
+;; `greader-continuous-call-function'.
+;; If minor-mode is deactivated, the function will be removed
+;; from the hook.
+(define-minor-mode greader-continuous-mode
+  "This minor-mode enables autoscrolling in buffers that support it
+require.
+Examples are `info-mode', `nov-mode', to some extent `man-mode' etc...
+When this minor-mode is active, say in `info-mode', it will be
+called the `info-scroll-up' function instead of finishing reading."
+  :lighter " continuous"
+  (if greader-continuous-mode
+      (add-hook 'greader-before-finish-functions
+               #'greader-continuous-call-function 0 t)
+    (remove-hook 'greader-before-finish-functions
+                #'greader-continuous-call-function t)))
+    
+
 (provide 'greader)
 ;;; greader.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]