forked from emacs-evil/evil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
evil-commands.el
4739 lines (4363 loc) · 176 KB
/
evil-commands.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;; evil-commands.el --- Evil commands and operators -*- lexical-binding: t -*-
;; Author: Vegard Øye <vegard_oye at hotmail.com>
;; Maintainer: Vegard Øye <vegard_oye at hotmail.com>
;; Version: 1.14.0
;;
;; This file is NOT part of GNU Emacs.
;;; License:
;; This file is part of Evil.
;;
;; Evil is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; Evil is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with Evil. If not, see <http://www.gnu.org/licenses/>.
(require 'evil-common)
(require 'evil-digraphs)
(require 'evil-search)
(require 'evil-ex)
(require 'evil-types)
(require 'evil-command-window)
(require 'evil-jumps)
(require 'evil-vars)
(require 'flyspell)
(require 'cl-lib)
(require 'reveal)
(declare-function imenu--in-alist "imenu")
;;; Motions
;; Movement commands, or motions, are defined with the macro
;; `evil-define-motion'. A motion is a command with an optional
;; argument COUNT (interactively accessed by the code "<c>").
;; It may specify the :type command property (e.g., :type line),
;; which determines how it is handled by an operator command.
;; Furthermore, the command must have the command properties
;; :keep-visual t and :repeat motion; these are automatically
;; set by the `evil-define-motion' macro.
;;; Code:
(evil-define-motion evil-forward-char (count &optional crosslines noerror)
"Move cursor to the right by COUNT characters.
Movement is restricted to the current line unless CROSSLINES is non-nil.
If NOERROR is non-nil, don't signal an error upon reaching the end
of the line or the buffer; just return nil."
:type exclusive
(interactive "<c>" (list evil-cross-lines
(evil-kbd-macro-suppress-motion-error)))
(cond
(noerror
(condition-case nil
(evil-forward-char count crosslines nil)
(error nil)))
((not crosslines)
;; for efficiency, narrow the buffer to the projected
;; movement before determining the current line
(evil-with-restriction
(point)
(save-excursion
(evil-forward-char (1+ (or count 1)) t t)
(point))
(condition-case err
(evil-narrow-to-line
(evil-forward-char count t noerror))
(error
;; Restore the previous command (this one never happend).
;; Actually, this preserves the current column if the
;; previous command was `evil-next-line' or
;; `evil-previous-line'.
(setq this-command last-command)
(signal (car err) (cdr err))))))
(t
(evil-motion-loop (nil (or count 1))
(forward-char)
;; don't put the cursor on a newline
(when (and (not evil-move-beyond-eol)
(not (evil-visual-state-p))
(not (evil-operator-state-p))
(eolp) (not (eobp)) (not (bolp)))
(forward-char))))))
(evil-define-motion evil-backward-char (count &optional crosslines noerror)
"Move cursor to the left by COUNT characters.
Movement is restricted to the current line unless CROSSLINES is non-nil.
If NOERROR is non-nil, don't signal an error upon reaching the beginning
of the line or the buffer; just return nil."
:type exclusive
(interactive "<c>" (list evil-cross-lines
(evil-kbd-macro-suppress-motion-error)))
(cond
(noerror
(condition-case nil
(evil-backward-char count crosslines nil)
(error nil)))
((not crosslines)
;; restrict movement to the current line
(evil-with-restriction
(save-excursion
(evil-backward-char (1+ (or count 1)) t t)
(point))
(1+ (point))
(condition-case err
(evil-narrow-to-line
(evil-backward-char count t noerror))
(error
;; Restore the previous command (this one never happened).
;; Actually, this preserves the current column if the
;; previous command was `evil-next-line' or
;; `evil-previous-line'.
(setq this-command last-command)
(signal (car err) (cdr err))))))
(t
(evil-motion-loop (nil (or count 1))
(backward-char)
;; don't put the cursor on a newline
(unless (or (evil-visual-state-p) (evil-operator-state-p))
(evil-adjust-cursor))))))
(evil-define-motion evil-next-line (count)
"Move the cursor COUNT lines down."
:type line
(let (line-move-visual)
(evil-line-move (or count 1))))
(evil-define-motion evil-previous-line (count)
"Move the cursor COUNT lines up."
:type line
(let (line-move-visual)
(evil-line-move (- (or count 1)))))
(evil-define-motion evil-next-visual-line (count)
"Move the cursor COUNT screen lines down."
:type exclusive
(let ((line-move-visual t))
(evil-line-move (or count 1))))
(evil-define-motion evil-previous-visual-line (count)
"Move the cursor COUNT screen lines up."
:type exclusive
(let ((line-move-visual t))
(evil-line-move (- (or count 1)))))
;; used for repeated commands like "dd"
(evil-define-motion evil-line (count)
"Move COUNT - 1 lines down."
:type line
(let (line-move-visual)
;; Catch bob and eob errors. These are caused when not moving
;; point starting in the first or last line, respectively. In this
;; case the current line should be selected.
(condition-case _err
(evil-line-move (1- (or count 1)))
((beginning-of-buffer end-of-buffer)))))
(evil-define-motion evil-line-or-visual-line (count)
"Move COUNT - 1 lines down."
:type screen-line
(let ((line-move-visual (and evil-respect-visual-line-mode
visual-line-mode)))
;; Catch bob and eob errors. These are caused when not moving
;; point starting in the first or last line, respectively. In this
;; case the current line should be selected.
(condition-case _err
(evil-line-move (1- (or count 1)))
((beginning-of-buffer end-of-buffer)))))
(evil-define-motion evil-beginning-of-line ()
"Move the cursor to the beginning of the current line."
:type exclusive
(move-beginning-of-line nil))
(evil-define-motion evil-end-of-line (count)
"Move the cursor to the end of the current line.
If COUNT is given, move COUNT - 1 lines downward first."
:type inclusive
(move-end-of-line count)
(when evil-track-eol
(setq temporary-goal-column most-positive-fixnum
this-command 'next-line))
(unless (evil-visual-state-p)
(evil-adjust-cursor)
(when (eolp)
;; prevent "c$" and "d$" from deleting blank lines
(setq evil-this-type 'exclusive))))
(evil-define-motion evil-beginning-of-visual-line ()
"Move the cursor to the first character of the current screen line."
:type exclusive
(if (fboundp 'beginning-of-visual-line)
(beginning-of-visual-line)
(beginning-of-line)))
(evil-define-motion evil-end-of-visual-line (count)
"Move the cursor to the last character of the current screen line.
If COUNT is given, move COUNT - 1 screen lines downward first."
:type inclusive
(if (fboundp 'end-of-visual-line)
(end-of-visual-line count)
(end-of-line count)))
(evil-define-motion evil-end-of-line-or-visual-line (count)
"Move the cursor to the last character of the current screen
line if `visual-line-mode' is active and
`evil-respect-visual-line-mode' is non-nil. If COUNT is given,
move COUNT - 1 screen lines downward first."
:type inclusive
(if (and (fboundp 'end-of-visual-line)
evil-respect-visual-line-mode
visual-line-mode)
(end-of-visual-line count)
(evil-end-of-line count)))
(evil-define-motion evil-middle-of-visual-line ()
"Move the cursor to the middle of the current visual line."
:type exclusive
(beginning-of-visual-line)
(evil-with-restriction
nil
(save-excursion (end-of-visual-line) (point))
(move-to-column (+ (current-column)
-1
(/ (with-no-warnings (window-body-width)) 2)))))
(evil-define-motion evil-beginning-of-line-or-digit-argument ()
"Move the cursor to the beginning of the current line.
This function passes its command to `digit-argument' (usually a 0)
if it is not the first event."
:type exclusive
(cond
(current-prefix-arg
(setq this-command #'digit-argument)
(call-interactively #'digit-argument))
(t
(setq this-command #'evil-beginning-of-line)
(call-interactively #'evil-beginning-of-line))))
(evil-define-motion evil-first-non-blank ()
"Move the cursor to the first non-blank character of the current line."
:type exclusive
(evil-narrow-to-line (back-to-indentation)))
(evil-define-motion evil-last-non-blank (count)
"Move the cursor to the last non-blank character of the current line.
If COUNT is given, move COUNT - 1 lines downward first."
:type inclusive
(goto-char
(save-excursion
(evil-move-beginning-of-line count)
(if (re-search-forward "[ \t]*$")
(max (line-beginning-position)
(1- (match-beginning 0)))
(line-beginning-position)))))
(evil-define-motion evil-first-non-blank-of-visual-line ()
"Move the cursor to the first non blank character
of the current screen line."
:type exclusive
(evil-beginning-of-visual-line)
(skip-chars-forward " \t\r"))
(evil-define-motion evil-next-line-first-non-blank (count)
"Move the cursor COUNT lines down on the first non-blank character."
:type line
(let ((this-command this-command))
(evil-next-line (or count 1)))
(evil-first-non-blank))
(evil-define-motion evil-next-line-1-first-non-blank (count)
"Move the cursor COUNT-1 lines down on the first non-blank character."
:type line
(let ((this-command this-command))
(evil-next-line (1- (or count 1))))
(evil-first-non-blank))
(evil-define-motion evil-previous-line-first-non-blank (count)
"Move the cursor COUNT lines up on the first non-blank character."
:type line
(let ((this-command this-command))
(evil-previous-line (or count 1)))
(evil-first-non-blank))
(evil-define-motion evil-goto-line (count)
"Go to the first non-blank character of line COUNT.
By default the last line."
:jump t
:type line
(if (null count)
(with-no-warnings (end-of-buffer))
(goto-char (point-min))
(forward-line (1- count)))
(evil-first-non-blank))
(evil-define-motion evil-goto-first-line (count)
"Go to the first non-blank character of line COUNT.
By default the first line."
:jump t
:type line
(evil-goto-line (or count 1)))
(evil-define-motion evil-forward-word-begin (count &optional bigword)
"Move the cursor to the beginning of the COUNT-th next word.
If BIGWORD is non-nil, move by WORDS.
If this command is called in operator-pending state it behaves
differently. If point reaches the beginning of a word on a new
line point is moved back to the end of the previous line.
If called after a change operator, i.e. cw or cW,
`evil-want-change-word-to-end' is non-nil and point is on a word,
then both behave like ce or cE.
If point is at the end of the buffer and cannot be moved signal
'end-of-buffer is raised.
"
:type exclusive
(let ((thing (if bigword 'evil-WORD 'evil-word))
(orig (point))
(count (or count 1)))
(evil-signal-at-bob-or-eob count)
(cond
;; default motion, beginning of next word
((not (evil-operator-state-p))
(evil-forward-beginning thing count))
;; the evil-change operator, maybe behave like ce or cE
((and evil-want-change-word-to-end
(memq evil-this-operator evil-change-commands)
(< orig (or (cdr-safe (bounds-of-thing-at-point thing)) orig)))
;; forward-thing moves point to the correct position because
;; this is an exclusive motion
(forward-thing thing count))
;; operator state
(t
(prog1 (evil-forward-beginning thing count)
;; if we reached the beginning of a word on a new line in
;; Operator-Pending state, go back to the end of the previous
;; line
(when (and (> (line-beginning-position) orig)
(looking-back "^[[:space:]]*" (line-beginning-position)))
;; move cursor back as long as the line contains only
;; whitespaces and is non-empty
(evil-move-end-of-line 0)
;; skip non-empty lines containing only spaces
(while (and (looking-back "^[[:space:]]+$" (line-beginning-position))
(not (<= (line-beginning-position) orig)))
(evil-move-end-of-line 0))
;; but if the previous line is empty, delete this line
(when (bolp) (forward-char))))))))
(evil-define-motion evil-forward-word-end (count &optional bigword)
"Move the cursor to the end of the COUNT-th next word.
If BIGWORD is non-nil, move by WORDS."
:type inclusive
(let ((thing (if bigword 'evil-WORD 'evil-word))
(count (or count 1)))
(evil-signal-at-bob-or-eob count)
;; Evil special behaviour: e or E on a one-character word in
;; operator state does not move point
(unless (and (evil-operator-state-p)
(= 1 count)
(let ((bnd (bounds-of-thing-at-point thing)))
(and bnd
(= (car bnd) (point))
(= (cdr bnd) (1+ (point)))))
(looking-at "[[:word:]]"))
(evil-forward-end thing count))))
(evil-define-motion evil-backward-word-begin (count &optional bigword)
"Move the cursor to the beginning of the COUNT-th previous word.
If BIGWORD is non-nil, move by WORDS."
:type exclusive
(let ((thing (if bigword 'evil-WORD 'evil-word)))
(evil-signal-at-bob-or-eob (- (or count 1)))
(evil-backward-beginning thing count)))
(evil-define-motion evil-backward-word-end (count &optional bigword)
"Move the cursor to the end of the COUNT-th previous word.
If BIGWORD is non-nil, move by WORDS."
:type inclusive
(let ((thing (if bigword 'evil-WORD 'evil-word)))
(evil-signal-at-bob-or-eob (- (or count 1)))
(evil-backward-end thing count)))
(evil-define-motion evil-forward-WORD-begin (count)
"Move the cursor to the beginning of the COUNT-th next WORD."
:type exclusive
(evil-forward-word-begin count t))
(evil-define-motion evil-forward-WORD-end (count)
"Move the cursor to the end of the COUNT-th next WORD."
:type inclusive
(evil-forward-word-end count t))
(evil-define-motion evil-backward-WORD-begin (count)
"Move the cursor to the beginning of the COUNT-th previous WORD."
:type exclusive
(evil-backward-word-begin count t))
(evil-define-motion evil-backward-WORD-end (count)
"Move the cursor to the end of the COUNT-th previous WORD."
:type inclusive
(evil-backward-word-end count t))
;; section movement
(evil-define-motion evil-forward-section-begin (count)
"Move the cursor to the beginning of the COUNT-th next section."
:jump t
:type exclusive
(evil-signal-at-bob-or-eob count)
(evil-forward-beginning 'evil-defun count))
(evil-define-motion evil-forward-section-end (count)
"Move the cursor to the end of the COUNT-th next section."
:jump t
:type inclusive
(evil-signal-at-bob-or-eob count)
(evil-forward-end 'evil-defun count)
(unless (eobp) (forward-line)))
(evil-define-motion evil-backward-section-begin (count)
"Move the cursor to the beginning of the COUNT-th previous section."
:jump t
:type exclusive
(evil-signal-at-bob-or-eob (- (or count 1)))
(evil-backward-beginning 'evil-defun count))
(evil-define-motion evil-backward-section-end (count)
"Move the cursor to the end of the COUNT-th previous section."
:jump t
:type inclusive
(evil-signal-at-bob-or-eob (- (or count 1)))
(end-of-line -1)
(evil-backward-end 'evil-defun count)
(unless (eobp) (forward-line)))
(evil-define-motion evil-forward-sentence-begin (count)
"Move to the next COUNT-th beginning of a sentence or end of a paragraph."
:jump t
:type exclusive
(evil-signal-at-bob-or-eob count)
(evil-forward-nearest count
#'(lambda (_cnt)
(evil-forward-beginning 'evil-sentence))
#'evil-forward-paragraph))
(evil-define-motion evil-backward-sentence-begin (count)
"Move to the previous COUNT-th beginning of a sentence or paragraph."
:jump t
:type exclusive
(evil-signal-at-bob-or-eob (- (or count 1)))
(evil-forward-nearest (- (or count 1))
#'(lambda (_cnt)
(evil-backward-beginning 'evil-sentence))
#'(lambda (_cnt)
(evil-backward-paragraph))))
(evil-define-motion evil-forward-paragraph (count)
"Move to the end of the COUNT-th next paragraph."
:jump t
:type exclusive
(evil-signal-at-bob-or-eob count)
(evil-forward-end 'evil-paragraph count)
(unless (eobp) (forward-line)))
(evil-define-motion evil-backward-paragraph (count)
"Move to the beginning of the COUNT-th previous paragraph."
:jump t
:type exclusive
(evil-signal-at-bob-or-eob (- (or count 1)))
(unless (eobp) (forward-line))
(evil-backward-beginning 'evil-paragraph count)
(unless (bobp) (forward-line -1)))
(defvar hif-ifx-else-endif-regexp)
(evil-define-motion evil-jump-item (count)
"Find the next item in this line after or under the cursor
and jump to the corresponding one."
:jump t
:type inclusive
(cond
;; COUNT% jumps to a line COUNT percentage down the file
(count
(goto-char
(evil-normalize-position
(let ((size (- (point-max) (point-min))))
(+ (point-min)
(if (> size 80000)
(* count (/ size 100))
(/ (* count size) 100))))))
(back-to-indentation)
(setq evil-this-type 'line))
((and (evil-looking-at-start-comment t)
(let ((pnt (point)))
(forward-comment 1)
(or (not (bolp))
(prog1 nil (goto-char pnt)))))
(backward-char))
((and (not (eolp)) (evil-looking-at-end-comment t))
(forward-comment -1))
((and
(memq major-mode '(c-mode c++-mode))
(require 'hideif nil t)
(with-no-warnings
(let* ((hif-else-regexp (concat hif-cpp-prefix "\\(?:else\\|elif[ \t]+\\)"))
(hif-ifx-else-endif-regexp
(concat hif-ifx-regexp "\\|" hif-else-regexp "\\|" hif-endif-regexp)))
(cond
((save-excursion (beginning-of-line) (or (hif-looking-at-ifX) (hif-looking-at-else)))
(hif-find-next-relevant)
(while (hif-looking-at-ifX)
(hif-ifdef-to-endif)
(hif-find-next-relevant))
t)
((save-excursion (beginning-of-line) (hif-looking-at-endif))
(hif-endif-to-ifdef)
t))))))
(t
(let* ((open (point-max))
(close (point-max))
(open-pair (condition-case nil
(save-excursion
;; consider the character right before eol given that
;; point may be placed there, e.g. in visual state
(when (and (eolp) (not (bolp)))
(backward-char))
(setq open (1- (scan-lists (point) 1 -1)))
(when (< open (line-end-position))
(goto-char open)
(forward-list)
(1- (point))))
(error nil)))
(close-pair (condition-case nil
(save-excursion
;; consider the character right before eol given that
;; point may be placed there, e.g. in visual state
(when (and (eolp) (not (bolp)))
(backward-char))
(setq close (1- (scan-lists (point) 1 1)))
(when (< close (line-end-position))
(goto-char (1+ close))
(backward-list)
(point)))
(error nil))))
(cond
((not (or open-pair close-pair))
;; nothing found, check if we are inside a string
(let ((pnt (point))
(bnd (bounds-of-thing-at-point 'evil-string)))
(if (not (and bnd (< (point) (cdr bnd))))
;; no, then we really failed
(user-error "No matching item found on the current line")
;; yes, go to the end of the string and try again
(let ((endstr (cdr bnd)))
(when (or (save-excursion
(goto-char endstr)
(let ((b (bounds-of-thing-at-point 'evil-string)))
(and b (< (point) (cdr b))))) ; not at end of string
(condition-case nil
(progn
(goto-char endstr)
(evil-jump-item)
nil)
(error t)))
;; failed again, go back to original point
(goto-char pnt)
(user-error "No matching item found on the current line"))))))
((< open close) (goto-char open-pair))
(t (goto-char close-pair)))))))
(defun evil--flyspell-overlays-in-p (beg end)
(let ((ovs (overlays-in beg end))
done)
(while (and ovs (not done))
(when (flyspell-overlay-p (car ovs))
(setq done t))
(setq ovs (cdr ovs)))
done))
(defun evil--flyspell-overlay-at (pos forwardp)
(when (not forwardp)
(setq pos (max (1- pos) (point-min))))
(let ((ovs (overlays-at pos))
done)
(while (and ovs (not done))
(if (flyspell-overlay-p (car ovs))
(setq done t)
(setq ovs (cdr ovs))))
(when done
(car ovs))))
(defun evil--flyspell-overlay-after (pos limit forwardp)
(let (done)
(while (and (if forwardp
(< pos limit)
(> pos limit))
(not done))
(let ((ov (evil--flyspell-overlay-at pos forwardp)))
(when ov
(setq done ov)))
(setq pos (if forwardp
(next-overlay-change pos)
(previous-overlay-change pos))))
done))
(defun evil--next-flyspell-error (forwardp)
(when (evil--flyspell-overlays-in-p (point-min) (point-max))
(let ((pos (point))
limit
ov)
(when (evil--flyspell-overlay-at pos forwardp)
(if (/= pos (point-min))
(setq pos (save-excursion (goto-char pos)
(forward-word (if forwardp 1 -1))
(point)))
(setq pos (point-max))))
(setq limit (if forwardp (point-max) (point-min))
ov (evil--flyspell-overlay-after pos limit forwardp))
(if ov
(goto-char (overlay-start ov))
(when evil-search-wrap
(setq limit pos
pos (if forwardp (point-min) (point-max))
ov (evil--flyspell-overlay-after pos limit forwardp))
(when ov
(goto-char (overlay-start ov))))))))
(evil-define-motion evil-next-flyspell-error (count)
"Go to the COUNT'th spelling mistake after point."
(interactive "p")
(dotimes (_ count)
(evil--next-flyspell-error t)))
(evil-define-motion evil-prev-flyspell-error (count)
"Go to the COUNT'th spelling mistake preceding point."
(interactive "p")
(dotimes (_ count)
(evil--next-flyspell-error nil)))
(evil-define-motion evil-previous-open-paren (count)
"Go to [count] previous unmatched '('."
:type exclusive
(evil-up-paren ?\( ?\) (- (or count 1))))
(evil-define-motion evil-next-close-paren (count)
"Go to [count] next unmatched ')'."
:type exclusive
(forward-char)
(evil-up-paren ?\( ?\) (or count 1))
(backward-char))
(evil-define-motion evil-previous-open-brace (count)
"Go to [count] previous unmatched '{'."
:type exclusive
(evil-up-paren ?{ ?} (- (or count 1))))
(evil-define-motion evil-next-close-brace (count)
"Go to [count] next unmatched '}'."
:type exclusive
(forward-char)
(evil-up-paren ?{ ?} (or count 1))
(backward-char))
(defun evil--lowercase-markers ()
"Get all lowercase markers."
(cl-remove-if-not (lambda (x) (and (markerp (cdr x))
(<= ?a (car x) ?z)))
evil-markers-alist))
(defun evil--next-mark (forwardp)
"Move to next lowercase mark.
Move forward if FORWARDP is truthy or backward if falsey.
Loop back to the top of buffer if the end is reached."
(let ((pos (point))
(sorted-markers (sort (evil--lowercase-markers)
(lambda (a b) (< (cdr a) (cdr b))))))
(cond
((null sorted-markers)
(user-error "No marks in this buffer"))
(forwardp
(let ((next-marker (cl-some (lambda (x) (and (< pos (cdr x)) (cdr x)))
sorted-markers)))
(if next-marker
(goto-char (marker-position next-marker))
(goto-char (marker-position (cdar sorted-markers))))))
(t
(let* ((descending-markers (reverse sorted-markers))
(prev-marker (cl-some (lambda (x) (and (> pos (cdr x)) (cdr x)))
descending-markers)))
(if prev-marker
(goto-char (marker-position prev-marker))
(goto-char (marker-position (cdar descending-markers)))))))))
(evil-define-motion evil-next-mark (count)
"Go to [count] next lowercase mark."
:keep-visual t
:repeat nil
:type exclusive
:jump t
(dotimes (_ (or count 1))
(evil--next-mark t)))
(evil-define-motion evil-next-mark-line (count)
"Go to [count] line of next lowercase mark after current line."
:keep-visual t
:repeat nil
:type exclusive
:jump t
(if (evil--lowercase-markers)
(dotimes (_ (or count 1))
(evil-end-of-line)
(evil--next-mark t)
(evil-first-non-blank))
(user-error "No marks in this buffer")))
(evil-define-motion evil-previous-mark (count)
"Go to [count] previous lowercase mark."
:keep-visual t
:repeat nil
:type exclusive
:jump t
(dotimes (_ (or count 1))
(evil--next-mark nil)))
(evil-define-motion evil-previous-mark-line (count)
"Go to [count] line of previous lowercase mark before current line."
:keep-visual t
:repeat nil
:type exclusive
:jump t
(if (evil--lowercase-markers)
(dotimes (_ (or count 1))
(evil-beginning-of-line)
(evil--next-mark nil)
(evil-first-non-blank))
(user-error "No marks in this buffer")))
(evil-define-command evil-set-col-0-mark (_beg end mark)
"Set MARK at column 0 of line of END. Default is cursor line."
(interactive "<r><a>")
(if (< 1 (length mark))
(user-error "Trailing characters")
(save-excursion
(goto-char (if (eobp) end (1- end)))
(evil-beginning-of-line)
(evil-set-marker (string-to-char mark)))))
(evil-define-motion evil-find-char (count char)
"Move to 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>")
(setq count (or count 1))
(let ((fwd (> count 0))
(visual (and evil-respect-visual-line-mode
visual-line-mode)))
(setq evil-last-find (list #'evil-find-char char fwd))
(when fwd (evil-forward-char 1 evil-cross-lines))
(let ((case-fold-search nil))
(unless (prog1
(search-forward (char-to-string char)
(cond (evil-cross-lines
nil)
((and fwd visual)
(save-excursion
(end-of-visual-line)
(point)))
(fwd
(line-end-position))
(visual
(save-excursion
(beginning-of-visual-line)
(point)))
(t
(line-beginning-position)))
t count)
(when fwd (backward-char)))
(user-error "Can't find %c" char)))))
(evil-define-motion evil-find-char-backward (count char)
"Move to the previous COUNT'th occurrence of CHAR."
:type exclusive
(interactive "<c><C>")
(evil-find-char (- (or count 1)) char))
(evil-define-motion evil-find-char-to (count char)
"Move before the next COUNT'th occurrence of CHAR."
:type inclusive
(interactive "<c><C>")
(unwind-protect
(progn
(evil-find-char count char)
(if (> (or count 1) 0)
(backward-char)
(forward-char)))
(setcar evil-last-find #'evil-find-char-to)))
(evil-define-motion evil-find-char-to-backward (count char)
"Move before the previous COUNT'th occurrence of CHAR."
:type exclusive
(interactive "<c><C>")
(evil-find-char-to (- (or count 1)) char))
(evil-define-motion evil-repeat-find-char (count)
"Repeat the last find COUNT times."
:type inclusive
(setq count (or count 1))
(if evil-last-find
(let ((cmd (car evil-last-find))
(char (nth 1 evil-last-find))
(fwd (nth 2 evil-last-find))
evil-last-find)
;; ensure count is non-negative
(when (< count 0)
(setq count (- count)
fwd (not fwd)))
;; skip next character when repeating t or T
(and (eq cmd #'evil-find-char-to)
evil-repeat-find-to-skip-next
(= count 1)
(or (and fwd (= (char-after (1+ (point))) char))
(and (not fwd) (= (char-before) char)))
(setq count (1+ count)))
(funcall cmd (if fwd count (- count)) char)
(unless (nth 2 evil-last-find)
(setq evil-this-type 'exclusive)))
(user-error "No previous search")))
(evil-define-motion evil-repeat-find-char-reverse (count)
"Repeat the last find COUNT times in the opposite direction."
:type inclusive
(evil-repeat-find-char (- (or count 1))))
;; ceci n'est pas une pipe
(evil-define-motion evil-goto-column (count)
"Go to column COUNT on the current line.
Columns are counted from zero."
:type exclusive
(move-to-column (or count 0)))
(evil-define-command evil-goto-mark (char &optional noerror)
"Go to the marker specified by CHAR."
:keep-visual t
:repeat nil
:type exclusive
:jump t
(interactive (list (read-char)))
(let ((marker (evil-get-marker char)))
(cond
((markerp marker)
(switch-to-buffer (marker-buffer marker))
(goto-char (marker-position marker)))
((numberp marker)
(goto-char marker))
((consp marker)
(when (or (find-buffer-visiting (car marker))
(and (y-or-n-p (format "Visit file %s again? "
(car marker)))
(find-file (car marker))))
(goto-char (cdr marker))))
((not noerror)
(user-error "Marker `%c' is not set%s" char
(if (evil-global-marker-p char) ""
" in this buffer"))))))
(evil-define-command evil-goto-mark-line (char &optional noerror)
"Go to the line of the marker specified by CHAR."
:keep-visual t
:repeat nil
:type line
:jump t
(interactive (list (read-char)))
(evil-goto-mark char noerror)
(evil-first-non-blank))
(evil-define-motion evil-jump-backward (count)
"Go to older position in jump list.
To go the other way, press \
\\<evil-motion-state-map>\\[evil-jump-forward]."
(evil--jump-backward count))
(evil-define-motion evil-jump-forward (count)
"Go to newer position in jump list.
To go the other way, press \
\\<evil-motion-state-map>\\[evil-jump-backward]."
(evil--jump-forward count))
(evil-define-motion evil-jump-backward-swap (count)
"Go to the previous position in jump list.
The current position is placed in the jump list."
(let ((pnt (point)))
(evil--jump-backward 1)
(evil-set-jump pnt)))
(defvar xref-prompt-for-identifier)
(evil-define-motion evil-jump-to-tag (arg)
"Jump to tag under point.
If called with a prefix argument, provide a prompt
for specifying the tag."
:jump t
(interactive "P")
(cond
((fboundp 'xref-find-definitions)
(let ((xref-prompt-for-identifier arg))
(call-interactively #'xref-find-definitions)))
((fboundp 'find-tag)
(if arg (call-interactively #'find-tag)
(let ((tag (funcall (or find-tag-default-function
(get major-mode 'find-tag-default-function)
#'find-tag-default))))
(unless tag (user-error "No tag candidate found around point"))
(find-tag tag))))))
(evil-define-motion evil-lookup ()
"Look up the keyword at point.
Calls `evil-lookup-func'."
(funcall evil-lookup-func))
(defun evil-ret-gen (count indent?)
(let* ((field (get-char-property (point) 'field))
(button (get-char-property (point) 'button))
(doc (get-char-property (point) 'widget-doc))
(widget (or field button doc)))
(cond
((and widget
(fboundp 'widget-type)
(fboundp 'widget-button-press)
(or (and (symbolp widget)
(get widget 'widget-type))
(and (consp widget)
(get (widget-type widget) 'widget-type))))
(when (evil-operator-state-p)
(setq evil-inhibit-operator t))
(when (fboundp 'widget-button-press)
(widget-button-press (point))))
((and (fboundp 'button-at)
(fboundp 'push-button)
(button-at (point)))
(when (evil-operator-state-p)
(setq evil-inhibit-operator t))
(push-button))
((or (evil-emacs-state-p)
(and (evil-insert-state-p)
(not buffer-read-only)))
(if (not indent?)
(newline count)
(delete-horizontal-space t)
(newline count)
(indent-according-to-mode)))
(t
(evil-next-line-first-non-blank count)))))
(evil-define-motion evil-ret (count)
"Move the cursor COUNT lines down.
If point is on a widget or a button, click on it.
In Insert state, insert a newline."
:type line
(evil-ret-gen count nil))
(evil-define-motion evil-ret-and-indent (count)
"Move the cursor COUNT lines down.
If point is on a widget or a button, click on it.
In Insert state, insert a newline and indent."
:type line
(evil-ret-gen count t))
(evil-define-motion evil-window-top (count)
"Move the cursor to line COUNT from the top of the window
on the first non-blank character."
:jump t
:type line
(move-to-window-line (max (or count 0)
(if (= (point-min) (window-start))
0
scroll-margin)))
(back-to-indentation))
(evil-define-motion evil-window-middle ()
"Move the cursor to the middle line in the window
on the first non-blank character."
:jump t
:type line
(move-to-window-line
(/ (1+ (save-excursion (move-to-window-line -1))) 2))
(back-to-indentation))
(evil-define-motion evil-window-bottom (count)
"Move the cursor to line COUNT from the bottom of the window
on the first non-blank character."