-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfixmee.el
1791 lines (1544 loc) · 74.7 KB
/
fixmee.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
;;; fixmee.el --- Quickly navigate to FIXME notices in code
;;
;; Copyright (c) 2012-2015 Roland Walker
;;
;; Author: Roland Walker <[email protected]>
;; Homepage: http://github.com/rolandwalker/fixmee
;; URL: http://raw.githubusercontent.com/rolandwalker/fixmee/master/fixmee.el
;; Version: 0.8.6
;; Last-Updated: 23 Feb 2015
;; EmacsWiki: FixmeeMode
;; Keywords: navigation, convenience
;; Package-Requires: ((button-lock "1.0.2") (nav-flash "1.0.0") (back-button "0.6.0") (smartrep "0.0.3") (string-utils "0.3.2") (tabulated-list "0"))
;;
;; Simplified BSD License
;;
;;; Commentary:
;;
;; Quickstart
;;
;; (require 'fixmee)
;;
;; (global-fixmee-mode 1)
;;
;; right-click on the word "fixme" in a comment
;;
;; ;; for `next-error' support
;; M-x fixmee-view-listing RET
;;
;; Explanation
;;
;; Fixmee-mode tracks "fixme" notices in code comments, highlights
;; them, ranks them by urgency, and lets you navigate to them quickly.
;;
;; A distinguishing feature of this library is that it tracks the
;; urgency of each notice, allowing the user to jump directly to
;; the most important problems.
;;
;; Urgency of "fixme" notices is indicated by repetitions of the final
;; character. For example, one might write "FIXMEEEEEEEEE" for an
;; important issue. The `fixmee-goto-nextmost-urgent' command will
;; navigate to the longest notice first.
;;
;; To use fixmee-mode, add the following to your ~/.emacs
;;
;; (require 'fixmee)
;; (global-fixmee-mode 1)
;;
;; Then, open some buffers and right-click on the word "fixme" in a
;; comment
;;
;; or press
;;
;; C-c f
;;
;; or
;;
;; M-x fixmee RET
;;
;; or
;;
;; roll the mouse wheel when hovering over the text "fixm"
;; in the modeline.
;;
;; or
;;
;; execute `fixmee-view-listing' to navigate using
;; `next-error' conventions.
;;
;; Key Bindings
;;
;; The default key bindings are
;;
;; C-c f `fixmee-goto-nextmost-urgent'
;; C-c F `fixmee-goto-prevmost-urgent'
;; C-c v `fixmee-view-listing'
;; M-n `fixmee-goto-next-by-position' ; only when the point is
;; M-p `fixmee-goto-previous-by-position' ; inside a "fixme" notice
;;
;; To constrain the nextmost/prevmost-urgent commands to the current
;; buffer only, use a universal prefix argument, eg
;;
;; C-u C-c f
;;
;; When the smartrep package is installed, the "C-c" prefix need not
;; be used for consecutive fixmee-mode keyboard commands. Instead,
;; just keep pressing "f" (or whichever key you set in customize).
;;
;; There is also a context menu and mouse-wheel bindings on the
;; minor-mode lighter in the modeline:
;;
;; mouse-1 context menu
;; wheel-down/up next/prev by urgency
;; M-wheel-down/up next/prev by position
;;
;; Patterns
;;
;; The following fixme patterns are supported by default:
;;
;; @@@
;; XXX ; only this one is case-sensitive
;; todo
;; fixme
;;
;; See Also
;;
;; M-x customize-group RET fixmee RET
;; M-x customize-group RET nav-flash RET
;;
;; Notes
;;
;; Currently, only open buffers are searched, not files or
;; projects.
;;
;; Compatibility and Requirements
;;
;; GNU Emacs version 24.5-devel : not tested
;; GNU Emacs version 24.4 : yes
;; GNU Emacs version 24.3 : yes
;; GNU Emacs version 23.3 : yes
;; GNU Emacs version 22.2 : yes, with some limitations
;; GNU Emacs version 21.x and lower : unknown
;;
;; Requires: button-lock.el
;; tabulated-list.el (included with Emacs 24.x)
;;
;; Uses if present: smartrep.el, nav-flash.el, back-button.el,
;; string-utils.el
;;
;; Bugs
;;
;; fixmee--listview-mode-map (the major-mode menu) does not work
;; well as a context menu.
;; - menu from major mode of selected window appears even when
;; right-clicking in this window
;; - mouse-event wrappers keep keyboard shortcuts from appearing
;; in menu-bar
;; - better to have a separate context menu attached to the
;; entries, using a keymap text property
;;
;; When comment-start is defined, only the first notice on a line
;; is lit up by button-lock, though fixmee-mode is aware of multiple
;; notices on a line. This is worked around for the moment by
;; stripping these cases from fixmee-notice-list. Better would be
;; to add comment-sensitivity logic to button-lock, and remove the
;; comment-matching section of the regexp passed to button-lock.
;;
;; Fixmee-maybe-turn-on gets called multiple times when a file
;; is loaded.
;;
;; Fixmee-buffer-include-functions may not contain the function
;; 'frame-bufs-associated-p, because a new buffer is not yet
;; associated with the frame at the time the global mode check
;; calls fixmee-maybe-turn-on.
;;
;; Bug in tabulated-list: position of point is not maintained
;; when sort headers are clicked while a different window is
;; selected.
;;
;; This package is generally incompatible with interactive modes
;; such as `comint-mode' and derivatives, due conflicting uses
;; of the rear-nonsticky text property. To change this, set
;; customizable variable fixmee-rear-nonsticky.
;;
;; TODO
;;
;; Push mark for navigation which happens from the listview
;;
;; There is no need for fixmee--listview-mode to be an interactive
;; command.
;;
;; Consider allowing all navigation commands to update the listview
;; buffer (currently only next-error commands do so)
;;
;; Display fully fontified context lines in listview buffer - some
;; lines have fontification, seemingly at random. Disabling
;; whitespace trimming and excluded properties had no effect.
;;
;; Multi-line context in listview buffer - tabulated-list accepts
;; newlines, but data then runs out of the column on the next
;; line. Would need to pad to match column position.
;;
;; Better feedback messages for end-of-list and start-of-list.
;;
;; Bookmark integration? (implicit bookmarking on notices).
;;
;; Wrap/cycle options on navigation-by-position.
;;
;; How to get last-command when user does M-x? (smex is not helping
;; here). (nth 0 command-history) ?
;;
;; Navigation can land on line near vertical edge of window -
;; should respect user settings and scroll in as needed for
;; context.
;;
;; Project support.
;;
;; Some kind of extra comment indicating a notice is to be ignored?
;; Lead with a backwhack?
;;
;;; License
;;
;; Simplified BSD License
;;
;; Redistribution and use in source and binary forms, with or
;; without modification, are permitted provided that the following
;; conditions are met:
;;
;; 1. Redistributions of source code must retain the above
;; copyright notice, this list of conditions and the following
;; disclaimer.
;;
;; 2. Redistributions in binary form must reproduce the above
;; copyright notice, this list of conditions and the following
;; disclaimer in the documentation and/or other materials
;; provided with the distribution.
;;
;; This software is provided by Roland Walker "AS IS" and any express
;; or implied warranties, including, but not limited to, the implied
;; warranties of merchantability and fitness for a particular
;; purpose are disclaimed. In no event shall Roland Walker or
;; contributors be liable for any direct, indirect, incidental,
;; special, exemplary, or consequential damages (including, but not
;; limited to, procurement of substitute goods or services; loss of
;; use, data, or profits; or business interruption) however caused
;; and on any theory of liability, whether in contract, strict
;; liability, or tort (including negligence or otherwise) arising in
;; any way out of the use of this software, even if advised of the
;; possibility of such damage.
;;
;; The views and conclusions contained in the software and
;; documentation are those of the authors and should not be
;; interpreted as representing official policies, either expressed
;; or implied, of Roland Walker.
;;
;;; Code:
;;
;;; requirements
;; for caddr, cadddr, incf, decf, callf, callf2, remove-if-not, position, intersection
(require 'cl)
(require 'nav-flash nil t)
(require 'back-button nil t)
(require 'smartrep nil t)
(require 'string-utils nil t)
(autoload 'button-lock-mode "button-lock" "Toggle button-lock-mode, a minor mode for making text clickable.")
(autoload 'button-lock-set-button "button-lock" "Attach mouse actions to text via `font-lock-mode'.")
(autoload 'tabulated-list-mode "tabulated-list" "Generic major mode for browsing a list of items.")
;;; declarations
(declare-function smartrep-define-key "smartrep.el")
(declare-function back-button-push-mark "back-button.el")
(declare-function back-button-push-mark-local-and-global "back-button.el")
(declare-function button-lock-unset-button "button-lock.el")
(declare-function button-lock-extend-binding "button-lock.el")
(declare-function button-lock-parent-modes "button-lock.el")
(declare-function string-utils-squeeze-filename "string-utils.el")
(declare-function string-utils-trim-whitespace "string-utils.el")
(declare-function tabulated-list-get-id "tabulated-list.el")
(declare-function tabulated-list-init-header "tabulated-list.el")
(declare-function tabulated-list-print "tabulated-list.el")
(declare-function tabulated-list-revert "tabulated-list.el")
(declare-function tabulated-list-print-entry "tabulated-list.el")
(eval-when-compile
(defvar tabulated-list-sort-key)
(defvar tabulated-list-format)
(defvar tabulated-list-padding)
(defvar tabulated-list-entries)
(defvar tabulated-list-printer)
(defvar button-lock-mode))
(unless (boundp 'special-mode-map)
;; backwards compat, needed for tabulated-list in Emacs 22
(defvar special-mode-map
(let ((map (make-sparse-keymap)))
(suppress-keymap map)
(define-key map "q" 'quit-window)
(define-key map " " 'scroll-up-command)
(define-key map "\C-?" 'scroll-down-command)
(define-key map "?" 'describe-mode)
(define-key map "h" 'describe-mode)
(define-key map ">" 'end-of-buffer)
(define-key map "<" 'beginning-of-buffer)
(define-key map "g" 'revert-buffer)
map)))
;;; customizable variables
;;;###autoload
(defgroup fixmee nil
"Navigate to \"fixme\" notices in code."
:version "0.8.6"
:link '(emacs-commentary-link :tag "Commentary" "fixmee")
:link '(url-link :tag "GitHub" "http://github.com/rolandwalker/fixmee")
:link '(url-link :tag "EmacsWiki" "http://emacswiki.org/emacs/FixmeeMode")
:prefix "fixmee-"
:group 'navigation
:group 'convenience)
(defcustom fixmee-notice-regexp "\\(@@@+\\|\\_<\\(?:[Tt][Oo][Dd][Oo]+\\|[Ff][Ii][Xx][Mm][Ee]+\\|XXX+\\)\\)\\(?:[/:?!. \t\r\n\f\v]+\\|-+\\(?:\\s-\\|[\r\n\f\v]\\)\\|\\_>\\)"
"Pattern for matching \"fixme\" notices.
There must be one parenthesized grouping which captures the
\"fixme\" text exactly. The captured text must be at minimum
three characters long.
The pattern will only be applied within comments for any mode
that defines comments in its syntax table."
:type 'regexp
:group 'fixmee)
(defcustom fixmee-mode-lighter " fixm"
"This string appears in the mode-line when `fixmee-mode' is active.
Set to nil or the empty string to disable the mode-line
lighter for `fixmee-mode'."
:type 'string
:group 'fixmee)
(put 'fixmee-mode-lighter 'risky-local-variable t)
(defcustom fixmee-less-feedback nil
"Give less echo area feedback."
:type 'boolean
:group 'fixmee)
(defcustom fixmee-cache-refresh-interval 60
"Force clearing of cached data after this many minutes.
To disable cache refresh, set this value to 0 or nil."
:type 'integer
:group 'fixmee)
(defcustom fixmee-push-mark t
"Whether to set the global mark before a series of `fixmee-mode' navigation commands.
When this option is set, `pop-global-mark' (typically bound to
C-x C-SPC) will return the cursor to the starting point after
a series of `fixmee-mode' navigation commands."
:type 'boolean
:group 'fixmee)
(defcustom fixmee-rear-nonsticky t
"Whether to set the 'rear-nonsticky property on fixmee buttons.
This value may be unset to stop `fixmee-mode' from attempting
to manage the 'rear-nonsticky text property, which may improve
compatibility with other modes that depend on setting the same
property (Example: ielm).
The default, t, is better for most users, because it keeps the
properties of the button from spuriously attaching to other
text."
:type 'boolean
:group 'fixmee)
(defface fixmee-notice-face
'((t (:inherit font-lock-warning-face)))
"Face to show \"fixme\" notices"
:group 'fixmee)
(defcustom fixmee-measure-urgency-function 'fixmee-measure-urgency
"Function used to calculate urgency ranking.
Function should accept a single string value, the match
value from `fixmee-notice-regexp', and return an
integer value.
The function must not change the match data."
:type 'function
:group 'fixmee)
;;;###autoload
(defgroup fixmee-global nil
"Settings for `global-fixmee-mode'."
:group 'fixmee)
(defcustom fixmee-exclude-modes '(
fundamental-mode
Buffer-menu-mode
bm-show-mode
dired-mode
wdired-mode
gnus-article-mode
mime/viewer-mode
rmail-mode
term-mode
comint-mode
shell-mode
eshell-mode
inferior-emacs-lisp-mode
fixmee--listview-mode
)
"Fixmee will not scan a buffer if its major mode is included in this list.
A buffer will also be excluded if its major mode is derived from a mode in
this list."
:type '(repeat symbol)
:group 'fixmee-global)
(defcustom fixmee-buffer-name-exclude-pattern "\\`[* ]"
"Fixmee will not scan a buffer if its name matches this regular expression.
The default pattern is designed to match buffers which are
programatically generated or internal to Emacs."
:type 'regexp
:group 'fixmee-global)
(defcustom fixmee-buffer-maximum-size 256000
"Fixmee will not scan a buffer if it is larger than this size.
The size is measured in characters.
Set the value to 0 to disable size limits."
:type 'integer
:group 'fixmee-global)
(defcustom fixmee-buffer-include-functions '(buffer-file-name)
"Fixmee will only scan buffers for which all functions evaluate to non-nil.
Each function should take a single argument (a buffer). The
default filter causes fixmee mode to consider only buffers which
are associated with a file.
Set this value to nil to disable."
:type '(repeat function)
:group 'fixmee-global)
(defcustom fixmee-buffer-exclude-functions '()
"Fixmee will not scan buffers for which any functions evaluate to non-nil.
Each function should take a single argument (a buffer).
Set this value to nil to disable."
:type '(repeat function)
:group 'fixmee-global)
;;;###autoload
(defgroup fixmee-keys nil
"Key bindings for `fixmee-mode'."
:group 'fixmee)
(defcustom fixmee-smartrep-prefix "C-c"
"Prefix key for smartrep.el bindings.
Smartrep bindings will be installed for all `fixmee-mode' key
bindings which match this prefix.
The format for key sequences is as defined by `kbd'.
Set to nil or the empty string to disable smartrep for
`fixmee-mode'."
:type 'string
:group 'fixmee-keys)
(defcustom fixmee-goto-nextmost-urgent-keystrokes '("C-c f")
"Key sequences to search for a \"fixme\" notice.
These keys are in effect whenever `fixmee-mode' is active in a
buffer.
These keys will navigate to the most urgent notice as
defined by length. If pressed multiple times in succession,
navigate to successively less-urgent notices.
Once any other command is used, `fixmee-mode' will forget your
place the list of notices and begin again at the most-urgent
notice.
Note that \"next\" here means next-by-urgency and not by
position.
The format for key sequences is as defined by `kbd'."
:type '(repeat string)
:group 'fixmee-keys)
(defcustom fixmee-goto-prevmost-urgent-keystrokes '("C-c F")
"Key sequences to search \"upward\" in the urgency ranking.
\"Upward\" means up in rankings, toward a more-urgent notice.
These keys are in effect whenever `fixmee-mode' is active in a
buffer.
These keys can only be used to back up after descending a series
of \"fixme\" notices via `fixmee-goto-nextmost-urgent-keystrokes'.
Once any other command is used, `fixmee-mode' will forget your
place the list of notices and begin again at the least-urgent
notice.
Note that \"previous\" here means previous-by-urgency and not
by position.
The format for key sequences is as defined by `kbd'."
:type '(repeat string)
:group 'fixmee-keys)
(defcustom fixmee-view-listing-keystrokes '("C-c v")
"Key sequences to run `fixmee-view-listing'.
The listview buffer displays all current \"fixme\" notices in a
sortable tabulated list, and provides `next-error' support.
These keys are in effect whenever `fixmee-global-mode' is active,
or when `fixmee-mode' is active in a buffer.
The format for key sequences is as defined by `kbd'."
:type '(repeat string)
:group 'fixmee-keys)
(defcustom fixmee-goto-next-by-position-keystrokes nil
"Key sequences to search forward in the same buffer for \"fixme\" notices.
These keys are in effect whenever `fixmee-mode' is active in a
buffer.
The format for key sequences is as defined by `kbd'."
:type '(repeat string)
:group 'fixmee-keys)
(defcustom fixmee-goto-previous-by-position-keystrokes nil
"Key sequences to search backward in the same buffer for \"fixme\" notices.
These keys are in effect whenever `fixmee-mode' is active in a
buffer.
The format for key sequences is as defined by `kbd'."
:type '(repeat string)
:group 'fixmee-keys)
(defcustom fixmee-within-notice-mouse-1-command nil
"Command bound to mouse-1 when clicking on \"fixme\" notices.
The format for key sequences is as defined by `kbd'."
:type 'function
:group 'fixmee-keys)
(defcustom fixmee-within-notice-mouse-2-command 'ignore
"Command bound to mouse-2 when clicking on \"fixme\" notices.
The format for key sequences is as defined by `kbd'."
:type 'function
:group 'fixmee-keys)
(defcustom fixmee-within-notice-down-mouse-3-command 'fixmee-notice-popup
"Command bound to down-mouse-3 when clicking on \"fixme\" notices.
The format for key sequences is as defined by `kbd'."
:type 'function
:group 'fixmee-keys)
(defcustom fixmee-within-notice-goto-next-by-position-keystrokes '("M-n")
"Key sequences to search forward in the same buffer for \"fixme\" notices.
These keys are only in effect when the point is inside a
\"fixme\" notice.
The format for key sequences is as defined by `kbd'."
:type '(repeat string)
:group 'fixmee-keys)
(defcustom fixmee-within-notice-goto-previous-by-position-keystrokes '("M-p")
"Key sequences to search backward in the same buffer for \"fixme\" notices.
These keys are only in effect when the point is inside a
\"fixme\" notice.
The format for key sequences is as defined by `kbd'."
:type '(repeat string)
:group 'fixmee-keys)
;;; variables
(defvar fixmee-mode nil "Mode variable for `fixmee-mode'.")
(make-variable-buffer-local 'fixmee-mode)
(defvar global-fixmee-mode nil
"Mode variable for `global-fixmee-mode'.")
(defvar fixmee-pristine-buffer-list nil
"List of buffers unmodified since the last execution of `fixmee-locate-all-notices'.")
(defvar fixmee-last-locate-state nil
"Status of all buffers at the last execution of `fixmee-locate-all-notices'.")
(defvar fixmee-last-good-hit nil
"The last successful `fixmee-mode' navigation.
Expressed as an element of `fixmee-notice-list'.")
(defvar fixmee-cache-refresh-timer nil
"A timer object for periodic cache invalidation.")
(defvar fixmee-notice-list nil
"Global list of \"fixme\" notices. Each element is a list (URGENCY BUFFER LOCATION-START LOCATION-END).")
(defvar fixmee-keyboard-navigation-commands '(
fixmee-goto-prevmost-urgent
fixmee-goto-nextmost-urgent
fixmee-goto-previous-by-position
fixmee-goto-next-by-position
)
"List of interactive keyboard navigation commands.")
(defvar fixmee-mouse-navigation-commands '(
fixmee-mouse-goto-nextmost-urgent
fixmee-mouse-goto-prevmost-urgent
fixmee-mouse-goto-next-by-position
fixmee-mouse-goto-previous-by-position
)
"List of interactive mouse navigation commands.")
(defvar fixmee-all-navigation-commands (append '(fixmee) ; alias for fixmee-goto-nextmost-urgent
fixmee-keyboard-navigation-commands
fixmee-mouse-navigation-commands)
"List of interactive navigation commands.")
(defvar fixmee-global-commands '(fixmee-view-listing)
"List of globally available commands.")
(defvar fixmee-button nil
"Buffer-local variable holding the `button-lock' button for \"fixme\" notices.")
(make-variable-buffer-local 'fixmee-button)
(defvar fixmee-lighter-menu-mouse-button 1
"Which mouse button invokes the modeline context menu.")
(defvar fixmee-lighter-keymap-property 'keymap
"Which property sets the lighter keymap.")
;; fixmee--listview variables
(defvar fixmee--listview-mode nil "Mode variable for `fixmee--listview-mode'.")
(make-variable-buffer-local 'fixmee--listview-mode)
(defvar fixmee--listview-buffer-name "*fixmee notices*"
"The name of the buffer used to show a listview of all \"fixme\" notices.")
(defvar fixmee--listview-arrow-id nil
"The `tabulated-list-mode' id associated with the overlay arrow.")
(make-variable-buffer-local 'fixmee--listview-arrow-id)
(defvar fixmee--listview-find-notice-hook nil
"Hook to run when viewing a notice from a `fixmee--listview-mode' buffer.")
(defvar fixmee--listview-line-format '[("Buffer" 35 fixmee--listview-name-sorter)
("Urgency" 10 fixmee--listview-urgency-sorter)
("Context" 80 fixmee--listview-context-sorter)]
"Tabulated list format for `fixmee--listview-mode' buffers.")
(defvar fixmee--listview-excluded-properties '(
category
field
follow-link
fontified
help-echo
intangible
invisible
keymap
local-map
mouse-face
read-only
yank-handler
)
"Properties removed from text before display in `fixmee--listview-mode' buffers.")
(defvar fixmee--listview-local-only nil
"If non-nil, `fixmee--listview-mode' shows notices from the current buffer only.")
(make-variable-buffer-local 'fixmee--listview-local-only)
;;; compatibility functions
(unless (fboundp 'string-match-p)
;; added in 23.x
(defun string-match-p (regexp string &optional start)
"Same as `string-match' except this function does not change the match data."
(let ((inhibit-changing-match-data t))
(string-match regexp string start))))
(unless (fboundp 'back-button-push-mark-local-and-global)
(fset 'back-button-push-mark (symbol-function 'push-mark))
(defun back-button-push-mark-local-and-global (&optional location nomsg activate consecutives)
"Push mark at LOCATION, and unconditionally add to `global-mark-ring'.
This function differs from `push-mark' in that `global-mark-ring'
is always updated.
LOCATION is optional, and defaults to the current point.
NOMSG and ACTIVATE are as documented at `push-mark'.
When CONSECUTIVES is set to 'limit and the new mark is in the same
buffer as the first entry in `global-mark-ring', the first entry
in `global-mark-ring' will be replaced. Otherwise, a new entry
is pushed onto `global-mark-ring'.
When CONSECUTIVES is set to 'allow-dupes, it is possible to push
an exact duplicate of the current topmost mark onto `global-mark-ring'."
(callf or location (point))
(back-button-push-mark location nomsg activate)
(when (or (eq consecutives 'allow-dupes)
(not (equal (mark-marker)
(car global-mark-ring))))
(when (and (eq consecutives 'limit)
(eq (marker-buffer (car global-mark-ring)) (current-buffer)))
(move-marker (car global-mark-ring) nil)
(pop global-mark-ring))
(push (copy-marker (mark-marker)) global-mark-ring)
(when (> (length global-mark-ring) global-mark-ring-max)
(move-marker (car (nthcdr global-mark-ring-max global-mark-ring)) nil)
(setcdr (nthcdr (1- global-mark-ring-max) global-mark-ring) nil)))))
(unless (fboundp 'string-utils-trim-whitespace)
(defun string-utils-trim-whitespace (str-val &optional whitespace-type multi-line)
"Return STR-VAL with leading and trailing whitespace removed.
WHITESPACE-TYPE is ignored.
If optional MULTI-LINE is set, trim spaces at starts and
ends of all lines throughout STR-VAL."
(let* ((string-utils-whitespace " \t\n\r\f")
(whitespace-regexp (concat "[" string-utils-whitespace "]"))
(start-pat (if multi-line "^" "\\`"))
(end-pat (if multi-line "$" "\\'")))
(save-match-data
(replace-regexp-in-string (concat start-pat whitespace-regexp "+") ""
(replace-regexp-in-string (concat whitespace-regexp "+" end-pat) ""
str-val))))))
;;; keymaps
(defvar fixmee-mode-map (make-sparse-keymap) "Keymap for `fixmee-mode' minor-mode.")
(defvar fixmee-mode-global-map (make-sparse-keymap) "Keymap for `global-fixmee-mode' global minor-mode.")
(let ((smart-keys nil))
(dolist (cmd fixmee-keyboard-navigation-commands)
(dolist (k (symbol-value (intern (concat (symbol-name cmd) "-keystrokes"))))
(when (and (not (string-match-p "mouse\\|wheel\\|button" k))
(not (get cmd :advertised-binding)))
(put cmd :advertised-binding (read-kbd-macro k)))
(if (and (featurep 'smartrep)
(stringp fixmee-smartrep-prefix)
(> (length fixmee-smartrep-prefix) 0)
(string-match-p (concat "\\`" fixmee-smartrep-prefix "\\>") k))
(push (cons (replace-regexp-in-string
(concat "\\`" fixmee-smartrep-prefix "\\>[ \t]*")
""
k)
cmd)
smart-keys)
;; else
(define-key fixmee-mode-map (read-kbd-macro k) cmd))))
(when smart-keys
(smartrep-define-key fixmee-mode-map fixmee-smartrep-prefix smart-keys)))
(dolist (cmd fixmee-global-commands)
(dolist (k (symbol-value (intern (concat (symbol-name cmd) "-keystrokes"))))
(when (and (not (string-match-p "mouse\\|wheel\\|button" k))
(not (get cmd :advertised-binding)))
(put cmd :advertised-binding (read-kbd-macro k)))
(define-key fixmee-mode-map (read-kbd-macro k) cmd)
(define-key fixmee-mode-global-map (read-kbd-macro k) cmd)))
(defvar fixmee--listview-mode-map
(let ((map (make-sparse-keymap))
(menu-map (make-sparse-keymap "Fixmee Listview")))
(define-key map (kbd "<mouse-2>") 'fixmee-listview-mouse-goto-notice)
(define-key map (kbd "C-c C-c" ) 'fixmee-listview-goto-notice)
(define-key map (kbd "<return>" ) 'fixmee-listview-goto-notice)
(define-key map (kbd "<SPC>" ) 'fixmee-listview-view-notice)
(define-key map (kbd "v" ) 'fixmee-listview-view-notice)
(define-key map (kbd "l" ) 'fixmee-listview-toggle-local-only)
(define-key map (kbd "n" ) 'next-error-no-select)
(define-key map (kbd "p" ) 'previous-error-no-select)
(define-key map (kbd "<tab>" ) 'next-error-no-select)
(define-key map (kbd "<backtab>") 'previous-error-no-select)
(define-key map (kbd "M-n" ) 'next-error-no-select)
(define-key map (kbd "M-p" ) 'previous-error-no-select)
(define-key map (kbd "C-c C-f" ) 'next-error-follow-minor-mode)
(define-key map (kbd "q" ) 'quit-window)
(define-key map (kbd "Q" ) 'fixmee-listview-quit)
(define-key map (kbd "{" ) 'fixmee-listview-previous-buffer)
(define-key map (kbd "}" ) 'fixmee-listview-next-buffer)
(define-key map (kbd "M-{" ) 'fixmee-listview-previous-buffer)
(define-key map (kbd "M-}" ) 'fixmee-listview-next-buffer)
(define-key menu-map [customize] '(menu-item "Customize" (lambda (e) (interactive "e") (customize-group 'fixmee))))
(define-key menu-map [quit-listview] '(menu-item "Quit Listview" fixmee-listview-quit))
(define-key menu-map [separator-1] '(menu-item "--"))
(define-key menu-map [follow-mode] '(menu-item "Follow Mode" next-error-follow-minor-mode
:button (:toggle . next-error-follow-minor-mode)))
(define-key menu-map [toggle-local-only] '(menu-item "Local Notices Only" fixmee-listview-toggle-local-only
:button (:toggle . fixmee--listview-local-only)))
(define-key menu-map [separator-2] '(menu-item "--"))
(define-key menu-map [previous-buffer] '(menu-item "Previous Buffer" (lambda (e)
(interactive "e")
(ignore-errors (posn-set-point (event-end last-nonmenu-event)))
(fixmee-listview-previous-buffer))))
(define-key menu-map [next-buffer] '(menu-item "Next Buffer" (lambda (e)
(interactive "e")
(ignore-errors (posn-set-point (event-end last-nonmenu-event)))
(fixmee-listview-next-buffer))))
(define-key menu-map [previous-notice] '(menu-item "Previous Notice" (lambda (e)
(interactive "e")
(ignore-errors (posn-set-point (event-end last-nonmenu-event)))
(previous-error-no-select))))
(define-key menu-map [next-notice] '(menu-item "Next Notice" (lambda (e)
(interactive "e")
(ignore-errors (posn-set-point (event-end last-nonmenu-event)))
(next-error-no-select))))
(define-key menu-map [separator-3] '(menu-item "--"))
(define-key menu-map [goto-notice] '(menu-item "Goto Notice" (lambda (e)
(interactive "e")
(ignore-errors (posn-set-point (event-end last-nonmenu-event)))
(fixmee-listview-goto-notice))))
(define-key menu-map [view-notice] '(menu-item "View Notice" (lambda (e)
(interactive "e")
(ignore-errors (posn-set-point (event-end last-nonmenu-event)))
(fixmee-listview-view-notice))))
(define-key map [menu-bar fixmee-listview] (cons "Fixmee Listview" menu-map))
map)
"Keymap for `fixmee--listview-mode' buffers.")
(put 'fixmee-listview-goto-notice :advertised-binding (kbd "<return>"))
(put 'fixmee-listview-view-notice :advertised-binding (kbd "<SPC>"))
;;; lighter
(defvar fixmee-lighter-map (let ((map (make-sparse-keymap))
(menu-map (make-sparse-keymap "Fixmee Mode")))
(define-key menu-map [customize] '(menu-item "Customize" (lambda (e) (interactive "e") (customize-group 'fixmee))))
(define-key menu-map [turn-off-fixmee-mode] '(menu-item "Turn Off Fixmee Mode" fixmee-mode))
(define-key menu-map [separator-2] '(menu-item "--"))
(define-key menu-map [fixmee-view-listing] '(menu-item "View Listing of Notices" fixmee-view-listing))
(define-key menu-map [separator-1] '(menu-item "--"))
(define-key menu-map [fixmee-goto-previous-by-position] (append '(menu-item "Previous Fixme By Position" fixmee-goto-previous-by-position)
;; force :keys because of smartrep
(when (get 'fixmee-goto-previous-by-position :advertised-binding)
(list :keys
(format-kbd-macro
(get 'fixmee-goto-previous-by-position :advertised-binding))))))
(define-key menu-map [fixmee-goto-next-by-position] (append '(menu-item "Next Fixme By Position" fixmee-goto-next-by-position)
(when (get 'fixmee-goto-next-by-position :advertised-binding)
(list :keys
(format-kbd-macro
(get 'fixmee-goto-next-by-position :advertised-binding))))))
(define-key menu-map [fixmee-goto-prevmost-urgent] (append '(menu-item "Previous Fixme By Urgency" fixmee-goto-prevmost-urgent)
(when (get 'fixmee-goto-prevmost-urgent :advertised-binding)
(list :keys
(format-kbd-macro
(get 'fixmee-goto-prevmost-urgent :advertised-binding))))))
(define-key menu-map [fixmee-goto-nextmost-urgent] (append '(menu-item "Next Fixme By Urgency" fixmee-goto-nextmost-urgent)
(when (get 'fixmee-goto-nextmost-urgent :advertised-binding)
(list :keys
(format-kbd-macro
(get 'fixmee-goto-nextmost-urgent :advertised-binding))))))
(define-key map (kbd "<mode-line> <wheel-up>" ) 'fixmee-goto-prevmost-urgent)
(define-key map (kbd "<mode-line> <wheel-down>" ) 'fixmee-goto-nextmost-urgent)
(define-key map (kbd "<mode-line> <M-wheel-up>" ) 'fixmee-goto-previous-by-position)
(define-key map (kbd "<mode-line> <M-wheel-down>" ) 'fixmee-goto-next-by-position)
(define-key map (kbd "<mode-line> <mouse-4>" ) 'fixmee-goto-prevmost-urgent)
(define-key map (kbd "<mode-line> <mouse-5>" ) 'fixmee-goto-nextmost-urgent)
(define-key map (kbd "<mode-line> <M-mouse-4>" ) 'fixmee-goto-previous-by-position)
(define-key map (kbd "<mode-line> <M-mouse-5>" ) 'fixmee-goto-next-by-position)
(define-key map (read-kbd-macro (format "<mode-line> <down-mouse-%s>" fixmee-lighter-menu-mouse-button)) menu-map)
map) "Keymap for the `fixmee-mode' lighter.")
(when (and (stringp fixmee-mode-lighter)
(> (length fixmee-mode-lighter) 0))
(callf propertize fixmee-mode-lighter
fixmee-lighter-keymap-property fixmee-lighter-map
'help-echo (format "fixmee-mode: mouse-%s menu\nwheel down/up by urgency\nwheel M-down/M-up by position." fixmee-lighter-menu-mouse-button)))
;;; aliases and fsets
;;;###autoload
(defalias 'fixmee 'fixmee-goto-nextmost-urgent)
;;; macros
(defmacro fixmee-called-interactively-p (&optional kind)
"A backward-compatible version of `called-interactively-p'.
Optional KIND is as documented at `called-interactively-p'
in GNU Emacs 24.1 or higher."
(cond
((not (fboundp 'called-interactively-p))
'(interactive-p))
((condition-case nil
(progn (called-interactively-p 'any) t)
(error nil))
`(called-interactively-p ,kind))
(t
'(called-interactively-p))))
;;; utility functions
;; general functions
(defun fixmee-refresh-timer-setup (&optional arg)
"Set up a timer to invalidate caches.
When optional ARG is less than 0, turn off timer.
This should help cover up various minor bugs, such as not
invalidating the cache when the regexp is changed."
(when (timerp fixmee-cache-refresh-timer)
(cancel-timer fixmee-cache-refresh-timer)
(setq fixmee-cache-refresh-timer nil))
(unless (and (numberp arg)
(< arg 0))
(when fixmee-cache-refresh-interval
(let ((secs (truncate (* 60 fixmee-cache-refresh-interval))))
(when (> secs 0)
(setq fixmee-cache-refresh-timer (run-with-timer secs secs 'fixmee-cache-invalidate)))))))
(defun fixmee-cache-invalidate ()
"Delete all cached data."
(setq fixmee-last-locate-state nil)
(setq fixmee-notice-list nil)
(setq fixmee-pristine-buffer-list nil))
;; buffer functions
(defun fixmee-get-buffer-state () ;; optimization
"Return a data structure we can use to test if buffers have changed."
(list (sort
(remove-if-not #'(lambda (buf)
(buffer-local-value 'fixmee-mode buf)) (buffer-list))
#'(lambda (a b) (string< (buffer-name a) (buffer-name b))))
fixmee-pristine-buffer-list))
(defun fixmee-this-buffer-not-pristine-hook (&rest _ignored)
"Add BUFFER to the list modified since the last search for \"fixme\" notices."
(remove-hook 'after-change-functions 'fixmee-this-buffer-not-pristine-hook t)
(setq fixmee-last-locate-state nil)
(callf2 delq (current-buffer) fixmee-pristine-buffer-list))
(defun fixmee-buffer-included-p (buf)
"Return BUF if BUF should be scanned for \"fixme\" notices."
(when (and (not noninteractive)
(bufferp buf)
(buffer-name buf))
(with-current-buffer buf
(when (and (not (minibufferp buf))
(not (eq (aref (buffer-name) 0) ?\s)) ; overlaps with exclude-pattern
(not (memq major-mode fixmee-exclude-modes))
(not (intersection (button-lock-parent-modes) fixmee-exclude-modes))
(not (string-match-p fixmee-buffer-name-exclude-pattern (buffer-name buf)))
(or (not (numberp fixmee-buffer-maximum-size))
(= 0 fixmee-buffer-maximum-size)
(<= (point-max) fixmee-buffer-maximum-size))
(catch 'success
(dolist (filt fixmee-buffer-exclude-functions)
(when (funcall filt buf)
(throw 'success nil)))
t)
(catch 'failure
(dolist (filt fixmee-buffer-include-functions)
(unless (funcall filt buf)
(throw 'failure nil)))
t))
buf))))
;; functions that operate on or produce notices
(defun fixmee-measure-urgency (str-val)
"Counts how many times the trailing character is repeated on STR-VAL.
Returns an integer, minimum of 1. Case-insensitive. The first two
characters of STR-VAL are always ignored."
(let ((tailchar (downcase (aref str-val (1- (length str-val)))))
(counter 1))
(while (and (< counter (- (length str-val) 2))
(eq tailchar (downcase (aref str-val (- (length str-val) (1+ counter))))))
(incf counter))
counter))
(defun fixmee-sort-notice-list ()
"Sort `fixmee-notice-list' by urgency."
(callf sort fixmee-notice-list #'(lambda (a b)
(cond
((not (= (car a) (car b)))
(> (car a) (car b)))
((not (eq (nth 1 a) (nth 1 b)))
(string< (buffer-name (nth 1 a)) (buffer-name (nth 1 b))))
(t
(< (nth 2 a) (nth 2 b)))))))
(defun fixmee-notices-from-pristine-buffers () ;; optimization
"Return the subset of `fixmee-notice-list' elements found in pristine buffers."
(remove-if-not #'(lambda (hit)
(and (buffer-name (cadr hit))
(memq (cadr hit) fixmee-pristine-buffer-list)))
fixmee-notice-list))
(defun fixmee-notices-from-current-buffer ()
"Return the subset of `fixmee-notice-list' elements found in the current buffer."
(remove-if-not #'(lambda (hit)
(eq (cadr hit) (current-buffer)))