From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: stardiviner Newsgroups: gmane.emacs.help Subject: Need help on writing an Emacs extension to help reading text content with timer Date: Wed, 29 Jan 2020 23:19:41 +0800 Message-ID: <87v9ou5lyq.fsf@gmail.com> Reply-To: numbchild@gmail.com Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="108848"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.3.2; emacs 27.0.50 To: Emacs Help Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jan 29 16:26:07 2020 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iwpEE-000SH2-OE for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 29 Jan 2020 16:26:06 +0100 Original-Received: from localhost ([::1]:47976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iwpED-0000Xt-Pq for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 29 Jan 2020 10:26:05 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45664) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iwpDo-0000Sd-Pc for help-gnu-emacs@gnu.org; Wed, 29 Jan 2020 10:25:44 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iwpDn-0002XY-IG for help-gnu-emacs@gnu.org; Wed, 29 Jan 2020 10:25:40 -0500 Original-Received: from [183.246.143.250] (port=9058 helo=dark.localdomain) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1iwpDm-0002QN-5p for help-gnu-emacs@gnu.org; Wed, 29 Jan 2020 10:25:39 -0500 Original-Received: by dark.localdomain (Postfix, from userid 1000) id 6D232200D4D; Wed, 29 Jan 2020 23:19:41 +0800 (CST) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 183.246.143.250 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:122309 Archived-At: When I read a long paragraph, move around text, leave for a while, then get= back to read it will lost the position. So I want to combine package =3DSpritz (= speed read)=3D and =3Dbeacon=3D. Make the cursor move animation like =3Dbeacon=3D= , and switch buffer into read-only state, and move around the cursor. Or use =3Doverlay=3D for = simplity. Make the cursor big and obvious like =3Dbeacon=3D. The inner core logic is = like Spritz speed read. After reading spray.el source code, I use following code loginc: - ~spray-start~ - ~(run-with-timer 0 (/ 60.0 spray-wpm) 'spray--update)~ - ~spray--word-at-point~ - ~make-overlay~ + ~overlay-put~ And here is my source code: #+begin_src emacs-lisp (defcustom amread-wps 2 "Read words per second." :type 'number :safe #'numberp :group 'amread) (defvar amread--running nil) (defvar amread--overlay nil) (defun amread--update () "Moving amread cursor forward." (let* ((begin (point)) (length (+ (skip-chars-forward "^\s\t\n=E2=80=94") (skip-chars-for= ward "=E2=80=94"))) (end (point))) (if (eobp) (amread-stop) ;; create the overlay if does not exist (unless amread--overlay (setq amread--overlay (make-overlay begin end))) ;; move forward overlay (when amread--overlay ;; (delete-overlay amread--overlay) (move-overlay amread--overlay begin end)) (overlay-put amread--overlay 'face '((foreground-color . "white") (background-color . "dark green"))) (skip-chars-forward "\s\t\n=E2=80=94")))) (defun amread-start () "Start / resume amread." (interactive) (setq qamread--running (run-with-timer 0 (/ 1.0 amread-wps) #'amread--update))) (defun amread-stop () "Stop amread." (interactive) (prog1 amread--running (when amread--running (cancel-timer amread--running) (setq amread--running nil) (delete-overlay amread--overlay)))) (defvar amread-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "q") 'amread-stop) (define-key map [remap keyaobrd-quit] 'amread-stop) map) "Keymap for amread-mode buffers.") (define-minor-mode amread-mode "I'm reading qmode." :init nil :keymap amread-mode-map (if amread--running (amread-stop) (amread-start))) #+end_src But the problem is that I can't stop this timer with defined keybinding =3D= [q]=3D nor with minor mode toggle command =3Damread-mode=3D. I don't know where is the problem. can someone help me to review my code? BTW, if someone can have better solution to integrate =3Dbeacon.el=3D packa= ge, it might be an alternative solution, will looks better with animation. Even th= ough using property on words is simple and clean. --=20 [ stardiviner ] I try to make every word tell the meaning what I want to express. Blog: https://stardiviner.github.io/ IRC(freenode): stardiviner, Matrix: stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 =20=20=20=20=20=20