From 523c4e99eb04ba3f8e279b0969b6df51eaab43b3 Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Tue, 13 Nov 2018 12:48:39 +0100 Subject: [PATCH] update focus. Signed-off-by: Andreas Gerler --- bba.org | 2 +- elpa/focus-20160111.522/focus-pkg.el | 1 - .../focus-autoloads.el | 10 +- elpa/focus-20171204.503/focus-pkg.el | 2 + .../focus.el | 105 +++++++++++------- 5 files changed, 74 insertions(+), 46 deletions(-) delete mode 100644 elpa/focus-20160111.522/focus-pkg.el rename elpa/{focus-20160111.522 => focus-20171204.503}/focus-autoloads.el (60%) create mode 100644 elpa/focus-20171204.503/focus-pkg.el rename elpa/{focus-20160111.522 => focus-20171204.503}/focus.el (79%) diff --git a/bba.org b/bba.org index 2aac89f5..aa9b9a00 100644 --- a/bba.org +++ b/bba.org @@ -306,7 +306,7 @@ focus on the important stuff. #+BEGIN_SRC emacs-lisp :tangle yes (if (>= emacs-major-version 24) (progn - (add-to-list 'load-path "~/.emacs.d/elpa/focus-20160111.522") + (add-to-list 'load-path "~/.emacs.d/elpa/focus-20171204.503") (require 'focus) (setq focus-dimness -1) )) diff --git a/elpa/focus-20160111.522/focus-pkg.el b/elpa/focus-20160111.522/focus-pkg.el deleted file mode 100644 index 9946956b..00000000 --- a/elpa/focus-20160111.522/focus-pkg.el +++ /dev/null @@ -1 +0,0 @@ -(define-package "focus" "20160111.522" "Dim the font color of text in surrounding sections" '((emacs "24") (cl-lib "0.5")) :url "http://github.com/larstvei/Focus") diff --git a/elpa/focus-20160111.522/focus-autoloads.el b/elpa/focus-20171204.503/focus-autoloads.el similarity index 60% rename from elpa/focus-20160111.522/focus-autoloads.el rename to elpa/focus-20171204.503/focus-autoloads.el index 6388df69..f782de71 100644 --- a/elpa/focus-20160111.522/focus-autoloads.el +++ b/elpa/focus-20171204.503/focus-autoloads.el @@ -1,9 +1,12 @@ ;;; focus-autoloads.el --- automatically extracted autoloads ;; ;;; Code: -(add-to-list 'load-path (or (file-name-directory #$) (car load-path))) + +(add-to-list 'load-path (directory-file-name + (or (file-name-directory #$) (car load-path)))) + -;;;### (autoloads nil "focus" "focus.el" (22173 12017 0 0)) +;;;### (autoloads nil "focus" "focus.el" (0 0 0 0)) ;;; Generated autoloads from focus.el (autoload 'focus-mode "focus" "\ @@ -16,11 +19,14 @@ A read-only mode optimized for `focus-mode'. \(fn &optional ARG)" t nil) +(if (fboundp 'register-definition-prefixes) (register-definition-prefixes "focus" '("turn-off-focus-read-only-mode" "focus-"))) + ;;;*** ;; Local Variables: ;; version-control: never ;; no-byte-compile: t ;; no-update-autoloads: t +;; coding: utf-8 ;; End: ;;; focus-autoloads.el ends here diff --git a/elpa/focus-20171204.503/focus-pkg.el b/elpa/focus-20171204.503/focus-pkg.el new file mode 100644 index 00000000..443f8b82 --- /dev/null +++ b/elpa/focus-20171204.503/focus-pkg.el @@ -0,0 +1,2 @@ +;;; -*- no-byte-compile: t -*- +(define-package "focus" "20171204.503" "Dim the font color of text in surrounding sections" '((emacs "24") (cl-lib "0.5")) :commit "045ee6175e9340f873db03445c74ff9eefa35a27" :authors '(("Lars Tveito" . "larstvei@ifi.uio.no")) :maintainer '("Lars Tveito" . "larstvei@ifi.uio.no") :url "http://github.com/larstvei/Focus") diff --git a/elpa/focus-20160111.522/focus.el b/elpa/focus-20171204.503/focus.el similarity index 79% rename from elpa/focus-20160111.522/focus.el rename to elpa/focus-20171204.503/focus.el index b24ef8f0..710030e0 100644 --- a/elpa/focus-20160111.522/focus.el +++ b/elpa/focus-20171204.503/focus.el @@ -4,9 +4,9 @@ ;; Author: Lars Tveito ;; URL: http://github.com/larstvei/Focus -;; Package-Version: 20160111.522 +;; Package-Version: 20171204.503 ;; Created: 11th May 2015 -;; Version: 0.1.0 +;; Version: 0.1.1 ;; Package-Requires: ((emacs "24") (cl-lib "0.5")) ;; This program is free software; you can redistribute it and/or modify @@ -71,9 +71,15 @@ Things that are defined include `symbol', `list', `sexp', :type '(float) :group 'focus) +(defvar focus-cursor-type cursor-type + "Used to restore the users `cursor-type'") + (defvar focus-current-thing nil "Overrides the choice of thing dictated by `focus-mode-to-thing' if set.") +(defvar focus-buffer nil + "Local reference to the buffer focus functions operate on.") + (defvar focus-pre-overlay nil "The overlay that dims the text prior to the current-point.") @@ -87,30 +93,19 @@ The timer calls `focus-read-only-hide-cursor' after ;; Use make-local-variable for backwards compatibility. (dolist (var '(focus-current-thing + focus-buffer focus-pre-overlay focus-post-overlay focus-read-only-blink-timer)) (make-local-variable var)) -;; Changing major-mode should not affect Focus mode. -(dolist (var '(focus-current-thing - focus-pre-overlay - focus-post-overlay - post-command-hook)) - (put var 'permanent-local t)) - -(defun focus-any (f lst) - "Apply F to each element of LST and return first NON-NIL." - (when lst - (let ((v (funcall f (car lst)))) - (if v v (focus-any f (cdr lst)))))) - (defun focus-get-thing () "Return the current thing, based on `focus-mode-to-thing'." (or focus-current-thing - (let* ((modes (mapcar 'car focus-mode-to-thing)) - (mode (focus-any 'derived-mode-p modes))) - (if mode (cdr (assoc mode focus-mode-to-thing)) 'sentence)))) + (let* ((modes (mapcar 'car focus-mode-to-thing)) + (mode (or (cl-find major-mode modes) + (apply #'derived-mode-p modes)))) + (if mode (cdr (assoc mode focus-mode-to-thing)) 'sentence)))) (defun focus-bounds () "Return the current bounds, based on `focus-get-thing'." @@ -139,14 +134,19 @@ argument." (make-list foregrounds foreground))))) (defun focus-move-focus () - "Move `focus-pre-overlay' and `focus-post-overlay'. + "Moves the focused section according to `focus-bounds'. -If function `focus-mode' is enabled, this command fires after -each command." - (let* ((bounds (focus-bounds))) - (when bounds - (move-overlay focus-pre-overlay (point-min) (car bounds)) - (move-overlay focus-post-overlay (cdr bounds) (point-max))))) +If `focus-mode' is enabled, this command fires after each +command." + (with-current-buffer focus-buffer + (let* ((bounds (focus-bounds))) + (when bounds + (focus-move-overlays (car bounds) (cdr bounds)))))) + +(defun focus-move-overlays (low high) + "Move `focus-pre-overlay' and `focus-post-overlay'." + (move-overlay focus-pre-overlay (point-min) low) + (move-overlay focus-post-overlay high (point-max))) (defun focus-init () "This function is run when command `focus-mode' is enabled. @@ -156,11 +156,13 @@ overlays; these are invisible until `focus-move-focus' is run. It adds `focus-move-focus' to `post-command-hook'." (unless (or focus-pre-overlay focus-post-overlay) (setq focus-pre-overlay (make-overlay (point-min) (point-min)) - focus-post-overlay (make-overlay (point-max) (point-max))) + focus-post-overlay (make-overlay (point-max) (point-max)) + focus-buffer (current-buffer)) (let ((color (focus-make-dim-color))) (mapc (lambda (o) (overlay-put o 'face (cons 'foreground-color color))) (list focus-pre-overlay focus-post-overlay))) - (add-hook 'post-command-hook 'focus-move-focus nil t))) + (add-hook 'post-command-hook 'focus-move-focus nil t) + (add-hook 'change-major-mode-hook 'focus-terminate nil t))) (defun focus-terminate () "This function is run when command `focus-mode' is disabled. @@ -188,11 +190,26 @@ default is overwritten. This function simply helps set the `focus-current-thing'." (interactive) (let* ((candidates '(symbol list sexp defun - filename url email word - sentence whitespace line page)) + filename url email word + sentence whitespace line page)) (thing (completing-read "Thing: " candidates))) (setq focus-current-thing (intern thing)))) +(defun focus-pin () + "Pin the focused section to its current location or the region, +if active." + (interactive) + (when focus-mode + (when (region-active-p) + (focus-move-overlays (region-beginning) (region-end))) + (remove-hook 'post-command-hook 'focus-move-focus t))) + +(defun focus-unpin () + "Unpin the focused section." + (interactive) + (when focus-mode + (add-hook 'post-command-hook 'focus-move-focus nil t))) + (defun focus-next-thing (&optional n) "Moves the point to the middle of the Nth next thing." (interactive "p") @@ -200,7 +217,7 @@ default is overwritten. This function simply helps set the (thing (focus-get-thing))) (forward-thing thing n) (when (equal current-bounds (focus-bounds)) - (forward-thing thing (signum n))) + (forward-thing thing (cl-signum n))) (focus-goto-thing (focus-bounds)))) (defun focus-prev-thing (&optional n) @@ -208,11 +225,11 @@ default is overwritten. This function simply helps set the (interactive "p") (focus-next-thing (- n))) -(defun focus-read-only-hide-cursor (&optional buffer) +(defun focus-read-only-hide-cursor () "Hide the cursor. This function is triggered by the `focus-read-only-blink-timer', when `focus-read-only-mode' is activated." - (with-current-buffer (or buffer (current-buffer)) + (with-current-buffer focus-buffer (when (and focus-read-only-mode (not (null focus-read-only-blink-timer))) (setq focus-read-only-blink-timer nil) (setq cursor-type nil)))) @@ -221,13 +238,14 @@ when `focus-read-only-mode' is activated." "Make the cursor visible for `focus-read-only-blink-seconds'. This is added to the `pre-command-hook' when `focus-read-only-mode' is active." - (when (and focus-read-only-mode - (not (member last-command '(focus-next-thing focus-prev-thing)))) - (when focus-read-only-blink-timer (cancel-timer focus-read-only-blink-timer)) - (setq cursor-type t) - (setq focus-read-only-blink-timer - (run-at-time focus-read-only-blink-seconds nil - 'focus-read-only-hide-cursor (current-buffer))))) + (with-current-buffer focus-buffer + (when (and focus-read-only-mode + (not (member last-command '(focus-next-thing focus-prev-thing)))) + (when focus-read-only-blink-timer (cancel-timer focus-read-only-blink-timer)) + (setq cursor-type focus-cursor-type) + (setq focus-read-only-blink-timer + (run-at-time focus-read-only-blink-seconds nil + 'focus-read-only-hide-cursor))))) (defun focus-read-only-init () "Run when `focus-read-only-mode' is activated. @@ -235,16 +253,17 @@ Enables `read-only-mode', hides the cursor and adds `focus-read-only-cursor-blink' to `pre-command-hook'. Also `focus-read-only-terminate' is added to the `kill-buffer-hook'." (read-only-mode 1) - (setq cursor-type nil) + (setq cursor-type nil + focus-buffer (current-buffer)) (add-hook 'pre-command-hook 'focus-read-only-cursor-blink nil t) - (add-hook 'kill-buffer-hook 'focus-read-only-terminate t)) + (add-hook 'kill-buffer-hook 'focus-read-only-terminate nil t)) (defun focus-read-only-terminate () "Run when `focus-read-only-mode' is deactivated. Disables `read-only-mode' and shows the cursor again. It cleans up the `focus-read-only-blink-timer' and hooks." (read-only-mode -1) - (setq cursor-type t) + (setq cursor-type focus-cursor-type) (when focus-read-only-blink-timer (cancel-timer focus-read-only-blink-timer)) (setq focus-read-only-blink-timer nil) @@ -281,6 +300,8 @@ up the `focus-read-only-blink-timer' and hooks." (define-key map (kbd "i") 'turn-off-focus-read-only-mode) (define-key map (kbd "q") 'turn-off-focus-read-only-mode) map) + (when cursor-type + (setq focus-cursor-type cursor-type)) (if focus-read-only-mode (focus-read-only-init) (focus-read-only-terminate))) (provide 'focus) -- 2.47.3