-
Notifications
You must be signed in to change notification settings - Fork 3
/
eev-blinks.el
1928 lines (1620 loc) · 73.8 KB
/
eev-blinks.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
;;; eev-blinks.el -- support for basic hyperlinks in Emacs. -*- lexical-binding: nil; -*-
;; The basic hyperlinks are the ones that do not depend on templates,
;; and that are not created by `code-c-d' and friends.
;; Copyright (C) 1999-2024 Free Software Foundation, Inc.
;;
;; This file is part of GNU eev.
;;
;; GNU eev 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.
;;
;; GNU eev 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;
;; Author: Eduardo Ochs <[email protected]>
;; Maintainer: Eduardo Ochs <[email protected]>
;; Version: 20241017
;; Keywords: e-scripts
;;
;; Latest version: <http://anggtwu.net/eev-current/eev-blinks.el>
;; htmlized: <http://anggtwu.net/eev-current/eev-blinks.el.html>
;; See also: <http://anggtwu.net/eev-current/eev-beginner.el.html>
;; <http://anggtwu.net/eev-intros/find-eev-intro.html>
;; (find-eev-intro)
;;; Commentary:
;; For the general notion of elisp hyperlinks, see:
;; (find-eev-quick-intro "3. Elisp hyperlinks")
;; For what are "basic elisp hyperlinks", see:
;; (find-links-conv-intro "3. Classification")
;; (find-links-conv-intro "3. Classification" "non-basic")
;; «.eek» (to "eek")
;; «.ee-goto-position» (to "ee-goto-position")
;; «.ee-goto-rest» (to "ee-goto-rest")
;; «.curved-single-quotes» (to "curved-single-quotes")
;; «.find-fline» (to "find-fline")
;; «.find-wottb» (to "find-wottb")
;; «.find-dbsw» (to "find-dbsw")
;; «.find-epackages» (to "find-epackages")
;; «.find-efaces» (to "find-efaces")
;; «.find-eregionpp» (to "find-eregionpp")
;; «.find-eoverlayspp» (to "find-eoverlayspp")
;; «.find-ebuffercontents» (to "find-ebuffercontents")
;; «.find-ebufferandpos» (to "find-ebufferandpos")
;; «.find-ebuffer» (to "find-ebuffer")
;; «.find-eoutput» (to "find-eoutput")
;; «.find-estring» (to "find-estring")
;; «.find-epropertize» (to "find-epropertize")
;; «.find-ehashtable» (to "find-ehashtable")
;; «.find-estruct» (to "find-estruct")
;; «.find-sh» (to "find-sh")
;; «.find-man» (to "find-man")
;; «.find-man-bug» (to "find-man-bug")
;; «.find-w3m» (to "find-w3m")
;; «.find-eww» (to "find-eww")
;; «.find-Package» (to "find-Package")
;; «.find-epp» (to "find-epp")
;; «.find-efunctionpp» (to "find-efunctionpp")
;; «.find-eloadhistory» (to "find-eloadhistory")
;; «.find-eloadhistory-for» (to "find-eloadhistory-for")
;; «.find-lgreps» (to "find-lgreps")
;; «.find-einternals» (to "find-einternals")
;; «.find-einsert» (to "find-einsert")
;; «.find-eunicode» (to "find-eunicode")
;; «.ee-symbol-function» (to "ee-symbol-function")
;; «.find-eejumps» (to "find-eejumps")
;; «.find-eeshortdefs» (to "find-eeshortdefs")
;; «.find-eaproposf» (to "find-eaproposf")
(defvar ee-buffer-name nil) ; overridden by `let's
;; (find-efunction 'ee-find-tag)
;;; _ _ _
;;; __ _ _ _| |_ ___ | | ___ __ _ __| |___
;;; / _` | | | | __/ _ \| |/ _ \ / _` |/ _` / __|
;;; | (_| | |_| | || (_) | | (_) | (_| | (_| \__ \
;;; \__,_|\__,_|\__\___/|_|\___/ \__,_|\__,_|___/
;;;
;;; autoloads for external functions
;; (find-elnode "Autoload")
;;
(autoload 'find-function-read "find-func")
(autoload 'pp-to-string "pp")
(autoload 'Man-translate-references "man")
(autoload 'Man-fontify-manpage "man" nil t)
(autoload 'word-at-point "thingatpt")
(autoload 'list-iso-charset-chars "mule-diag")
(autoload 'list-non-iso-charset-chars "mule-diag")
(autoload 'customize-read-group "cus-edit")
(autoload 'custom-unlispify-tag-name "cus-edit")
;;; _
;;; ___ ___| | __
;;; / _ \/ _ \ |/ /
;;; | __/ __/ <
;;; \___|\___|_|\_\
;;;
;; «eek» (to ".eek")
;; See: (find-eev-quick-intro "3. Elisp hyperlinks" "eek")
;; (find-efunctiondescr 'edmacro-mode)
;; (find-ekbmacro-links)
(defun eek (str)
"Execute STR as a keyboard macro. See `edmacro-mode' for the exact format.\n
An example: (eek \"C-x 4 C-h\")"
(interactive "sKeys: ")
(execute-kbd-macro (read-kbd-macro str)))
(defun find-eek (str &rest pos-spec-list)
(eek str)
(apply 'ee-goto-position pos-spec-list))
;;; _ _ _
;;; _ __ ___ ___ ___ _ __ ___ ___ | (_)___| |_ ___
;;; | '_ \ / _ \/ __| ___ / __| '_ \ / _ \/ __|___| | / __| __/ __|
;;; | |_) | (_) \__ \|___|\__ \ |_) | __/ (__|___| | \__ \ |_\__ \
;;; | .__/ \___/|___/ |___/ .__/ \___|\___| |_|_|___/\__|___/
;;; |_| |_|
;;;
;; «ee-goto-position» (to ".ee-goto-position")
;; Support for pos-spec-lists in hyperlinks.
;; See: (find-refining-intro "1. Pos-spec-lists")
;; (find-refining-intro "2. Refining hyperlinks")
(defun ee-goto-position (&optional pos-spec &rest rest)
"Process the \"absolute pos-spec-lists\" arguments in hyperlink functions.
POS-SPEC, the first element of a pos-spec-list, is treated
specially; if it is a string then jump to the first occurrence of
that string in the buffer, and if it a number jump to the line
with that number in the buffer; if it is nil, do nothing.
The rest of the pos-spec-list, REST, is treated by
`ee-goto-rest'.
Many kinds of hyperlinks - for example,
(find-efunction 'ee-goto-position)
already jump to specific positions of a buffer; those hyperlink
functions support \"relative pos-spec-lists\", and they invoke
`ee-goto-rest' straight away to handle their pos-spec-lists -
they skip the first \"absolute\" pos-spec."
(when pos-spec
(cond ((numberp pos-spec)
(goto-char (point-min))
(forward-line (1- pos-spec)))
((stringp pos-spec)
(goto-char (save-excursion ; This used to be just:
(goto-char (point-min)) ; (goto-char (point-min))
(search-forward pos-spec) ; (search-forward pos-spec)
(point)))) ;
((eq pos-spec :end)
(goto-char (point-max)))
(t (error "This is not a valid pos-spec: %S" pos-spec)))
(if rest (ee-goto-rest rest))))
;; «ee-goto-rest» (to ".ee-goto-rest")
;; See: (find-refining-intro "1. Pos-spec-lists")
;;
(defun ee-goto-rest (list)
"Process \"relative pos-spec-lists\".
For each element in LIST, if it is:
a string -> jump to the next occurrence of that string in the
current buffer
a number -> go down that many lines
a list -> evaluate the list (take care!)
anything else generates an error - but users are encouraged to
create their own extended versions of this function and override
the standard definition."
(cond ((null list))
((stringp (car list))
(search-forward (car list))
(ee-goto-rest (cdr list)))
((numberp (car list))
(forward-line (car list))
(ee-goto-rest (cdr list)))
((consp (car list))
(eval (car list))
(ee-goto-rest (cdr list)))
(t (error "Not a valid pos-spec item: %S" (car list)))))
;; «curved-single-quotes» (to ".curved-single-quotes")
;; In some situations Emacs converts "`foo'"s to "‘foo’"s, or
;; vice-versa, in info pages and docstrings; see:
;;
;; (find-elnode "Keys in Documentation" "User Option: text-quoting-style")
;; (find-elnode "Text Quoting Style" "User Option: text-quoting-style")
;; (find-elnode "Text Quoting Style" "curved single quotes")
;; (find-elnode "Text Quoting Style" "grave accent and apostrophe")
;; (find-efunction 'eejump "find-eejumps")
;; (find-efunctiondescr 'eejump "find-eejumps")
;;
;; Eev doesn't have a way to convert strings in pos-spec-lists between
;; these styles yet; at this moment `ee-goto-position' and
;; `ee-goto-rest' do the simplest thing possible - they search for
;; their string arguments literally with `search-forward'.
;;; __ _ _ __ _ _
;;; / _(_)_ __ __| | / _| (_)_ __ ___
;;; | |_| | '_ \ / _` |_____| |_| | | '_ \ / _ \
;;; | _| | | | | (_| |_____| _| | | | | | __/
;;; |_| |_|_| |_|\__,_| |_| |_|_|_| |_|\___|
;;; __ _ _ _
;;; / _(_)_ __ __| | _ __ ___ __| | ___
;;; | |_| | '_ \ / _` |_____| '_ \ / _ \ / _` |/ _ \
;;; | _| | | | | (_| |_____| | | | (_) | (_| | __/
;;; |_| |_|_| |_|\__,_| |_| |_|\___/ \__,_|\___|
;;;
;; «find-fline» (to ".find-fline")
;; Basic links: `find-fline' and `find-node'.
;; See: (find-eev-quick-intro "3. Elisp hyperlinks")
;; (find-eev-quick-intro "9.2. Extra arguments to `code-c-d'" ":gz")
(defun find-fline (fname &rest pos-spec-list)
"Hyperlink to a file (or a directory).
This function is similar to `find-file' but it supports a
\"pos-spec-list\" - see `ee-goto-position'.
Examples:\n
(find-file \"~/.emacs\")
(find-fline \"~/.emacs\")
(find-fline \"~/.emacs\" \"Beginning of the eev block\")"
(find-file (ee-expand fname))
(apply 'ee-goto-position pos-spec-list))
(defun find-fline-gz (fname &rest pos-spec-list)
"Like `find-fline', but also tries \"FNAME.gz\" if \"FNAME\" does not exist."
(let* ((efname (ee-expand fname))
(efnamegz (concat efname ".gz")))
(if (and (not (file-exists-p efname))
(file-exists-p efnamegz))
(apply 'find-fline efnamegz pos-spec-list)
(apply 'find-fline efname pos-spec-list))))
(defun find-node (nodestr &rest pos-spec-list)
"Hyperlink to an info page.
This function is similar to `info' but it supports a
\"pos-spec-list\" - see `ee-goto-position'.
Examples:\n
(info \"(emacs)Lisp Eval\")
(find-node \"(emacs)Lisp Eval\" \"C-x C-e\")"
(info nodestr)
(ee-goto-rest pos-spec-list))
;;; __ _ _ _ _ _
;;; / _(_)_ __ __| | __ _____ | |_| |_| |__
;;; | |_| | '_ \ / _` |____\ \ /\ / / _ \| __| __| '_ \
;;; | _| | | | | (_| |_____\ V V / (_) | |_| |_| |_) |
;;; |_| |_|_| |_|\__,_| \_/\_/ \___/ \__|\__|_.__/
;;;
;; «find-wottb» (to ".find-wottb")
;; Hyperlinks to the output of Emacs's help-like functions.
(defun find-wottb-call (sexp bufname &rest pos-spec-list)
"Hyperlink to functions that call `with-output-to-temp-buffer'.
First evaluate SEXP with a trick to not let it split the current window,
then switch to the buffer that it created (it must be called BUFNAME),
then go to the position specified by POS-SPEC-LIST.\n
\(This is a horrible hack.)"
(let ((same-window-buffer-names
(cons bufname same-window-buffer-names)))
(eval sexp))
(set-buffer bufname) ; why is this needed?
(apply 'ee-goto-position pos-spec-list))
;; Tests: (find-eapropos "regexp")
;; (find-eapropos "^find-.*-links" "find-intro-links")
;;
(defun find-eapropos (regexp &rest pos-spec-list)
"Hyperlink to the result of running `apropos' on REGEXP."
(interactive "sApropos symbol (regexp): ")
(apply 'find-wottb-call '(apropos regexp) "*Apropos*" pos-spec-list))
;; Tests: (find-efunctiondescr 'find-file)
;; (find-efunctiondescr 'next-line "line-move-visual")
;;
(defun find-efunctiondescr (symbol &rest pos-spec-list)
"Hyperlink to the result of running `describe-function' on SYMBOL."
(interactive (find-function-read))
(apply 'find-wottb-call '(describe-function symbol) "*Help*" pos-spec-list))
;; Tests: (find-evardescr 'default-directory)
;; (find-evariabledescr 'line-move-visual "visual lines")
;;
(defun find-evariabledescr (symbol &rest pos-spec-list)
"Hyperlink to the result of running `describe-variable' on SYMBOL."
(interactive (find-function-read 'variable))
(apply 'find-wottb-call '(describe-variable symbol) "*Help*" pos-spec-list))
(defalias 'find-evardescr 'find-evariabledescr)
;; Tests: (find-ekeydescr "\M-h\M-h")
;; (find-ekeydescr [down] "line-move-visual")
;;
(defun find-ekeydescr (key &rest pos-spec-list)
"Hyperlink to the result of running `describe-key' on KEY."
(interactive "kFind function on key: ")
(apply 'find-wottb-call '(describe-key key) "*Help*" pos-spec-list))
;; Tests: (find-efunctiond 'find-file)
;; (find-efunctiond 'next-line "next-line-add-newlines")
;;
(defun find-efunctiond (function &rest pos-spec-list)
"Hyperlink to the result of running `disassemble' on FUNCTION."
(interactive (find-function-read))
(apply 'find-wottb-call '(disassemble function) "*Disassemble*"
pos-spec-list))
;; Tests: (find-customizegroup 'processes)
;; (find-customizeoption 'fill-column)
;; (find-customizevariable 'fill-column)
;; (find-customizeapropos "subed")
;; (find-customizeface 'font-lock-comment-face)
;;
(defun find-customizegroup (group &rest pos-spec-list)
"Hyperlink to the result of running `customize-group' on GROUP."
(interactive (list (customize-read-group)))
(when (stringp group)
(if (string-equal "" group)
(setq group 'emacs)
(setq group (intern group))))
(apply 'find-wottb-call '(customize-group group)
(format "*Customize Group: %s*" (custom-unlispify-tag-name group))
pos-spec-list))
(defun find-customizeoption (symbol &rest rest)
"Hyperlink to the result of running `customize-option' on SYMBOL."
(interactive (custom-variable-prompt))
(apply 'find-dbsw-call `(customize-option ',symbol) rest))
(defun find-customizevariable (symbol &rest rest)
"Hyperlink to the result of running `customize-variable' on SYMBOL."
(interactive (custom-variable-prompt))
(apply 'find-dbsw-call `(customize-variable ',symbol) rest))
(defun find-customizeapropos (pattern &optional type &rest rest)
"Hyperlink to the result of running `customize-apropos' on PATTERN."
(interactive (list (apropos-read-pattern "symbol") nil))
(apply 'find-dbsw-call `(customize-apropos pattern type) rest))
(defun find-customizeface (face &rest rest)
"Hyperlink to the result of running `customize-face' on PATTERN."
(interactive (list (read-face-name
"Customize face"
(or (face-at-point t t) "all faces") t)))
(apply 'find-dbsw-call `(customize-face face) rest))
;; Tests: (find-epackages nil "\n 0x0 ")
;; (find-epackages t "\n 0x0 ")
;;
(defun find-epackages0 (&optional no-fetch &rest pos-spec-list)
"Hyperlink to the output of `list-packages'.
This is similar to `find-epackages', but it is much simpler and
far less convenient. The suffix `0' means \"low-level\"."
(interactive "P")
(apply 'find-wottb-call '(list-packages no-fetch)
"*Packages*" pos-spec-list))
;; Test: (find-epackage '0x0)
;; Note: `M-x find-epackage' currently doesn't work well.
;; See: (find-elnode "Interactive Codes" "S" "An interned symbol")
;; (find-elnode "Index" "* read-no-blanks-input:")
;;
(defun find-epackage (&optional pkg-desc &rest pos-spec-list)
"Hyperlink to the output of `describe-package'."
;; (interactive "Spackage name: ")
(interactive (list (intern (read-no-blanks-input "Package name: " ""))))
(apply 'find-wottb-call '(describe-package pkg-desc)
"*Help*" pos-spec-list))
;; Test: (find-eshortdoc 'keymaps)
;; See: (find-efunction 'shortdoc-display-group)
;; TODO: (autoload 'shortdoc-display-group "shortdoc")
;; TODO: make the autoload work in the interactive clause.
;;
(defun find-eshortdoc (group &rest rest)
"Hyperlink to the output of `shortdoc-display-group'."
(interactive (list (completing-read "Show summary for functions in: "
(mapcar #'car shortdoc--groups))))
(require 'shortdoc)
(apply 'find-dbsw-call `(shortdoc-display-group ',group) rest))
;;; __ _ _ _ _
;;; / _(_)_ __ __| | __| | |__ _____ __
;;; | |_| | '_ \ / _` |_____ / _` | '_ \/ __\ \ /\ / /
;;; | _| | | | | (_| |_____| (_| | |_) \__ \\ V V /
;;; |_| |_|_| |_|\__,_| \__,_|_.__/|___/ \_/\_/
;;;
;; «find-dbsw» (to ".find-dbsw")
;; See: https://lists.gnu.org/archive/html/help-gnu-emacs/2022-03/msg00354.html
;; Thanks to Emanuel Berg for help with this!
;;
(defun find-dbsw-call (sexp &rest pos-spec-list)
"Run SEXP in \"display-buffer-same-window mode\" and go to POS-SPEC-LIST.
This is similar to `find-wottb-call' but uses another method to
force using the same window. This is an experimental hack and may
change soon."
(let ((display-buffer-overriding-action '(display-buffer-same-window)))
(eval sexp))
(apply 'ee-goto-position pos-spec-list))
;;; __ _ _ _
;;; / _(_)_ __ __| | ___ _ __ __ _ ___| | ____ _ __ _ ___ ___
;;; | |_| | '_ \ / _` |_____ / _ \ '_ \ / _` |/ __| |/ / _` |/ _` |/ _ \/ __|
;;; | _| | | | | (_| |_____| __/ |_) | (_| | (__| < (_| | (_| | __/\__ \
;;; |_| |_|_| |_|\__,_| \___| .__/ \__,_|\___|_|\_\__,_|\__, |\___||___/
;;; |_| |___/
;;
;; «find-epackages» (to ".find-epackages")
;; Tests: (find-epackages)
;; (find-epackages 'eev)
(defun find-epackages (&rest pos-spec-list)
"Hyperlink to the output of `list-packages'.
This is similar to `find-epackages0', but uses these three hacks:
1. if a buffer called \"*Packages*\" exists, just switch to it,
2. if it doesn't exist, create it with (list-packages 'no-fetch),
3. use `ee-goto-position-package' instead of `ee-goto-position'."
(interactive "P")
(if (get-buffer "*Packages*")
(find-ebuffer "*Packages*")
(find-wottb-call
'(list-packages 'no-fetch)
"*Packages*"))
(apply 'ee-goto-position-package pos-spec-list))
(defun ee-goto-position-package (&optional pkgsymbol &rest rest)
"Like `ee-goto-position', but treats PKGSYMBOL as a package name.
This is an internal function used by `find-epackages'."
(if (and pkgsymbol (symbolp pkgsymbol))
(let ((nline (ee-packages-nline-for pkgsymbol)))
(if (not nline) (error "Package not found"))
(apply 'ee-goto-position nline rest))
(apply 'ee-goto-position pkgsymbol rest)))
(defun ee-packages-nline-for (pkgsymbol &optional nns)
"This is an internal function that only works in the *Packages* buffer."
(car (reverse (ee-packages-nlines-for pkgsymbol nns))))
(defun ee-packages-nlines-for (pkgsymbol &optional nns)
"This is an internal function that only works in the *Packages* buffer."
(setq nns (or nns (ee-packages-nlines-and-names)))
(cl-loop for (nline name) in nns
if (eq name pkgsymbol)
collect nline))
(defun ee-packages-nlines-and-names (&optional tles)
"This is an internal function that only works in the *Packages* buffer."
(cl-loop for nline from 1
for cols in (or tles tabulated-list-entries)
collect (list nline (package-desc-name (car cols)))))
;;; __
;;; / _| __ _ ___ ___ ___
;;; | |_ / _` |/ __/ _ \/ __|
;;; | _| (_| | (_| __/\__ \
;;; |_| \__,_|\___\___||___/
;;;
;; «find-efaces» (to ".find-efaces")
;; Inspect faces, colors and characters.
;; Most of these use `find-wottb-call'.
;; Tests:
;; (find-ecolors " white")
;; (find-efaces 'eepitch-star-face "abcd")
;; (find-efaces "\neepitch-star-face " "abcd")
;; (find-efacedescr 'default "Foreground:")
;;
;; Key bindings:
;; (find-eev "eev-mode.el" "eev-mode-map-set")
;; (find-eev "eev-mode.el" "eev-mode-map-set" "M-h" "M-c" "find-echardescr")
;; (find-eev "eev-mode.el" "eev-mode-map-set" "M-h" "M-s" "find-eface-links")
;; (find-eev "eev-mode.el" "eev-mode-map-set" "M-h" "M-t" "find-etpat")
;; (find-eev "eev-mode.el" "eev-mode-map-set" "M-h" "t" "find-etpat0")
;; (find-eev "eev-mode.el" "eev-mode-map-set" "M-h" "c" "find-ecolor-links")
;; (find-enode "International Chars" "C-u C-x =" "describe-char")
(defun find-echardescr (&optional pos &rest pos-spec-list)
"Hyperlink to the result of running `describe-char' at POS."
(interactive)
(setq pos (or pos (point)))
(apply 'find-wottb-call '(describe-char pos) "*Help*" pos-spec-list))
(defun find-ecolors (&rest pos-spec-list)
"Hyperlink to the result of running `list-colors-display'."
(interactive)
(apply 'find-wottb-call '(list-colors-display) "*Colors*" pos-spec-list))
;; See:
;; (find-eev "eev-elinks.el" "find-eface-links")
;; (find-eev "eev-elinks.el" "find-eface-links" "find-efacedescr")
;;
(defun find-efacedescr (&optional face &rest pos-spec-list)
"Hyperlink to the result of running `describe-face' on FACE.
When called interactively use `ee-face-at-point' to select the
FACE. See the documentation for `ee-face-at-point' for the
details of how it works."
(interactive (list (ee-face-at-point current-prefix-arg)))
(apply 'find-wottb-call '(describe-face face) "*Help*" pos-spec-list))
(defun find-efaces (&rest pos-spec-list)
"Hyperlink to the result of running `list-faces-display'."
(interactive)
(apply 'find-wottb-call '(list-faces-display)
"*Faces*" (ee-find-efaces-hack pos-spec-list)))
(defun ee-find-efaces-hack (pos-spec-list)
"An internal function used by `find-efaces'."
(let* ((face (car pos-spec-list))
(rest (cdr pos-spec-list)))
(if (and face (symbolp face)) ; if pos-spec-list starts with a symbol:
(cons (format "\n%s " face) rest) ; convert it to a string in the right way
pos-spec-list))) ; otherwise return pos-spec-list unchanged
(defun find-etpat (&optional pos &rest pos-spec-list)
"Hyperlink to the result of running `describe-text-properties' at point.
See `find-etpat0' and `find-etpat00' for lower-level tools for
inspecting text proprties."
(interactive)
(setq pos (or pos (point)))
(apply 'find-dbsw-call '(describe-text-properties pos)
pos-spec-list))
(defun find-etpat0 (&rest pos-spec-list)
"Hyperlink to a pretty version of the result of (text-properties-at (point))."
(interactive)
(let* ((ee-buffer-name
(or ee-buffer-name "*(text-properties-at (point))*")))
(apply 'find-epp (text-properties-at (point)) pos-spec-list)))
(defun find-etpat00 ()
"Show the result of (text-properties-at (point)) in the echo area."
(interactive)
(find-epp0 (text-properties-at (point))))
(defalias 'find-etp 'find-etpat)
;;; __ _ _ _
;;; / _(_)_ __ __| | ___ _ __ ___ __ _(_) ___ _ __ _ __ _ __
;;; | |_| | '_ \ / _` |_____ / _ \ '__/ _ \/ _` | |/ _ \| '_ \| '_ \| '_ \
;;; | _| | | | | (_| |_____| __/ | | __/ (_| | | (_) | | | | |_) | |_) |
;;; |_| |_|_| |_|\__,_| \___|_| \___|\__, |_|\___/|_| |_| .__/| .__/
;;; |___/ |_| |_|
;;
;; «find-eregionpp» (to ".find-eregionpp")
;; The functions `find-etpat', `find-etpat0' and `find-etpat00'
;; defined above can be used to the examine the text properties of
;; characters in a buffer; `find-eregionpp' can be used to examine all
;; text properties in a region.
;; Test:
;; (eek "2*<down> C-a C-SPC <down> C-x 1 C-x 3 C-x o <<find-eregionpp>>")
;;
(defun find-eregionpp (b e &optional arg)
"Show the text properties of the text in the region.
This function pretty-prints the result of `(buffer-substring B
E)' and shows the result in a temporary buffer; B and E are the
extremities of the region. The argument ARG is passed to
`ee-eregionpp-preprocess', that uses it to decide which text
properties to omit."
(interactive "r\nP")
(let* ((ee-buffer-name (or ee-buffer-name "*(find-eregionpp)*"))
(str (buffer-substring b e))
(intervals0 (ee-string-intervals str))
(intervals (ee-eregionpp-preprocess intervals0 arg)))
(find-epp intervals)))
;; See: https://lists.gnu.org/archive/html/help-gnu-emacs/2022-10/msg00729.html
;; https://lists.gnu.org/archive/html/help-gnu-emacs/2022-10/msg00745.html
(defun ee-string-intervals (str)
"This is similar to `object-intervals', but uses another output format."
(cl-loop for (b e props) in (object-intervals str)
for s = (substring-no-properties str b e)
for pairs = (cl-loop for (x y) on props by 'cddr
collect (list x y))
collect (cons s (ee-sort-pairs pairs))))
(defun ee-symbol< (symbol1 symbol2)
(string< (symbol-name symbol1) (symbol-name symbol2)))
;; Tests: (find-eppp global-minor-modes)
;; (find-eppp (ee-sort-symbols global-minor-modes))
(defun ee-sort-symbols (symbols)
(sort symbols 'ee-symbol<))
(defun ee-sort-pairs (pairs)
"Sort a list of PAIRS of the the form (symbol value)."
(let ((pair< (lambda (pair1 pair2)
(string< (symbol-name (car pair1))
(symbol-name (car pair2))))))
(sort pairs pair<)))
;; This is a stub!
(defun ee-eregionpp-preprocess (intervals0 arg)
"Redefine this if you want ways to omit certain properties."
intervals0)
;; Test:
;; (eek "2*<down> C-a C-SPC <down> C-x 1 C-x 3 C-x o <<find-eregionpp0>>")
;;
(defun find-eregionpp0 (b e &optional use-print-circle)
"Show the text properties of the text in the region.
This function pretty-prints the result of `(buffer-substring B
E)' and shows the result in a temporary buffer; B and E are the
extremities of the region. If this function is called with a
numeric argument, as in `C-u M-x find-eregionpp0', then the
pretty-printer is run with the flag `print-circle' turned on, and
this makes the pretty-printer display copies of shared subobjects
using a more compact notation. See:
(find-elnode \"Circular Objects\")"
(interactive "r\nP")
(let ((ee-buffer-name (or ee-buffer-name "*(find-eregionpp0)*"))
(print-circle use-print-circle))
(find-epp (buffer-substring b e))))
;; «find-eoverlayspp» (to ".find-eoverlayspp")
(defun find-eoverlayspp ()
"Show the overlays at point."
(interactive)
(find-epp (mapcar 'ee-overlay-pp0 (overlays-at (point) 'sorted))))
(defun ee-overlay-pp0 (ovl)
(let* ((props (overlay-properties ovl)))
(cons ovl (cl-loop for (a b) on props by 'cddr
collect (list a b)))))
;; «find-ebuffercontents» (to ".find-ebuffercontents")
;; One way to inspect text properties in buffers with weird keymaps is
;; to copy the contents of these buffers to other buffers that are in
;; fundamental mode, then edit the copy to leave only the parts that
;; we want to inspect, and then use `find-eregionpp'.
;; Tests:
;; (find-wset "1_3o_o" nil '(find-ebuffercontents))
;; (find-wset "1_3o_o" '(find-eevfile "") '(find-ebuffercontents))
;;
(defun find-ebuffercontents (&optional b &rest pos-spec-list)
"Show a copy of `(ee-buffer-contents B)' in a buffer in fundamental mode.
This function does not copy overlays.
BUG: at this moment invisible text is not copied. I need to fix that!!!"
(interactive (list (current-buffer)))
(let ((ee-buffer-name (or ee-buffer-name "*(find-ebuffercontents)*")))
(apply 'find-estring (ee-buffer-contents b) pos-spec-list)))
(defun ee-buffer-contents (&optional b)
"Like `ee-buffer-contents0', but uses the current buffer if B is nil.
If B neither nil nor an existing buffer this function returns the
empty string instead of throwing an error."
(setq b (or b (current-buffer)))
(if (get-buffer b) (ee-buffer-contents0 b) ""))
(defun ee-buffer-contents0 (b)
"Return the contents of the buffer B.
B must be a buffer or the name of an existing buffer. If the
buffer B is narrowed this function returns only its accessible
portion."
(with-current-buffer b
(buffer-substring (point-min) (point-max))))
;;; __ _ _ __ _ _
;;; / _(_)_ __ __| | ___ / _|_ _ _ __ ___| |_(_) ___ _ __
;;; | |_| | '_ \ / _` |____ / _ \ |_| | | | '_ \ / __| __| |/ _ \| '_ \
;;; | _| | | | | (_| |____| __/ _| |_| | | | | (__| |_| | (_) | | | |
;;; |_| |_|_| |_|\__,_| \___|_| \__,_|_| |_|\___|\__|_|\___/|_| |_|
;;;
;; «find-ebufferandpos» (to ".find-ebufferandpos")
;; Hyperlinks to the source code of Emacs functions and variables.
;; Tests:
;; (find-efunction 'next-line)
;; (find-evariable 'line-move-visual)
(defun find-ebufferandpos (buffer-and-pos &rest pos-spec-list)
"Internal use; hyperlink to a \"buffer and pos\" structure.
Emacs has some standard (i.e., non-eev) functions that can be
used as hyperlinks, like `find-function' and `find-variable';
they call internal functions like `find-function-noselect' and
`find-variable-noselect', that return structures of the form
BUFFER-AND-POS, that are conses like (#<buffer foo> . 42). This
function jumps to the position described by a cons like that, and
then processes an optional relative POS-SPEC-LIST using
`ee-goto-rest'.
Functions like `find-efunction' and `find-evariable' (defined in
eev.el) are wrappers around `find-function' and `find-variable'
that add support for a relative pos-spec-list after the symbol."
(if (not (bufferp (car buffer-and-pos)))
(error "Bad (BUFFER . POS): %S" buffer-and-pos))
(switch-to-buffer (car buffer-and-pos))
(goto-char (cdr buffer-and-pos))
(ee-goto-rest pos-spec-list))
(defun find-efunction (symbol &rest pos-spec-list)
"Hyperlink to the result of running `find-function' on SYMBOL.
The `find-function' function of Emacs can be used as a hyperlink
- it finds the Elisp source code of SYMBOL -, but it doesn't
support a POS-SPEC-LIST like this function does."
(interactive (find-function-read))
(apply 'find-ebufferandpos (find-function-noselect symbol) pos-spec-list))
(defun find-ealias (symbol &rest pos-spec-list)
"Like `find-efunction', but do not resolve aliases to functions.
See: https://lists.gnu.org/archive/html/help-gnu-emacs/2022-01/msg00323.html"
(interactive (find-function-read))
(apply 'find-ebufferandpos
(find-function-search-for-symbol
symbol nil (symbol-file symbol 'defun))
pos-spec-list))
(defun find-evariable (symbol &rest pos-spec-list)
"Hyperlink to the result of running `find-variable' on SYMBOL."
(interactive (find-function-read 'variable))
(apply 'find-ebufferandpos (find-variable-noselect symbol) pos-spec-list))
(defun find-eface (face &rest pos-spec-list)
"Hyperlink to the result of running `find-face-definition' on FACE.
The `find-face-definition' function of Emacs can be used as a hyperlink
- it finds the Elisp source code of SYMBOL -, but it doesn't
support a POS-SPEC-LIST like this function does."
(interactive (find-function-read 'defface))
(apply 'find-ebufferandpos (find-definition-noselect face 'defface)
pos-spec-list))
;;; __ _ _ _ __ __
;;; / _(_)_ __ __| | ___| |__ _ _ / _|/ _| ___ _ __
;;; | |_| | '_ \ / _` |_____ / _ \ '_ \| | | | |_| |_ / _ \ '__|
;;; | _| | | | | (_| |_____| __/ |_) | |_| | _| _| __/ |
;;; |_| |_|_| |_|\__,_| \___|_.__/ \__,_|_| |_| \___|_|
;;;
;; «find-ebuffer» (to ".find-ebuffer")
;; Hyperlinks to buffers
;; Tests:
;; (find-ebuffer "*Messages*")
(defun find-ebuffer (buffer &rest pos-spec-list)
"Hyperlink to an Emacs buffer (existing or not)."
(interactive "bBuffer: ")
(switch-to-buffer buffer)
(apply 'ee-goto-position pos-spec-list))
;;; __ _ _ _ _
;;; / _(_)_ __ __| | ___ ___ _ _| |_ _ __ _ _| |_
;;; | |_| | '_ \ / _` |_____ / _ \/ _ \| | | | __| '_ \| | | | __|
;;; | _| | | | | (_| |_____| __/ (_) | |_| | |_| |_) | |_| | |_
;;; |_| |_|_| |_|\__,_| \___|\___/ \__,_|\__| .__/ \__,_|\__|
;;; |_|
;; «find-eoutput» (to ".find-eoutput")
;; Tests:
;; (find-estring "a\nb\nc\n")
;; (find-estring-elisp "(dotimes (i 10) (insert \"\\na\"))")
(defun find-eoutput-rerun (buffer-name code &rest pos-spec-list)
"Hyperlink to the effect of running CODE in Emacs.
If the buffer BUFFER-NAME does not exist then create it and run
CODE in it. If the buffer already exists, then \"run CODE
again\" (compare with `find-output-reuse'): delete the buffer,
recreate it, and run CODE in it.\n
For simplicity we are deleting the buffer and then recreating it,
but it could be better to just delete the buffer's contents. This
needs to be thought out."
(if (get-buffer buffer-name) ; if the buffer exists
(if (not (kill-buffer buffer-name)) ; try to kill it; confirm if needed
(error "Not killing the buffer %s" buffer-name)))
(switch-to-buffer buffer-name) ; create the buffer
(eval code) ; always run CODE on the empty buffer
(goto-char (point-min))
(apply 'ee-goto-position pos-spec-list))
(defun find-eoutput-reuse (buffer-name code &rest pos-spec-list)
"Hyperlink to the effect of running CODE in Emacs.
If the buffer BUFFER-NAME does not exist then create it and run
CODE in it. If the buffer already exists, then \"reuse
it\" (compare with `find-output-rerun'): switch to it, ignore the
CODE argument, and process the POS-SPEC-LIST."
(if (get-buffer buffer-name) ; if the buffer exists
(switch-to-buffer buffer-name) ; then just switch to it
(switch-to-buffer buffer-name) ; otherwise switch to it and
(eval code) ; run CODE to produce its contents
(goto-char (point-min)))
(apply 'ee-goto-position pos-spec-list))
;; «find-estring» (to ".find-estring")
;; Tests: (find-2a nil '(find-estring ";; Foo\n(+ 1 2)\n"))
;; (find-2a nil '(find-estring-elisp ";; Foo\n(+ 1 2)\n"))
;; (find-estring-2a ";; Foo\n(+ 1 2)\n")
;;
(defun find-estring (string &rest pos-spec-list)
"Visit a temporary buffer whose contents are given by STR.
The default name for the buffer is \"*string*\", but this can be
overridden by setting `ee-buffer-name' to another name with a
`let'. If the buffer already exists its contents are destroyed.
The buffer is not made read-only."
(apply 'find-eoutput-rerun (or ee-buffer-name "*string*")
`(insert ,string) pos-spec-list))
(defun find-estring-elisp (string &rest pos-spec-list)
"Visit a temporary buffer whose contents are given by STR.
This function is similar to `find-estring', but this one also
runs `emacs-lisp-mode' in the buffer."
(apply 'find-eoutput-rerun (or ee-buffer-name "*string*")
`(progn (insert ,string) (emacs-lisp-mode)) pos-spec-list))
(defun find-estring-2a (str &rest pos-spec-list)
"Show STR in the window at the right."
(find-2a nil `(find-estring str ,@pos-spec-list)))
;;; __ _ _ _ _
;;; / _(_)_ __ __| | ___ _ __ _ __ ___ _ __ ___ _ __| |_(_)_______
;;; | |_| | '_ \ / _` |_____ / _ \ '_ \| '__/ _ \| '_ \ / _ \ '__| __| |_ / _ \
;;; | _| | | | | (_| |_____| __/ |_) | | | (_) | |_) | __/ | | |_| |/ / __/
;;; |_| |_|_| |_|\__,_| \___| .__/|_| \___/| .__/ \___|_| \__|_/___\___|
;;; |_| |_|
;;
;; «find-epropertize» (to ".find-epropertize")
;; See:
;; (find-elnode "Special Properties" "face")
;; (find-elnode "Special Properties" "mouse-face")
;; (find-elnode "Special Properties" "keymap")
;;
;; Tests:
;; (find-epropertize '(face (:foreground "red")))
;; (find-epropertize '(face (:foreground "yellow" :background "red")))
;; (find-epropertize '(face (:background "red")))
;; (find-epropertize '(face font-lock-comment-face))
;; (find-epropertize '(mouse-face highlight))
;;
;; (setq ee-fep-keymap (make-sparse-keymap))
;; (define-key ee-fep-keymap (kbd "C-c C-c") 'next-line)
;; (find-epropertize-2b `(keymap ,ee-fep-keymap))
;; (find-epropertize-2b `(keymap ,ee-fep-keymap mouse-face highlight))
;;
(defun ee-epropertize (textproperties)
"And internal function used by `find-epropertize'."
(concat (apply 'propertize "Some text" textproperties) "\n\n"))
(defun find-epropertize (textproperties)
"Show a string with TEXTPROPERTIES at the window at the right.
TEXTPROPERTIES is a list of the form (prop1 value1 prop2 value2 ...)."
(find-2a nil `(find-estring ,(ee-epropertize textproperties) 3)))
(defun find-epropertize-2b (textproperties)
"Show a string with TEXTPROPERTIES at the window at the right.
TEXTPROPERTIES is a list of the form (prop1 value1 prop2 value2 ...).
This is a variant of `find-epropertize' that switches to the window at
the right."
(find-2b nil `(find-estring ,(ee-epropertize textproperties) 3)))
;; TODO: Delete this.
;; This is an ugly hack.
;; It was created for: (find-efunction 'find-anchors-intro)
;; It was made obsolete by: (find-eev "eev-codings.el")
(defun ee-raw-text-unix ()
"Set the current buffer to unibyte (for certain glyphs).
See: (find-anchors-intro \"WARNING: some glyphs need raw-text-unix\")"
(interactive)
(set-buffer-file-coding-system 'raw-text-unix 'force)
(set-buffer-multibyte nil))
(defun find-estring-lv (string &rest pos-spec-list)
"Visit a temporary buffer whose contents are given by STR.
The default name for the buffer is \"*string*\", but this can be
overridden by setting `ee-buffer-name' to another name with a `let'.
If the buffer already exists its contents are destroyed.
The buffer is not made read-only.
The \"Local variables:\" section in the buffer is processed."
(apply 'find-eoutput-rerun (or ee-buffer-name "*string*")
`(progn (ee-raw-text-unix)
(insert ,string)
(hack-local-variables))
pos-spec-list))
;;; _ _ _ _ _
;;; | |__ __ _ ___| |__ | |_ __ _| |__ | | ___ ___
;;; | '_ \ / _` / __| '_ \ | __/ _` | '_ \| |/ _ \/ __|
;;; | | | | (_| \__ \ | | | | || (_| | |_) | | __/\__ \
;;; |_| |_|\__,_|___/_| |_| \__\__,_|_.__/|_|\___||___/
;;;
;; Test: (cl-defstruct mypoint x y)
;; (setq myp (make-mypoint :x 3 :y 4))
;; (ee-struct-index-table myp)
;; (ee-hashtable-to-string nil (ee-struct-index-table myp))
;; (find-ehashtable (ee-struct-index-table myp))
;;
;; See also: (find-epackage-links 'ht)
;; «find-ehashtable» (to ".find-ehashtable")
(defun ee-hashtable-to-string (f hashtable)
"Apply F to each key-value pair of HASHTABLE, and return a big string.
The function F should be a function that expects three arguments
- the key, the value, and the hashtable - and returns either a
line terminated by a newline or an empty string. The lines
returned by F are collected in a list, then sorted, and then the
duplicates are removed; the result after that is concatenated
into a big string, and returned. The key-value pairs for which F
returned an empty string disappear in the concatenation.
If F is nil then use a default function.
I often refer to strings that may have, and usually do have,
newlines, as \"big strings\". This function returns a \"big string\"."
(setq f (or f (lambda (k v h) (format "%S -> %S\n" k v))))
(let ((lines (cl-loop for k being the hash-keys of hashtable
collect (funcall f k (gethash k hashtable) hashtable))))
(apply 'concat (seq-uniq (sort lines 'string<)))))
(defun find-ehashtable (hashtable &rest pos-spec-list)
(apply 'find-estring (ee-hashtable-to-string nil hashtable) pos-spec-list))
;;; __ _ _ _ _
;;; / _(_)_ __ __| | ___ ___| |_ _ __ _ _ ___| |_
;;; | |_| | '_ \ / _` |_____ / _ \/ __| __| '__| | | |/ __| __|
;;; | _| | | | | (_| |_____| __/\__ \ |_| | | |_| | (__| |_
;;; |_| |_|_| |_|\__,_| \___||___/\__|_| \__,_|\___|\__|
;;;
;; «find-estruct» (to ".find-estruct")
;; Hyperlinks that display human-readable versions of structures
;; created with cl-defstruct. To understand how this works, try this:
;;
;; (cl-defstruct mytriple a b c)
;; (make-mytriple :a 22 :c "44")
;; (find-estruct (make-mytriple :a 22 :c "44"))
;;
;; The second sexp returns this:
;;
;; #s(mytriple 22 nil "44")
;;
;; that is difficult to read because it doesn't show the field names.
;; The `find-estruct' sexp above converts that to a multi-line
;; representation that shows the slot numbers and the field names.
;;
;; See: (find-clnode "Structures")
;; (find-clnode "Structures" "cl-defstruct")