From 0ca738989e405c96bf8d67882d6fb50ddacb219c Mon Sep 17 00:00:00 2001 From: syl20bnr Date: Wed, 2 Mar 2016 09:13:09 -0500 Subject: [PATCH] Update, simplify and add smooth scrolling toggle on `SPC t v` --- doc/DOCUMENTATION.org | 5 ++- .../spacemacs-ui-visual/packages.el | 43 ++++++++++--------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/doc/DOCUMENTATION.org b/doc/DOCUMENTATION.org index 8944d6200..6424d5917 100644 --- a/doc/DOCUMENTATION.org +++ b/doc/DOCUMENTATION.org @@ -919,6 +919,7 @@ and ~T~): | ~SPC t l~ | toggle truncate lines | | ~SPC t L~ | toggle visual lines | | ~SPC t n~ | toggle line numbers | +| ~SPC t v~ | toggle smooth scrolling | | Key Binding | Description | |-------------+--------------------------------------------------------------| @@ -1405,9 +1406,11 @@ On Windows, you may want to disable it. To disable the smooth scrolling set the =dotspacemacs-smooth-scrolling= variable in your =~/.spacemacs= to =nil=: #+BEGIN_SRC emacs-lisp -(setq-default dotspacemacs-smooth-scrolling t) +(setq-default dotspacemacs-smooth-scrolling nil) #+END_SRC +You can also toggle smooth scrolling with ~SPC t v~. + *** Vim motions with avy Spacemacs uses the =evil= integration of [[https://github.com/abo-abo/avy][avy]] which enables the invocation of =avy= during motions. diff --git a/layers/+spacemacs/spacemacs-ui-visual/packages.el b/layers/+spacemacs/spacemacs-ui-visual/packages.el index dbdc7af95..6e4589136 100644 --- a/layers/+spacemacs/spacemacs-ui-visual/packages.el +++ b/layers/+spacemacs/spacemacs-ui-visual/packages.el @@ -233,32 +233,33 @@ (spacemacs//neotree-key-bindings))) (defun spacemacs-ui-visual/init-smooth-scrolling () - (defun spacemacs//unset-scroll-margin () - "Set scroll-margin to zero." - (setq-local scroll-margin 0)) - (use-package smooth-scrolling - :if dotspacemacs-smooth-scrolling - :init (setq smooth-scroll-margin 5 - scroll-conservatively 101 - scroll-preserve-screen-position t - auto-window-vscroll nil) - :config + :init (progn - (setq scroll-margin 5) + (setq smooth-scroll-margin 5) + (spacemacs|add-toggle smooth-scrolling + :status smooth-scrolling-mode + :on (progn + (smooth-scrolling-mode) + (enable-smooth-scroll-for-function previous-line) + (enable-smooth-scroll-for-function next-line) + (enable-smooth-scroll-for-function isearch-repeat)) + :off (progn + (smooth-scrolling-mode -1) + (disable-smooth-scroll-for-function previous-line) + (disable-smooth-scroll-for-function next-line) + (disable-smooth-scroll-for-function isearch-repeat)) + :documentation "Smooth scrolling." + :evil-leader "tv") + (unless dotspacemacs-smooth-scrolling + (spacemacs/toggle-smooth-scrolling-off)) ;; add hooks here only for emacs built-in packages that are not owned ;; by a layer. + (defun spacemacs//unset-scroll-margin () + "Set scroll-margin to zero." + (setq-local scroll-margin 0)) (spacemacs/add-to-hooks 'spacemacs//unset-scroll-margin - '(messages-buffer-mode-hook)))) - - (unless dotspacemacs-smooth-scrolling - ;; deactivate smooth-scrolling advices - (ad-disable-advice 'previous-line 'after 'smooth-scroll-down) - (ad-activate 'previous-line) - (ad-disable-advice 'next-line 'after 'smooth-scroll-up) - (ad-activate 'next-line) - (ad-disable-advice 'isearch-repeat 'after 'isearch-smooth-scroll) - (ad-activate 'isearch-repeat))) + '(messages-buffer-mode-hook))))) (defun spacemacs-ui-visual/init-spaceline () (use-package spaceline-config