branch: elpa/evil-emacs-cursor-model-mode
commit 03cda90774485e1ce95dded3656daad749cac5ed
Author: maxfriis <[email protected]>
Commit: GitHub <[email protected]>

    Let case-fold-search added to repeat find char
    
    Cured bug where repeat-find-char was not case sensitive when normal 
find-char is.
---
 evil-emacs-cursor-model-mode.el | 96 +++++++++++++++++++----------------------
 1 file changed, 44 insertions(+), 52 deletions(-)

diff --git a/evil-emacs-cursor-model-mode.el b/evil-emacs-cursor-model-mode.el
index dde91513cb..11d0cd4a96 100644
--- a/evil-emacs-cursor-model-mode.el
+++ b/evil-emacs-cursor-model-mode.el
@@ -5,12 +5,14 @@
 ;; ============================================================================
 ;; Creative Commons Attribution-ShareAlike 4.0 International License
 ;; [[https://creativecommons.org/licenses/by-sa/4.0/]]
-
 ;; ----------------------------------------------------------------------------
 ;; Thanks.
-;; A special thanks to Toby Cubitt who coded the motions in the cursor model.
+;; Thanks to Toby Cubitt who coded most of the motions in the cursor model.
 ;; Peter Friis Jensen made it a mode and swapped some keybindings.
 
+;; ============================================================================
+;;; Package meta data:
+;; ============================================================================
 ;; Author: Toby Cubitt
 ;; Maintainer: Peter Friis Jensen <[email protected]>
 ;; URL: https://github.com/maxfriis/evil-emacs-cursor-model-mode
@@ -40,15 +42,15 @@
 ;;; Code:
 ;; ============================================================================
 (require 'evil)
-
 ;; ----------------------------------------------------------------------------
 ;; Remember init defaults.
 (defvar evil-emacs-cursor-model-move-cursor-back-init evil-move-cursor-back
-  "For toggling the variable with `evil-emacs-cursor-model-mode'.")
+  "For toggling `evil-move-cursor-back' with `evil-emacs-cursor-model-mode'.")
 (defvar evil-emacs-cursor-model-move-beyond-eol-init evil-move-beyond-eol
-  "For toggling the variable with `evil-emacs-cursor-model-mode'.")
+  "For toggling `evil-move-beyond-eol' with `evil-emacs-cursor-model-mode'.")
 (defvar evil-emacs-cursor-model-highlight-closing-paren-at-point-states-init 
evil-highlight-closing-paren-at-point-states
-  "For toggling the variable with `evil-emacs-cursor-model-mode'.")
+  "For toggling `evil-highlight-closing-paren-at-point-states' with
+`evil-emacs-cursor-model-mode'.")
 
 ;; ============================================================================
 ;;; The minor mode
@@ -59,7 +61,7 @@
 The idea is to avoid the <shift> layer when dealing with the current line.
 Layers can then be replaced with a motion with equivalent efficiency.
 \nEmbrace the mindset of Emacs' cursor model and motions among line nuggets.
-Maybe fewer layers are better for your Emacs pinky?"
+Maybe fewer layers are better if you have an Emacs pinky?"
   :lighter nil
   :global t
   :require 'evil-emacs-cursor-model-mode
@@ -83,7 +85,7 @@ Maybe fewer layers are better for your Emacs pinky?"
       "O"  #'evil-org-open-below))
    (t ; else
     ;; 
----------------------------------------------------------------------------
-    ;; Back to `evil-mode' defaults when `evil-emacs-cursor-model-mode' is 
disabled.
+    ;; Back to user init defaults when `evil-emacs-cursor-model-mode' is 
disabled.
     (setq
      evil-move-cursor-back evil-emacs-cursor-model-move-cursor-back-init
      evil-move-beyond-eol evil-emacs-cursor-model-move-beyond-eol-init
@@ -163,52 +165,50 @@ Maybe fewer layers are better for your Emacs pinky?"
 Movement is restricted to the current line unless `evil-cross-lines' is 
non-nil."
   :type inclusive
   (interactive "<c><C>")
-  (unless count (setq count 1))
-  (if (and (= char (char-after))
-           (> count 0))
+  (setq count (or count 1))
+  (if (and (= char (char-after)) (plusp count))
       (evil-find-char (1- count) char)
     (evil-find-char count char))
-  (when (> count 0) (forward-char))
-  (setq evil-last-find (list #'evil-find-char char (> count 0))))
+  (when (plusp count) (forward-char)))
 
 (evil-define-motion evil-emacs-cursor-model-find-before-char (count char)
   "Move point immediately before the next COUNT'th occurrence of CHAR.
 Movement is restricted to the current line unless `evil-cross-lines' is 
non-nil."
   :type inclusive
   (interactive "<c><C>")
-  (unless count (setq count 1))
-  (if (and (= char (char-after))
-           (> count 0))
+  (setq count (or count 1))
+  (if (and (= char (char-after)) (plusp count))
       (evil-find-char (1- count) char)
     (evil-find-char count char))
-  (setq evil-last-find (list #'evil-find-char-to char (> count 0))))
+  (setq evil-last-find (list #'evil-find-char-to char (plusp count))))
 
 (evil-define-motion evil-emacs-cursor-model-repeat-find-char (count)
   "Repeat the last find COUNT times."
   :type inclusive
   (interactive "<c>")
-  (unless count (setq count 1))
-  (unless (nth 2 evil-last-find) (setq count (- count))) ; Backwards search.
+  (setq count (or count 1))
+  (unless (nth 2 evil-last-find) (setq count (- count)))
   (let ((find (eq (car evil-last-find) #'evil-find-char))
-        (char (nth 1 evil-last-find)))
+        (char (nth 1 evil-last-find))
+        case-fold-search)
     (unless char (user-error "No previous search"))
     (unless find
-      (cond ; Vim does this when find is nil.
-       ((and (= count  1) (= char (char-after)))  (setq count (1+ count)))
-       ((and (= count -1) (= char (char-before))) (setq count (1- count)))))
+      (cond ((and (= count  1) (= char (char-after)))  (incf count))
+            ((and (= count -1) (= char (char-before))) (decf count))))
     (if (search-forward
          (char-to-string char)
          (cond (evil-cross-lines nil)
-               ((and evil-respect-visual-line-mode
-                     visual-line-mode)
+               ((and evil-respect-visual-line-mode visual-line-mode)
                 (save-excursion
-                  (if (> count 0) (end-of-visual-line) 
(beginning-of-visual-line))
+                  (if (plusp count)
+                      (end-of-visual-line)
+                    (beginning-of-visual-line))
                   (point)))
-               ((> count 0) (line-end-position))
+               ((plusp count) (line-end-position))
                (t (line-beginning-position)))
          t count)
-        (unless (or find (= count 0))
-          (if (> count 0) (backward-char) (forward-char)))
+        (unless (or find (zerop count))
+          (if (plusp count) (backward-char) (forward-char)))
       (user-error "Can't find `%c'" char))))
 
 (evil-define-motion evil-emacs-cursor-model-repeat-find-char-reverse (count)
@@ -221,22 +221,19 @@ Movement is restricted to the current line unless 
`evil-cross-lines' is non-nil.
   "Move forward to end of THING.
 The motion is repeated COUNT times."
   (setq count (or count 1))
-  (cond
-   ((> count 0)
-    (forward-thing thing count))
-   (t
+  (if (plusp count)
+      (forward-thing thing count)
     (unless (bobp) (backward-char))
     (let ((bnd (bounds-of-thing-at-point thing))
           rest)
       (when bnd
-        (cond
-         ((< (point) (cdr bnd)) (goto-char (car bnd)))
-         ((= (point) (cdr bnd)) (setq count (1+ count)))))
+        (cond ((< (point) (cdr bnd)) (goto-char (car bnd)))
+              ((= (point) (cdr bnd)) (incf count))))
       (condition-case nil
           (when (zerop (setq rest (forward-thing thing count)))
             (end-of-thing thing))
         (error))
-      rest))))
+      rest)))
 
 (defun evil-emacs-cursor-model-backward-after-end (thing &optional count)
   "Move backward to end of THING.
@@ -282,26 +279,21 @@ If the end position is at the beginning of a line, then:
   :expand (lambda (beg end) (evil-range beg end))
   :contract (lambda (beg end) (evil-range beg end))
   :normalize (lambda (beg end)
-               (cond
-                ((progn
-                   (goto-char end)
-                   (and (/= beg end) (bolp)))
+               (if (progn
+                     (goto-char end)
+                     (or (= beg end) (not (bolp))))
+                   (evil-range beg end)
                  (setq end (max beg (1- end)))
-                 (cond
-                  ((progn
-                     (goto-char beg)
-                     (looking-back "^[\f\s\t\v]*" (line-beginning-position)))
-                   (evil-expand beg end 'line))
-                  (t
+                 (if (progn
+                       (goto-char beg)
+                       (looking-back "^[\f\s\t\v]*" (line-beginning-position)))
+                     (evil-expand beg end 'line)
                    (unless evil-cross-lines
                      (setq end (max beg (1- end))))
                    (evil-expand beg end 'inclusive))))
-                (t
-                 (evil-range beg end))))
   :string (lambda (beg end)
             (let ((width (- end beg)))
-              (format "%s character%s" width
-                      (if (= width 1) "" "s")))))
+              (format "%s character%s" width (if (= width 1) "" "s")))))
 
 ;; ----------------------------------------------------------------------------
 ;;;; Make "e" search offset put point after last character.
@@ -328,7 +320,7 @@ or somewhere after the cursor and jump to the corresponding 
one."
   :jump t
   :type inclusive
   (let ((pos (point)))
-    (unless (or (bolp) (bobp)) (backward-char))
+    (unless (bolp) (backward-char))
     (condition-case nil
         (evil-jump-item count)
       (user-error (goto-char pos)))

Reply via email to