-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheconf-world-wide-web.html
More file actions
867 lines (765 loc) · 59.6 KB
/
econf-world-wide-web.html
File metadata and controls
867 lines (765 loc) · 59.6 KB
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
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2022-W11-4 02:13 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Econf World Wide Web</title>
<meta name="author" content="Inanna" />
<meta name="description" content="Search engine configuration for emacs." />
<meta name="generator" content="Org Mode" />
<link href="/site.css" rel="stylesheet" type="text/css" /><link href="images/website-icon.png" rel="icon" />
</head>
<body>
<div id="preamble" class="status">
<div><a href="/index.html"><img alt="An abstract logo representing a series of three assembly line stamping machines with the words CONS, DEV, and embalzoned in white on each machine." id="site-logo" src="/images/website-logo.png" /></a></div>
</div>
<div id="content" class="content">
<h1 class="title">Econf World Wide Web</h1>
<div id="table-of-contents" role="doc-toc">
<h2>Table of Contents</h2>
<div id="text-table-of-contents" role="doc-toc">
<ul>
<li><a href="#org1ef63b2">Introduction</a></li>
<li><a href="#orgc42ce1b">Dependencies</a></li>
<li><a href="#orgc718fed">Variables</a>
<ul>
<li><a href="#org0731e08">Setting Browsers (and stuff)</a></li>
<li><a href="#orgbc13e59">The w3m Directory</a></li>
<li><a href="#org265bd39">Further Customizations</a></li>
</ul>
</li>
<li><a href="#orgf35fe44">Playing Videos Without JS</a>
<ul>
<li><a href="#org5e82b87">Playing Videos</a>
<ul>
<li><a href="#orgfe43b78">ec-w3m-view-video</a></li>
<li><a href="#orgd7e5920">ec-w3m-video-url?</a></li>
</ul>
</li>
<li><a href="#org16ba1da">Redefining Some Functions</a>
<ul>
<li><a href="#org277da4a">w3m-goto-url-new-session-or-video</a></li>
<li><a href="#orgacb60e0">w3m-view-this-url</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#org7ae1998">Search Engine Suggestions</a>
<ul>
<li><a href="#org095cb11">Variables</a></li>
<li><a href="#org754a402">Functions</a>
<ul>
<li><a href="#org570c782">ec-ddg-suggest-fetch</a></li>
<li><a href="#org8065f1e">ec-ddg-get-suggestions</a></li>
<li><a href="#orgcf8270d">ec-wikipedia-suggest-fetch</a></li>
<li><a href="#org35c4529">ec-get-region</a></li>
<li><a href="#org1058cc2">ec-ddg-search-interactive-arg</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#org43834e1">Saving Stuff</a>
<ul>
<li><a href="#orgfd7d5ee">ec-clone-website</a></li>
<li><a href="#org1ba01a8">ec-download-video</a></li>
</ul>
</li>
<li><a href="#orgea90481">User Interface</a>
<ul>
<li><a href="#org488f526">Buffer Names</a></li>
<li><a href="#orgb09a41e">Hydra Interface</a></li>
<li><a href="#org9bd4500">Binding Keys</a></li>
<li><a href="#orgabbc565">Browser Functions</a></li>
<li><a href="#orge2ab771">Ace Link</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div id="outline-container-org1ef63b2" class="outline-2">
<h2 id="org1ef63b2">Introduction</h2>
<div class="outline-text-2" id="text-org1ef63b2">
<p>
This is some fo the code I use for search engine stuff in Emacs.
</p>
</div>
</div>
<div id="outline-container-orgc42ce1b" class="outline-2">
<h2 id="orgc42ce1b">Dependencies</h2>
<div class="outline-text-2" id="text-orgc42ce1b">
<table id="orgf03f817" border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
</colgroup>
<thead>
<tr>
<th scope="col" class="org-left">Dependency</th>
<th scope="col" class="org-left">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left"><a href="https://github.com/tkf/emacs-request">request</a></td>
<td class="org-left">A popular library for making requests in Emacs Lisp.</td>
</tr>
<tr>
<td class="org-left"><a href="https://emacs-w3m.github.io/">w3m</a></td>
<td class="org-left">A wrapper around the w3m web browser that exits for Emacs.</td>
</tr>
<tr>
<td class="org-left"><a href="https://github.com/abo-abo/ace-link">ace-link</a></td>
<td class="org-left">A thing that dynamically assigns links key sequences that you can jump to.</td>
</tr>
</tbody>
</table>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #494949;">(</span>ec-load-deps deps<span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgc718fed" class="outline-2">
<h2 id="orgc718fed">Variables</h2>
<div class="outline-text-2" id="text-orgc718fed">
<p>
Here I set up a bunch of variables that are used in the rest of the package. However, I do not set all my variables here and do make some closer to where they are used. <label class="sidenote-number" for="1"><sup>1</sup></label><input checked="checked" id="1" style="display:none" type="checkbox" /><span class="sidenote"><span class="sidenote-number"> 1</span> I am not sure that this is the best practice, but I am so far from the "best practices" zone with this configuration that I may as well just go with it.</span>
</p>
</div>
<div id="outline-container-org0731e08" class="outline-3">
<h3 id="org0731e08">Setting Browsers (and stuff)</h3>
<div class="outline-text-3" id="text-org0731e08">
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defvar</span> <span style="font-style: italic;">ec-graphical-browser</span> <span style="color: #494949;">"firefox"</span>
<span style="color: #a4a4a4; font-style: italic;">"The browser and options used to browse the web when a non-gui browser will not work."</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defvar</span> <span style="font-style: italic;">ec-search-engine</span> <span style="color: #494949;">"lite.duckduckgo.com/lite/&q="</span>
<span style="color: #a4a4a4; font-style: italic;">"The search engine string used to search the web."</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defvar</span> <span style="font-style: italic;">ec-video-fstring</span> <span style="color: #494949;">"vlc '%s' --qt-minimal-view --no-video-title --loop"</span>
<span style="color: #a4a4a4; font-style: italic;">"The format string used to generate the video playing command."</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defvar</span> <span style="font-style: italic;">ec-graphical-browse-domains</span> '<span style="color: #bbb;">(</span><span style="color: #494949;">"http://127.0.0.1:1337?token="</span>
<span style="color: #494949;">"https://meet.jit.si"</span>
<span style="color: #494949;">"http://localhost:35901/"</span><span style="color: #bbb;">)</span>
<span style="color: #a4a4a4; font-style: italic;">"Domains that are to be browsed graphically in `</span><span style="color: #E53935; font-style: italic;">w3m-goto-url-new-session-or-video</span><span style="color: #a4a4a4; font-style: italic;">'."</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgbc13e59" class="outline-3">
<h3 id="orgbc13e59">The w3m Directory</h3>
<div class="outline-text-3" id="text-orgbc13e59">
<p>
Like everything else I like to keep the data for w3m in my data directory instead of randomly floating around in the dotfiles, so I change it to the data directory here.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp" id="org58ad9c4"> <span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defvar</span> <span style="font-style: italic;">ec-w3m-dir</span> <span style="color: #bbb;">(</span>concat ec-data-dir <span style="color: #494949;">"w3m/"</span><span style="color: #bbb;">)</span>
<span style="color: #a4a4a4; font-style: italic;">"Directory where all w3m files are located."</span><span style="color: #494949;">)</span>
</pre>
</div>
<p>
Here I set the variables that I have found that need a directory to dump their files in.
</p>
<table id="orgbcad6a5" border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
</colgroup>
<thead>
<tr>
<th scope="col" class="org-left">Variable</th>
<th scope="col" class="org-left">Value</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left"><code>w3m-profile-directory</code></td>
<td class="org-left"><code>ec-w3m-dir</code></td>
</tr>
<tr>
<td class="org-left"><code>w3m-default-save-directory</code></td>
<td class="org-left"><code>ec-downloads-dir</code></td>
</tr>
<tr>
<td class="org-left"><code>w3m-external-view-temp-directory</code></td>
<td class="org-left"><code>ec-w3m-dir</code></td>
</tr>
<tr>
<td class="org-left"><code>w3m-bookmark-file</code></td>
<td class="org-left"><code>(concat ec-w3m-dir "bookmarks")</code></td>
</tr>
<tr>
<td class="org-left"><code>w3m-cookie-file</code></td>
<td class="org-left">(concat ec-w3m-dir "cookie")</td>
</tr>
</tbody>
</table>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #494949;">(</span>ec-set-variables vars-data-dir<span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org265bd39" class="outline-3">
<h3 id="org265bd39">Further Customizations</h3>
<div class="outline-text-3" id="text-org265bd39">
<p>
Now I just add some further quick customizations to make the browser a little nicer to work with and to conform more with my standard interface.
</p>
<table id="org66fa62d" border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
</colgroup>
<thead>
<tr>
<th scope="col" class="org-left">Variable</th>
<th scope="col" class="org-left">Value</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left"><code>browse-url-browser-function</code></td>
<td class="org-left"><code>#'w3m-goto-url-new-session-or-video</code></td>
</tr>
<tr>
<td class="org-left"><code>w3m-default-display-inline-images</code></td>
<td class="org-left"><code>t</code></td>
</tr>
<tr>
<td class="org-left"><code>w3m-pop-up-windows</code></td>
<td class="org-left"><code>t</code></td>
</tr>
<tr>
<td class="org-left"><code>w3m-search-default-engine</code></td>
<td class="org-left"><code>"duckduckgo"</code></td>
</tr>
<tr>
<td class="org-left"><code>w3m-use-tab</code></td>
<td class="org-left"><code>nil</code></td>
</tr>
<tr>
<td class="org-left"><code>w3m-display-mode</code></td>
<td class="org-left"><code>'plain</code></td>
</tr>
</tbody>
</table>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #494949;">(</span>ec-set-variables vars-further-custom<span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-orgf35fe44" class="outline-2">
<h2 id="orgf35fe44">Playing Videos Without JS</h2>
<div class="outline-text-2" id="text-orgf35fe44">
<p>
Now I don't really like exiting Emacs, so I have added some features to view videos without javascript.
</p>
</div>
<div id="outline-container-org5e82b87" class="outline-3">
<h3 id="org5e82b87">Playing Videos</h3>
<div class="outline-text-3" id="text-org5e82b87">
</div>
<div id="outline-container-orgfe43b78" class="outline-4">
<h4 id="orgfe43b78">ec-w3m-view-video</h4>
<div class="outline-text-4" id="text-orgfe43b78">
<p>
This function simply calls the view video function on the video.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defun</span> <span style="font-weight: bold; font-style: italic;">ec-w3m-view-video</span> <span style="color: #bbb;">(</span>url <span style="color: #E53935;">&rest</span> _<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">interactive</span> <span style="color: #494949;">(</span>browse-url-interactive-arg <span style="color: #494949;">"URL: "</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>start-process-shell-command <span style="color: #494949;">"video"</span>
nil
<span style="color: #494949;">(</span>format ec-video-fstring url<span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgd7e5920" class="outline-4">
<h4 id="orgd7e5920">ec-w3m-video-url?</h4>
<div class="outline-text-4" id="text-orgd7e5920">
<p>
Checks if the video is on a streaming website or if the video content type is something playable with w3m. This way I can directly view videos from download links.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defun</span> <span style="font-weight: bold; font-style: italic;">ec-w3m-video-url?</span> <span style="color: #bbb;">(</span>url<span style="color: #bbb;">)</span>
<span style="color: #a4a4a4; font-style: italic;">"Determine if a URL is a video, if yes return T, if not return nil."</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">and</span> url <span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">or</span> <span style="color: #bbb;">(</span>s-matches? <span style="color: #494949;">"^</span><span style="color: #000; font-weight: bold;">\\</span><span style="color: #000; font-weight: bold;">(</span><span style="color: #494949;">http</span><span style="color: #000; font-weight: bold;">\\</span><span style="color: #000; font-weight: bold;">|</span><span style="color: #494949;">https</span><span style="color: #000; font-weight: bold;">\\</span><span style="color: #000; font-weight: bold;">)</span><span style="color: #494949;">://www.youtube.com/watch\\?v=.*$"</span> url<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>s-matches? <span style="color: #494949;">"^</span><span style="color: #000; font-weight: bold;">\\</span><span style="color: #000; font-weight: bold;">(</span><span style="color: #494949;">http</span><span style="color: #000; font-weight: bold;">\\</span><span style="color: #000; font-weight: bold;">|</span><span style="color: #494949;">https</span><span style="color: #000; font-weight: bold;">\\</span><span style="color: #000; font-weight: bold;">)</span><span style="color: #494949;">://vimeo.com/[0-9]+$"</span> url<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>member <span style="color: #494949;">(</span>ec-get-content-type
url<span style="color: #494949;">)</span>
'<span style="color: #494949;">(</span><span style="color: #494949;">"video/mpg"</span> <span style="color: #494949;">"video/mpeg"</span> <span style="color: #494949;">"video/mp3"</span> <span style="color: #494949;">"video/mp4"</span>
<span style="color: #494949;">"video/avi"</span> <span style="color: #494949;">"video/wmv"</span> <span style="color: #494949;">"video/wav"</span> <span style="color: #494949;">"video/mov"</span>
<span style="color: #494949;">"video/flv"</span> <span style="color: #494949;">"video/ogm"</span> <span style="color: #494949;">"video/ogg"</span> <span style="color: #494949;">"video/mkv"</span>
<span style="color: #494949;">"video/webm"</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-org16ba1da" class="outline-3">
<h3 id="org16ba1da">Redefining Some Functions</h3>
<div class="outline-text-3" id="text-org16ba1da">
<p>
Unfortunately, depending on how a video is reached, a different function may be called. I used to just advise the relevant functions, but I have (against the usual recommendations of the Emacs community) come to prefer redefining functions as redefinition ensures that the function at hand works as expected. <label class="sidenote-number" for="2"><sup>2</sup></label><input checked="checked" id="2" style="display:none" type="checkbox" /><span class="sidenote"><span class="sidenote-number"> 2</span> Basically advices are weird and difficult to parse when you get too many of them whereas redefinition is pretty clear and simple.</span>
</p>
</div>
<div id="outline-container-org277da4a" class="outline-4">
<h4 id="org277da4a">w3m-goto-url-new-session-or-video</h4>
<div class="outline-text-4" id="text-org277da4a">
<p>
This opens a buffer in w3m, a graphical web browser, or vlc intelligently. Exciting.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defun</span> <span style="font-weight: bold; font-style: italic;">w3m-goto-url-new-session-or-video</span> <span style="color: #bbb;">(</span>url <span style="color: #E53935;">&rest</span> _<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">cond</span> <span style="color: #494949;">(</span><span style="color: #bbb;">(</span>ec-w3m-video-url? url<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>ec-w3m-view-video url<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">->></span> ec-graphical-browse-domains
<span style="color: #494949;">(</span>-map <span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">lambda</span> <span style="color: #494949;">(</span>domain<span style="color: #494949;">)</span> <span style="color: #494949;">(</span>s-contains? domain url<span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
first<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>ec-graphical-browse-url url<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span>t <span style="color: #bbb;">(</span>w3m-goto-url-new-session url<span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgacb60e0" class="outline-4">
<h4 id="orgacb60e0">w3m-view-this-url</h4>
<div class="outline-text-4" id="text-orgacb60e0">
<p>
This just redefines the w3m URL thing entirely, checking if it is a video in the first portion of the cond predicate <code>cond</code> macro.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defun</span> <span style="font-weight: bold; font-style: italic;">w3m-view-this-url</span> <span style="color: #bbb;">(</span><span style="color: #E53935;">&optional</span> arg new-session<span style="color: #bbb;">)</span>
<span style="color: #a4a4a4; font-style: italic;">"Display the page pointed to by the link under point.</span>
<span style="color: #a4a4a4; font-style: italic;">If ARG is the number 2 or the list of the number 16 (you may produce</span>
<span style="color: #a4a4a4; font-style: italic;">this by typing `</span><span style="color: #E53935; font-style: italic;">C-u</span><span style="color: #a4a4a4; font-style: italic;">' twice) or NEW-SESSION is non-nil and the link is</span>
<span style="color: #a4a4a4; font-style: italic;">an anchor, this function makes a copy of the current buffer in advance.</span>
<span style="color: #a4a4a4; font-style: italic;">Otherwise, if ARG is non-nil, it forces to reload the url at point."</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">interactive</span> <span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">if</span> <span style="color: #bbb;">(</span>member current-prefix-arg '<span style="color: #494949;">(</span>2 <span style="color: #bbb;">(</span>16<span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>list nil t<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>list current-prefix-arg nil<span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #a4a4a4; font-style: italic;">;; </span><span style="color: #a4a4a4; font-style: italic;">Store the current position in the history structure.</span>
<span style="color: #bbb;">(</span>w3m-history-store-position<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">let</span> <span style="color: #494949;">(</span><span style="color: #bbb;">(</span>w3m-prefer-cache
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">or</span> w3m-prefer-cache
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">and</span> <span style="color: #494949;">(</span>stringp w3m-current-url<span style="color: #494949;">)</span>
<span style="color: #494949;">(</span>string-match <span style="color: #494949;">"\\`about://</span><span style="color: #000; font-weight: bold;">\\</span><span style="color: #000; font-weight: bold;">(?:</span><span style="color: #494949;">db-</span><span style="color: #000; font-weight: bold;">\\</span><span style="color: #000; font-weight: bold;">)</span><span style="color: #494949;">?history/"</span>
w3m-current-url<span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
act url<span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">cond</span>
<span style="color: #bbb;">(</span><span style="color: #494949;">(</span>ec-w3m-video-url? <span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">w3m-anchor</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">progn</span> <span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">w3m-arrived-intern</span> <span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">w3m-anchor</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>ec-w3m-view-video <span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">w3m-anchor</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>w3m-redisplay-this-page<span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">setq</span> act <span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">w3m-action</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">let</span> <span style="color: #bbb;">(</span><span style="color: #494949;">(</span>w3m-form-new-session new-session<span style="color: #494949;">)</span>
<span style="color: #494949;">(</span>w3m-form-download nil<span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>ignore w3m-form-new-session w3m-form-download<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>eval act<span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">setq</span> url <span style="color: #bbb;">(</span>w3m-url-valid <span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">w3m-anchor</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">if</span> new-session
<span style="color: #bbb;">(</span>w3m-goto-url-new-session url arg<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>w3m-goto-url url arg<span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #494949;">(</span>w3m-url-valid <span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">w3m-image</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">if</span> <span style="color: #bbb;">(</span>display-images-p<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>w3m-toggle-inline-image<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>w3m-view-image<span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">setq</span> url <span style="color: #bbb;">(</span>w3m-active-region-or-url-at-point 'never<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">unless</span> <span style="color: #bbb;">(</span>eq 'quit <span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">setq</span> url <span style="color: #bbb;">(</span>w3m-input-url nil url 'quit nil
'feeling-searchy 'no-initial<span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">if</span> new-session
<span style="color: #494949;">(</span>w3m-goto-url-new-session url arg<span style="color: #494949;">)</span>
<span style="color: #494949;">(</span>w3m-goto-url url arg<span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>t <span style="color: #494949;">(</span>w3m-message <span style="color: #494949;">"No URL at point"</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
</div>
</div>
<div id="outline-container-org7ae1998" class="outline-2">
<h2 id="org7ae1998">Search Engine Suggestions</h2>
<div class="outline-text-2" id="text-org7ae1998">
<p>
To add search engine suggestions
</p>
</div>
<div id="outline-container-org095cb11" class="outline-3">
<h3 id="org095cb11">Variables</h3>
<div class="outline-text-3" id="text-org095cb11">
<p>
Here I set a list of variables for the search engine suggestions that.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defvar</span> <span style="font-style: italic;">*search-history*</span> '<span style="color: #bbb;">(</span><span style="color: #494949;">"emacs"</span> <span style="color: #494949;">"clojure"</span> <span style="color: #494949;">"julia"</span> <span style="color: #494949;">"logistics"</span><span style="color: #bbb;">)</span>
<span style="color: #a4a4a4; font-style: italic;">"The search history for the current session."</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defvar</span> <span style="font-style: italic;">*ddg-suggestions*</span> nil
<span style="color: #a4a4a4; font-style: italic;">"The suggestions sent by DDG."</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defvar</span> <span style="font-style: italic;">*ddg-search-string*</span> nil
<span style="color: #a4a4a4; font-style: italic;">"The string to be searched by DDG."</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org754a402" class="outline-3">
<h3 id="org754a402">Functions</h3>
<div class="outline-text-3" id="text-org754a402">
</div>
<div id="outline-container-org570c782" class="outline-4">
<h4 id="org570c782">ec-ddg-suggest-fetch</h4>
<div class="outline-text-4" id="text-org570c782">
<p>
This asynchronously fetches suggestions from the <a href="https://duckduckgo.com">duckduckgo</a> API, using a variable to pass the suggestions to the display function.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"> <span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defun</span> <span style="font-weight: bold; font-style: italic;">ec-duckduckgo-suggest-fetch</span> <span style="color: #bbb;">(</span>input<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>request <span style="color: #494949;">"https://api.duckduckgo.com/ac/"</span>
<span style="color: #E53935;">:type</span> <span style="color: #494949;">"POST"</span>
<span style="color: #E53935;">:params</span> `<span style="color: #494949;">(</span><span style="color: #bbb;">(</span><span style="color: #494949;">"q"</span> . ,input<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #E53935;">:parser</span> 'json-read
<span style="color: #E53935;">:success</span> <span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">cl-function</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">lambda</span> <span style="color: #494949;">(</span><span style="color: #E53935;">&key</span> data <span style="color: #E53935;">&allow-other-keys</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">setq</span> *ddg-suggestions*
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">->></span> data
<span style="color: #494949;">(</span>-map <span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">lambda</span> <span style="color: #494949;">(</span>val<span style="color: #494949;">)</span>
<span style="color: #494949;">(</span>cdar val<span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org8065f1e" class="outline-4">
<h4 id="org8065f1e">ec-ddg-get-suggestions</h4>
<div class="outline-text-4" id="text-org8065f1e">
<p>
Here we define a pretty simple function to get the list of suggestions for the search engine and merge them with the search history. It also starts a new request for suggestions.<label class="sidenote-number" for="3"><sup>3</sup></label><input checked="checked" id="3" style="display:none" type="checkbox" /><span class="sidenote"><span class="sidenote-number"> 3</span> Unfortunately this doesn't actually work fully</span>
</p>
<p>
I also use the rx-macro to dynamically filter out suggestions that don't contain any of the words currently in the input.
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defun</span> <span style="font-weight: bold; font-style: italic;">ec-ddg-get-suggestions</span> <span style="color: #bbb;">(</span>input<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">when</span> <span style="color: #494949;">(</span>not <span style="color: #bbb;">(</span>s-equals? input *ddg-search-string*<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">setq</span> *ddg-search-string* input<span style="color: #494949;">)</span>
<span style="color: #494949;">(</span>ec-duckduckgo-suggest-fetch input<span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">->></span> *search-history*
<span style="color: #494949;">(</span>-filter <span style="color: #bbb;">(</span>-partial 's-matches? <span style="color: #494949;">(</span>rx-to-string `<span style="color: #bbb;">(</span>seq ,@<span style="color: #494949;">(</span>s-split-words input<span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span>-union *ddg-suggestions*<span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgcf8270d" class="outline-4">
<h4 id="orgcf8270d">ec-wikipedia-suggest-fetch</h4>
<div class="outline-text-4" id="text-orgcf8270d">
<p>
I also like to browse wikipedia. <label class="sidenote-number" for="4"><sup>4</sup></label><input checked="checked" id="4" style="display:none" type="checkbox" /><span class="sidenote"><span class="sidenote-number"> 4</span> Unfortunately this function doesn't work yet, but soon™, it will.</span>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defun</span> <span style="font-weight: bold; font-style: italic;">ec-wikipedia-suggest-fetch</span> <span style="color: #bbb;">(</span>input<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">let</span> <span style="color: #494949;">(</span><span style="color: #bbb;">(</span>input <span style="color: #494949;">"emacs"</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">->></span> <span style="color: #bbb;">(</span>request <span style="color: #494949;">"https://en.wikipedia.org/w/api.php"</span>
<span style="color: #E53935;">:type</span> <span style="color: #494949;">"GET"</span>
<span style="color: #E53935;">:params</span> `<span style="color: #494949;">(</span><span style="color: #bbb;">(</span><span style="color: #494949;">"action"</span> . <span style="color: #494949;">"opensearch"</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #494949;">"format"</span> . <span style="color: #494949;">"json"</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #494949;">"search"</span> . <span style="color: #494949;">"emacs"</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #E53935;">:parser</span> 'json-read
<span style="color: #E53935;">:sync</span> t<span style="color: #bbb;">)</span>
request-response-data<span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org35c4529" class="outline-4">
<h4 id="org35c4529">ec-get-region</h4>
<div class="outline-text-4" id="text-org35c4529">
<p>
This is a simple function to grab a region if it is highlighted, else return nil. IDK if it is defined in emacs elsewhere or not, but I decided to add it anyways because it might not be. <label class="sidenote-number" for="5"><sup>5</sup></label><input checked="checked" id="5" style="display:none" type="checkbox" /><span class="sidenote"><span class="sidenote-number"> 5</span> Yes, I know that is a terrible idea.</span>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defun</span> <span style="font-weight: bold; font-style: italic;">ec-get-region</span> <span style="color: #bbb;">()</span>
<span style="color: #a4a4a4; font-style: italic;">"Get the text or return a empty string if it is not present."</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">if</span> <span style="color: #494949;">(</span>use-region-p<span style="color: #494949;">)</span>
<span style="color: #494949;">(</span>buffer-substring-no-properties <span style="color: #bbb;">(</span>region-beginning<span style="color: #bbb;">)</span> <span style="color: #bbb;">(</span>region-end<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">""</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org1058cc2" class="outline-4">
<h4 id="org1058cc2">ec-ddg-search-interactive-arg</h4>
<div class="outline-text-4" id="text-org1058cc2">
<p>
This searches using my suggestions. I use it mostly to build more complex functions for searching the web.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"> <span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defun</span> <span style="font-weight: bold; font-style: italic;">ec-ddg-search-interactive-arg</span> <span style="color: #bbb;">(</span>prompt<span style="color: #bbb;">)</span>
<span style="color: #a4a4a4; font-style: italic;">"Search `</span><span style="color: #E53935; font-style: italic;">w3m-search-default-engine</span><span style="color: #a4a4a4; font-style: italic;">' with ddg completion candidates."</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">let</span> <span style="color: #494949;">(</span><span style="color: #bbb;">(</span>ec-ddg-search <span style="color: #494949;">(</span>ivy-read prompt
#'ec-ddg-get-suggestions
<span style="color: #E53935;">:initial-input</span> <span style="color: #bbb;">(</span>ec-get-region<span style="color: #bbb;">)</span>
<span style="color: #E53935;">:dynamic-collection</span> t<span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">setq</span> *search-history* <span style="color: #bbb;">(</span>cons ec-ddg-search *search-history*<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
`<span style="color: #494949;">(</span>,ec-ddg-search<span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
</div>
</div>
<div id="outline-container-org43834e1" class="outline-2">
<h2 id="org43834e1">Saving Stuff</h2>
<div class="outline-text-2" id="text-org43834e1">
<p>
I also like to occasionally save documentation, so I have written some functions to make that easier.
</p>
</div>
<div id="outline-container-orgfd7d5ee" class="outline-3">
<h3 id="orgfd7d5ee">ec-clone-website</h3>
<div class="outline-text-3" id="text-orgfd7d5ee">
<p>
This just clones a website fully and places it in a directory with the name of the website.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defun</span> <span style="font-weight: bold; font-style: italic;">ec-clone-website</span> <span style="color: #bbb;">(</span>url dirname<span style="color: #bbb;">)</span>
<span style="color: #a4a4a4; font-style: italic;">"Clone a wesbiste to directory."</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">interactive</span> `<span style="color: #494949;">(</span>,<span style="color: #bbb;">(</span>read-string <span style="color: #494949;">"URL: "</span><span style="color: #bbb;">)</span>
,<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">-></span> <span style="color: #494949;">(</span>read-string <span style="color: #494949;">"Directory name: "</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span>s-trim<span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>exec-shell-command <span style="color: #494949;">(</span>format <span style="color: #494949;">"httrack \"%s\" -O ~/Websites/%s"</span> url dirname<span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org1ba01a8" class="outline-3">
<h3 id="org1ba01a8">ec-download-video</h3>
<div class="outline-text-3" id="text-org1ba01a8">
<p>
Sometimes while watching videos from C3 I like to download them, so this is a small, easy function that allows me to do just that.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"> <span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defun</span> <span style="font-weight: bold; font-style: italic;">ec-download-video</span> <span style="color: #bbb;">(</span>url <span style="color: #E53935;">&rest</span> _<span style="color: #bbb;">)</span>
<span style="color: #a4a4a4; font-style: italic;">"Download a youtube video."</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">interactive</span> <span style="color: #494949;">(</span>browse-url-interactive-arg <span style="color: #494949;">"URL: "</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>exec-shell-command <span style="color: #494949;">(</span>concat <span style="color: #494949;">"youtube-dl -f bestaudio --extract-audio --audio-format mp3 --audio-quality 0 '"</span>
url
<span style="color: #494949;">"'"</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-orgea90481" class="outline-2">
<h2 id="orgea90481">User Interface</h2>
<div class="outline-text-2" id="text-orgea90481">
<p>
This is the porcelain of the system. Eventually I think I will separate this into multiple different porcelains (which won't be unit-tested) and libraries (which will).
</p>
</div>
<div id="outline-container-org488f526" class="outline-3">
<h3 id="org488f526">Buffer Names</h3>
<div class="outline-text-3" id="text-org488f526">
<p>
Here we add a function to rename the buffers to the current title to make them both more manageable and searchable than they were otherwise. <label class="sidenote-number" for="6"><sup>6</sup></label><input checked="checked" id="6" style="display:none" type="checkbox" /><span class="sidenote"><span class="sidenote-number"> 6</span> One of my pet-peeves was that w3m didn't really have good names for buffers, instead giving them the usual numeric names which sucked.</span>
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defun</span> <span style="font-weight: bold; font-style: italic;">ec-w3m-rename-buffer-name</span> <span style="color: #bbb;">()</span>
<span style="color: #a4a4a4; font-style: italic;">"Rename the current buffer to whatever the current title is."</span>
<span style="color: #bbb;">(</span>rename-buffer <span style="color: #494949;">(</span>format <span style="color: #494949;">"*world wide web: %s*"</span> w3m-current-title<span style="color: #494949;">)</span> t<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span>add-hook 'w3m-fontify-before-hook #'ec-w3m-rename-buffer-name<span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgb09a41e" class="outline-3">
<h3 id="orgb09a41e">Hydra Interface</h3>
<div class="outline-text-3" id="text-orgb09a41e">
<p>
We also throw in a hydra interface to make all of this much easier to work with.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">ec-defhydra</span> hydra-web <span style="color: #ffffff; background-color: #0000ff;">blue</span>
<span style="color: #bbb;">(</span>'material <span style="color: #494949;">"search"</span> <span style="color: #494949;">"Search the World Wide Web"</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #494949;">"Search"</span>
<span style="color: #494949;">(</span><span style="color: #bbb;">(</span><span style="color: #494949;">"s"</span> ec-search-interactively-new-session<span style="color: #494949;">"search the web"</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #494949;">"u"</span> w3m-goto-url-new-session <span style="color: #494949;">"view URL"</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">"Graphical Search"</span>
<span style="color: #494949;">(</span><span style="color: #bbb;">(</span><span style="color: #494949;">"C-u"</span> ec-graphical-browse-url <span style="color: #494949;">"view URL using graphical browser"</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #494949;">"C-s"</span> ec-graphical-search <span style="color: #494949;">"search using graphical browser"</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">"Site"</span>
<span style="color: #494949;">(</span><span style="color: #bbb;">(</span><span style="color: #494949;">"D"</span> <span style="color: #494949;">(</span>ec-graphical-browse-url <span style="color: #494949;">"https://discord.com/app"</span><span style="color: #494949;">)</span> <span style="color: #494949;">"discord.com/app"</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #494949;">"t"</span> <span style="color: #494949;">(</span>ec-graphical-browse-url <span style="color: #494949;">"https://twitter.com"</span><span style="color: #494949;">)</span> <span style="color: #494949;">"twitter.com"</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #494949;">"y"</span> ec-search-yt-interactively <span style="color: #494949;">"youtube.com"</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">bind-key</span> <span style="color: #bbb;">(</span>kbd <span style="color: #494949;">"C-c w"</span><span style="color: #bbb;">)</span> #'hydra-web/body<span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org9bd4500" class="outline-3">
<h3 id="org9bd4500">Binding Keys</h3>
<div class="outline-text-3" id="text-org9bd4500">
<p>
To regularize the user interface we bind a bunch of keys that are, for some ineffable reason, not bound in a standard way. To rebind the keys in the mode I use the table and function call below.
</p>
<table id="org2421496" border="2" cellspacing="0" cellpadding="6" rules="groups" frame="hsides">
<colgroup>
<col class="org-left" />
<col class="org-left" />
</colgroup>
<thead>
<tr>
<th scope="col" class="org-left">Chord</th>
<th scope="col" class="org-left">Function</th>
</tr>
</thead>
<tbody>
<tr>
<td class="org-left">s</td>
<td class="org-left">ec-search-interactively</td>
</tr>
<tr>
<td class="org-left">S</td>
<td class="org-left">ec-search-interactively-new-session</td>
</tr>
<tr>
<td class="org-left">q</td>
<td class="org-left">quit-window</td>
</tr>
<tr>
<td class="org-left">f</td>
<td class="org-left">w3m-view-next-page</td>
</tr>
<tr>
<td class="org-left">b</td>
<td class="org-left">w3m-view-previous-page</td>
</tr>
<tr>
<td class="org-left">n</td>
<td class="org-left">w3m-next-anchor</td>
</tr>
<tr>
<td class="org-left">p</td>
<td class="org-left">w3m-previous-anchor</td>
</tr>
<tr>
<td class="org-left">M-s</td>
<td class="org-left">w3m-select-buffer</td>
</tr>
<tr>
<td class="org-left"><right></td>
<td class="org-left">forward-char</td>
</tr>
<tr>
<td class="org-left"><left></td>
<td class="org-left">backward-char</td>
</tr>
<tr>
<td class="org-left"><up></td>
<td class="org-left">previous-line</td>
</tr>
<tr>
<td class="org-left"><down></td>
<td class="org-left">next-line</td>
</tr>
<tr>
<td class="org-left">h</td>
<td class="org-left">w3m-history</td>
</tr>
<tr>
<td class="org-left">C-c C-d</td>
<td class="org-left">lexic-search-word-at-point</td>
</tr>
<tr>
<td class="org-left">g</td>
<td class="org-left">w3m-redisplay-this-page</td>
</tr>
<tr>
<td class="org-left">G</td>
<td class="org-left">w3m-reload-this-page</td>
</tr>
<tr>
<td class="org-left">u</td>
<td class="org-left">w3m-goto-url</td>
</tr>
<tr>
<td class="org-left">U</td>
<td class="org-left">w3m-goto-url-new-session</td>
</tr>
</tbody>
</table>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #494949;">(</span>ec-bind-keys w3m-bound-keys 'w3m-mode-map<span style="color: #494949;">)</span>
</pre>
</div>
<p>
I also add my system for creating epubs from websites automatically so I can write notes on the websites in org-mode.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">use-package</span> <span style="color: #E53935;">w3m</span> <span style="color: #E53935;">:config</span> <span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">bind-key</span> <span style="color: #494949;">(</span>kbd <span style="color: #494949;">"w"</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">def-web-note-writer</span> w3m-mode w3m-current-url w3m-current-title<span style="color: #494949;">)</span>
'w3m-mode-map<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgabbc565" class="outline-3">
<h3 id="orgabbc565">Browser Functions</h3>
<div class="outline-text-3" id="text-orgabbc565">
<p>
To make all of it work I also have to define a series of browser functions that will be called in the hydra.
</p>
<div class="org-src-container">
<pre class="src src-elisp"><span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defun</span> <span style="font-weight: bold; font-style: italic;">ec-graphical-browse-url</span> <span style="color: #bbb;">(</span>url <span style="color: #E53935;">&rest</span> _<span style="color: #bbb;">)</span>
<span style="color: #a4a4a4; font-style: italic;">"Browse a URL using the graphical browser."</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">interactive</span> <span style="color: #494949;">(</span>browse-url-interactive-arg <span style="color: #bbb;">(</span>format <span style="color: #494949;">"Open URL in %s: "</span> ec-graphical-browser<span style="color: #bbb;">)</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span> <span style="color: #bbb;">(</span>start-process-shell-command <span style="color: #494949;">"ec-graphical-browser"</span>
nil
<span style="color: #494949;">(</span>format <span style="color: #494949;">"%s '%s'"</span> ec-graphical-browser url<span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defun</span> <span style="font-weight: bold; font-style: italic;">ec-graphical-search</span> <span style="color: #bbb;">(</span>search-terms<span style="color: #bbb;">)</span>
<span style="color: #a4a4a4; font-style: italic;">"Open the graphical browser in a buffer for browsing various websites."</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">interactive</span> <span style="color: #494949;">(</span>ec-ddg-search-interactive-arg <span style="color: #494949;">"Search in graphical browser. DuckDuckGo Search: "</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>exec-shell-command ec-graphical-browser <span style="color: #494949;">"\"https://"</span> ec-search-engine search-terms <span style="color: #494949;">"\""</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defun</span> <span style="font-weight: bold; font-style: italic;">ec-search-interactively-new-session</span> <span style="color: #bbb;">(</span>search-terms<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">interactive</span> <span style="color: #494949;">(</span>ec-ddg-search-interactive-arg <span style="color: #494949;">"Search in new buffer. DuckDuckGo Search: "</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>w3m-search-new-session w3m-search-default-engine search-terms<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defun</span> <span style="font-weight: bold; font-style: italic;">ec-search-interactively</span> <span style="color: #bbb;">(</span>search-terms<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">interactive</span> <span style="color: #494949;">(</span>ec-ddg-search-interactive-arg <span style="color: #494949;">"Search in current buffer. DuckDuckGo Search: "</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>w3m-search w3m-search-default-engine search-terms<span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">defun</span> <span style="font-weight: bold; font-style: italic;">ec-search-yt-interactively</span> <span style="color: #bbb;">(</span>search-terms<span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span><span style="color: #E53935; font-style: italic;">interactive</span> <span style="color: #494949;">(</span>ec-ddg-search-interactive-arg <span style="color: #494949;">"Search in current buffer. Youtube Search: "</span><span style="color: #494949;">)</span><span style="color: #bbb;">)</span>
<span style="color: #bbb;">(</span>w3m-search-new-session w3m-search-default-engine <span style="color: #494949;">(</span>format <span style="color: #494949;">"site:youtube.com %s"</span> search-terms<span style="color: #494949;">)</span><span style="color: #bbb;">)</span><span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orge2ab771" class="outline-3">
<h3 id="orge2ab771">Ace Link</h3>
<div class="outline-text-3" id="text-orge2ab771">
<p>
Now I just add <a href="https://github.com/abo-abo/ace-link">ace-link</a> to make traversing documents much nicer.
</p>
<div class="org-src-container">
<pre class="src src-emacs-lisp"><span style="color: #494949;">(</span>ace-link-setup-default<span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">bind-key</span> <span style="color: #bbb;">(</span>kbd <span style="color: #494949;">"C-o"</span><span style="color: #bbb;">)</span> #'ace-link<span style="color: #494949;">)</span>
<span style="color: #494949;">(</span><span style="color: #E53935; font-style: italic;">bind-key</span> <span style="color: #bbb;">(</span>kbd <span style="color: #494949;">"o"</span><span style="color: #bbb;">)</span> #'ace-link 'w3m-mode-map<span style="color: #494949;">)</span>
</pre>
</div>
</div>
</div>
</div>
<!-- Footnotes --><!--
<div class="footdef"><sup><a id="fn.1" class="footnum" href="#fnr.1" role="doc-backlink">1</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">I am not sure that this is the best practice, but I am so far from the "best practices" zone with this configuration that I may as well just go with it.</p></div></div>
<div class="footdef"><sup><a id="fn.2" class="footnum" href="#fnr.2" role="doc-backlink">2</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">Basically advices are weird and difficult to parse when you get too many of them whereas redefinition is pretty clear and simple.</p></div></div>
<div class="footdef"><sup><a id="fn.3" class="footnum" href="#fnr.3" role="doc-backlink">3</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">Unfortunately this doesn't actually work fully</p></div></div>
<div class="footdef"><sup><a id="fn.4" class="footnum" href="#fnr.4" role="doc-backlink">4</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">Unfortunately this function doesn't work yet, but soon™, it will.</p></div></div>
<div class="footdef"><sup><a id="fn.5" class="footnum" href="#fnr.5" role="doc-backlink">5</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">Yes, I know that is a terrible idea.</p></div></div>
<div class="footdef"><sup><a id="fn.6" class="footnum" href="#fnr.6" role="doc-backlink">6</a></sup> <div class="footpara" role="doc-footnote"><p class="footpara">One of my pet-peeves was that w3m didn't really have good names for buffers, instead giving them the usual numeric names which sucked.</p></div></div>
--></div>
<div id="postamble" class="status">
<p class="date">Last Modified: 2021-W50-6 00:53</p><p class="creator">Generated Using: <a href="https://www.gnu.org/software/emacs/">Emacs</a> 27.2 (<a href="https://orgmode.org">Org</a> mode 9.4.6)</p><p class="license">Except where otherwise noted content on <a href="https://cons.dev">cons.dev</a> is licensed under a <a href="https://creativecommons.org/licenses/by-sa/4.0/" rel="license">Creative Commons Attribution-ShareAlike 4.0 International License</a>.</p>
</div>
</body>
</html>