-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathemacs.el
1530 lines (1282 loc) · 57.3 KB
/
emacs.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
;;; .emacs --- old init file -*- lexical-binding: t; -*-
;; Copyright (C) 1989-2020 Juri Linkov <[email protected]>
;; Author: Juri Linkov <[email protected]>
;; Keywords: dotemacs, init
;; URL: <http://www.linkov.net/emacs>
;; Version: 2023-08-31 for GNU Emacs 28.0.50 (x86_64-pc-linux-gnu)
;; This file now contains semi-obsolete settings.
;; For more up-to-date settings,
;; please see the file README.org in the same directory.
;;; mouse
;; Move the mouse to the screen corner on any keypress.
;; This is commented out because now `mouse-avoidance-mode'
;; is customized to `banish' in `custom-set-variables':
;; (when (and (display-mouse-p) (require 'avoid nil t))
;; ;; Move the mouse to the lower-right corner instead of default upper-right
;; ;; (defun mouse-avoidance-banish-destination ()
;; ;; (cons (+ 3 (frame-width)) (- (frame-height) 1)))
;; ;; The above is now customized for 24.2+ in `custom-set-variables' as:
;; ;; (mouse-avoidance-banish-position
;; ;; '((frame-or-window . frame) (side . right) (side-pos . -3)
;; ;; (top-or-bottom . bottom) (top-or-bottom-pos . 1)))
;; (mouse-avoidance-mode 'banish))
;; Show the text pointer in void text areas (no need any more)
;; (setq void-text-area-pointer nil)
;; (setq make-pointer-invisible t)
;;; colors
(defun my-colors-light (&optional frame)
"Set colors suitable for working in light environments,
i.e. in daylight or under bright electric lamps."
(interactive)
(setq frame-background-mode 'light)
(if frame
(select-frame frame)
(setq frame (selected-frame)))
;; The color with minimal eye fatigue in light environments
;; is "AntiqueWhite3" (RGB: 205 192 176),
;; (set-background-color "AntiqueWhite3")
(set-background-color "white")
(set-foreground-color "black")
(when (facep 'region)
(set-face-background 'region "gray90" frame))
(when (facep 'fringe)
(set-face-background 'fringe (face-background 'default) frame)
(set-face-foreground 'fringe (face-foreground 'default) frame)))
(define-key global-map [f6 ?c ?s] 'my-colors-light)
(defun my-colors-dark (&optional frame)
"Set colors suitable for working in the darkness without electricity."
(interactive)
(setq frame-background-mode 'dark)
(if frame
(select-frame frame)
(setq frame (selected-frame)))
(set-background-color "black")
(set-foreground-color "DarkGrey")
(when (facep 'region)
(set-face-background 'region "DimGray" frame))
(when (facep 'fringe)
(set-face-background 'fringe (face-background 'default) frame)
(set-face-foreground 'fringe (face-foreground 'default) frame)))
(define-key global-map [f6 ?c ?d] 'my-colors-dark)
(define-key global-map [Multi_key] [t]) ; don't beep on accidental keypress
(defvar my-sunset-timer nil)
(defvar my-sunrise-timer nil)
;; Automatically switch to dark background after sunset
;; and to light background after sunrise.
;; (Note that `calendar-latitude' and `calendar-longitude'
;; should be set before calling the `solar-sunrise-sunset')
(defun my-colors-set (&optional frame)
(interactive)
(require 'solar)
(if (and (bound-and-true-p calendar-latitude)
(bound-and-true-p calendar-longitude)
(bound-and-true-p calendar-time-zone))
(let* ((l (solar-sunrise-sunset (calendar-current-date)))
(sunrise-string (apply 'solar-time-string (car l)))
(sunset-string (apply 'solar-time-string (car (cdr l))))
(current-time-string (format-time-string "%H:%M")))
(if (or (string-lessp current-time-string sunrise-string)
(string-lessp sunset-string current-time-string))
(my-colors-dark frame)
(my-colors-light frame))
(if (and (boundp 'my-sunset-timer) (timerp my-sunset-timer))
(cancel-timer my-sunset-timer))
(if (and (boundp 'my-sunrise-timer) (timerp my-sunrise-timer))
(cancel-timer my-sunrise-timer))
(setq my-sunset-timer (run-at-time sunset-string (* 60 60 24)
'my-colors-dark))
(setq my-sunrise-timer (run-at-time sunrise-string (* 60 60 24)
'my-colors-light)))))
;; (my-colors-set)
;; (add-hook 'after-make-frame-functions 'my-colors-set)
;;; faces
(defvar face nil)
(defun my-faces-fix (&optional frame)
"Fix defined faces."
(interactive)
;; Check if this function is called by `custom-define-hook' from
;; `custom-declare-face' where the variable `face' is bound locally.
(when (boundp 'face)
(dolist (face (face-list))
;; Make italic gray instead of black
;; (when (face-italic-p face frame)
;; (if (equal (face-foreground face frame) "black")
;; (set-face-foreground face "gray50" frame)))
;; My font makes bold text illegible,
;; so replace bold property with underline property
;; (when (face-bold-p face frame)
;; (set-face-bold face nil frame)
;; ;; (set-face-inverse-video face t frame)
;; (set-face-underline face t frame))
;; Fonts with different height decrease the amount of lines
;; visible on screen, so remove the height property
;; (when (numberp (face-attribute face :height frame))
;; (set-face-attribute face frame :height 'unspecified))
;; Fonts with different width decrease the amount of characters
;; on the line, so remove the width property
;; (when (numberp (face-attribute face :width frame))
;; (set-face-attribute face frame :width 'unspecified))
;; Fonts with different weight decrease the height and width,
;; of the line, so remove the weight property
;; (when (numberp (face-attribute face :weight frame))
;; (set-face-attribute face frame :weight 'unspecified))
;; (unless (string-match "^mode-line" (symbol-name face))
;; ;; Reset all face attributes
;; (modify-face face))
;; New feature in Emacs 27
;; (set-face-attribute face frame :extend t)
;; (set-face-extend face t frame)
)))
;; 1. Fix existing faces
;; (let ((face t)) (my-faces-fix))
;; (add-hook 'after-init-hook (lambda () (let (face) (my-faces-fix))) t)
;; 2. Call `my-faces-fix' every time some new face gets defined
(add-hook 'custom-define-hook 'my-faces-fix)
;;; keybindings
;; Keybindings (meta up) (meta down) are free when windmove uses `super'.
;; Actually I don't use next two keybindings, use them for something useful
;; (define-key global-map [(control meta prior)] 'scroll-right)
;; (define-key global-map [(control meta next)] 'scroll-left)
;; (define-key global-map [(control return)]
;; (lambda () (interactive) (let ((use-hard-newlines t)) (newline))))
;; (define-key global-map [(meta return)]
;; (lambda () (interactive) (scroll-other-window 1))) ;; [(meta down)]
;; (define-key global-map [(meta backspace)]
;; (lambda () (interactive) (scroll-other-window -1))) ;; [(meta up)]
;; (define-key global-map [(control backspace)] 'backward-kill-word)
;; (define-key global-map [(meta backspace)] 'undo)
;; (define-key global-map [(meta backspace)] 'backward-kill-word)
;; (define-key global-map [(control backspace)] 'join-lines)
;; These following two keybindings are standard default:
;; (define-key global-map [(meta /)] 'dabbrev-expand)
;; (define-key global-map [(control meta /)] 'dabbrev-completion)
;; The following key is not available:
;; (define-key global-map [(control meta kp-divide)] 'hippie-expand)
;; BAD key: (define-key global-map "\M-n" 'clone-buffer)
(define-key global-map [(control x) (c) (b)] 'clone-buffer)
;; (define-key global-map [(control escape)]
;; (lambda () (interactive) (buffer-menu 1))) ; not needed
;; (define-key global-map [(control escape)] 'ibuffer)
;; (define-key global-map [(shift f10)] 'buffer-menu) ; not needed
;; TODO: currently key (control escape) is free, bind it to something useful,
;; unless it is used by the window manager
;; The following two corrections are for Scandinavian keyboard layouts.
;; Bind AltGr-space to the same command as is bound to Alt-space (M-SPC)
;; instead of inserting space-looking nobreak-space (nbsp, 0xa0, 0x8a0).
;; This is not necessary in Emacs 22 where nbsp has a special face.
;; (define-key global-map [?\xa0] 'just-one-space)
;; (define-key global-map [?\x8a0] 'just-one-space)
;; Swap currency sign with dollar sign, so dollar sign which is used more
;; often in programming languages could be typed more easily by pressing
;; shift-4 instead of AltGr-4.
;; (keyboard-translate ?\244 ?\$)
;; (keyboard-translate ?\$ ?\244)
;; Better to change this in .xmodmaprc for other applications too as:
;; keycode 13 = 4 dollar 4 dollar dollar cent
;; Map some diacritic characters (Ao, A", O") to arrow keys
;; which have the same layout as arrow pad keys on AltGr keyboards
;; This is experimental to make C-f/C-b/C-n/C-p like as easy as hjkl.
;; (define-key global-map [?\x8e5] 'previous-line) ; [up]
;; (define-key global-map [?\x8e4] 'next-line)
;; (define-key global-map [?\x8f6] 'backward-char)
;; (define-key global-map [?'] 'forward-char)
;; On some keyboards, '<' and '>' are on the same key near 'z',
;; so when switching keyboards, I often mistype 'M-z' for 'M-<' and 'M->':
(define-key esc-map "z" 'beginning-of-buffer)
(define-key esc-map "Z" 'end-of-buffer)
;;; quail
;; The default key `C-\' is difficult to type on AltGr keyboards.
;; (global-set-key [(control ?+)] 'toggle-input-method)
;; (global-set-key [(control ?')] 'toggle-input-method)
;; (global-set-key [(meta return)] 'toggle-input-method)
;; (define-key isearch-mode-map [(meta return)] 'isearch-toggle-input-method)
;; added for capslock to ~/.xsession: echo "keycode 66 = Print" | xmodmap -
;; (global-set-key [print] 'toggle-input-method)
;; (define-key isearch-mode-map [print] 'isearch-toggle-input-method)
;; (define-key mule-keymap "\\" 'set-input-method)
;; TODO for Emacs23: if toggle-input-method is called on the active region
;; then convert region to other coding, this is very useful when the region
;; was typed with a wrong input method, when the user forgot to toggle it
;; (this is like venerable PuntoSwitcher)
;;; functions
(defvar my-scroll-auto-timer nil)
(defun my-scroll-auto (arg)
"Scroll text of current window automatically with a given frequency.
With a numeric prefix ARG, use its value as frequency in seconds.
With C-u, C-0 or M-0, cancel the timer."
(interactive
(list (progn
(if (and (boundp 'my-scroll-auto-timer)
(timerp my-scroll-auto-timer))
(cancel-timer my-scroll-auto-timer))
(or current-prefix-arg
(read-from-minibuffer
"Enter scroll frequency measured in seconds (0 or RET for cancel): "
nil nil t nil "0")))))
(if (not (or (eq arg 0) (equal arg '(4))))
(setq my-scroll-auto-timer (run-at-time t arg 'scroll-up 1))))
;; (define-key my-map "s" 'my-scroll-auto)
;;; cursor
;; USE (setq-default cursor-type ...) INSTEAD OF THE NEXT FUNCTION
;; (defun set-cursor-type (cursor-type)
;; "Set the text cursor type of the selected frame to CURSOR-TYPE.
;; When called interactively, prompt for the name of the type to use.
;; To get the frame's current cursor type, use `frame-parameters'."
;; ;; see `fringe-query-style'
;; (interactive (list (intern (completing-read
;; "Cursor type: "
;; '("box" "hollow" "bar" "hbar" nil)))))
;; (modify-frame-parameters (selected-frame)
;; (list (cons 'cursor-type cursor-type))))
;; Currently cursor color is frame-local, but should be buffer-local like
;; cursor-type (or maybe even window-local).
;; Also background color should be buffer-local
;; (maybe this is already fixed in the tiled-background branch?).
;; (defadvice toggle-input-method (after my-toggle-input-method activate)
;; (if current-input-method
;; (set-cursor-color "red") ; "AntiqueWhite4"
;; (set-cursor-color "black")))
;;; isearch
;; Wrap without failing, posted to
;; http://stackoverflow.com/questions/285660/automatically-wrapping-i-search#287067
;; (defadvice isearch-repeat (after isearch-no-fail activate)
;; (unless isearch-success
;; (ad-disable-advice 'isearch-repeat 'after 'isearch-no-fail)
;; (ad-activate 'isearch-repeat)
;; (isearch-repeat (if isearch-forward 'forward))
;; (ad-enable-advice 'isearch-repeat 'after 'isearch-no-fail)
;; (ad-activate 'isearch-repeat)))
;; Automatically recenter every found isearch match
;; (defadvice isearch-update (before my-isearch-update activate)
;; (sit-for 0)
;; (if (and
;; ;; not the scrolling command
;; (not (eq this-command 'isearch-other-control-char))
;; ;; not the empty string
;; (> (length isearch-string) 0)
;; ;; not the first key (to lazy highlight all matches w/o recenter)
;; (> (length isearch-cmds) 2)
;; ;; the point in within the given window boundaries
;; (let ((line (count-screen-lines (point) (window-start))))
;; (or (> line (* (/ (window-height) 4) 3))
;; (< line (* (/ (window-height) 9) 1)))))
;; (let ((my-recenter-position 0.3))
;; (recenter '(4)))))
;; Automatically reposition every found isearch match
;; (defadvice isearch-update (before my-isearch-reposite activate)
;; (sit-for 0)
;; (reposition-window))
;; TODO: try to use `isearch-update-post-hook', e.g.
;; (add-hook 'isearch-update-post-hook 'recenter)
;; (add-hook 'replace-update-post-hook 'recenter)
;; (defadvice isearch-update (before my-isearch-reposite activate)
;; (sit-for 0)
;; ;; While browsing patches, make the next hunk posited at the window's top:
;; (when (and (derived-mode-p 'diff-mode) isearch-regexp (equal "^revno:" isearch-string))
;; (recenter 1)))
;; Make Isearch mode-line string shorter, just " /" instead of " Isearch"
;; (add-hook 'isearch-mode-hook
;; (lambda () (setq isearch-mode " /") (force-mode-line-update)))
;;; minibuffer
;; THE NEXT 3 FUNCTIONS WORK WITH BIG DELAY (try to use like icomplete.el)
;; see also PC-temp-minibuffer-message, file-cache-temp-minibuffer-message,
;; calc-temp-minibuffer-message and bug report in emacs-pretest-bug
;; Subject: bad doc string for PC-temp-minibuffer-message
;; Actually this is like isearch-count
(defun minibuffer-history-position-message ()
(if (memq this-command '(next-history-element previous-history-element
next-line-or-history-element previous-line-or-history-element))
(minibuffer-message
(propertize
(format "%s[%s]"
(make-string
1
;; (- (frame-width)
;; (minibuffer-prompt-width)
;; (length (minibuffer-contents-no-properties))
;; 5)
?\ )
minibuffer-history-position)
'face 'shadow))))
;; (defadvice next-history-element (after history-position-message activate)
;; (minibuffer-history-position-message))
;; (defadvice previous-history-element (after history-position-message activate)
;; (minibuffer-history-position-message))
;; (defadvice next-line-or-history-element (after history-position-message activate)
;; (minibuffer-history-position-message))
;; (defadvice previous-line-or-history-element (after history-position-message activate)
;; (minibuffer-history-position-message))
;; (defadvice goto-history-element (after history-position-message activate)
;; (minibuffer-history-position-message))
;; (defadvice goto-history-element (before minibuffer-set-default activate)
;; (if (functionp minibuffer-default-function)
;; (funcall minibuffer-default-function)))
;; Another implementation of the same idea:
(defvar minibuffer-history-position-overlay)
(make-variable-buffer-local 'minibuffer-history-position-overlay)
(defun minibuffer-history-position-setup ()
"Set up a minibuffer for `minibuffer-history-position-mode'.
The prompt should already have been inserted."
(setq minibuffer-history-position-overlay (make-overlay (point-min) (1+ (point-min))))
(overlay-put minibuffer-history-position-overlay 'evaporate t))
;; (add-hook 'minibuffer-setup-hook 'minibuffer-history-position-setup)
(defun minibuffer-history-position-update ()
"Update a minibuffer for `minibuffer-history-position-mode'."
(overlay-put minibuffer-history-position-overlay 'before-string
(propertize (format "(%d) " minibuffer-history-position)
'face 'minibuffer-prompt)))
;; (defadvice next-history-element (after my-next-history-element activate)
;; (minibuffer-history-position-update))
;; (defadvice previous-history-element (after my-previous-history-element activate)
;; (minibuffer-history-position-update))
;; (defadvice next-line-or-history-element (after my-next-history-element activate)
;; (minibuffer-history-position-update))
;; (defadvice previous-line-or-history-element (after my-previous-history-element activate)
;; (minibuffer-history-position-update))
;;; other features
;; http://thread.gmane.org/gmane.emacs.devel/116457/focus=116468 is like this:
(defun my-info-refresh (&optional arg)
"Display some useful information in the echo area instead of the mode line.
With prefix arg, insert the current timestamp to the current buffer."
(interactive "P")
(cond
((equal arg '(4)) ; C-u f5
(insert (format-time-string "%Y%m%d" (current-time))))
((equal arg '(16)) ; C-u C-u f5
(insert (format-time-string "%Y-%m-%d" (current-time))))
(t (message "%s"
(concat
(format-time-string "%Y-%m-%d %H:%M:%S %z" (current-time)) ;; ISO
" "
(if (boundp 'calendar-day-abbrev-array)
(aref calendar-day-abbrev-array (nth 6 (decode-time (current-time))))
(format-time-string "%a" (current-time)))
" : "
(or (buffer-file-name) default-directory))))))
(define-key my-map [f5] 'my-info-refresh)
(define-key global-map [f5] 'my-info-refresh)
(defvar my-work-log-file)
(defun my-work-log-add (&optional _arg)
(interactive "P")
(find-file my-work-log-file)
(goto-char (point-max))
(cond ((re-search-backward "^[0-9-]+ [0-9:]+\\( +\\)[^0-9]" nil t)
(goto-char (match-beginning 1))
(replace-match "" t t nil 1)
(insert (format-time-string " %H:%M " (current-time))))
((re-search-backward "^[0-9-]+ [0-9:]+" nil t)
(forward-line 1)
(insert (format-time-string "%Y-%m-%d %H:%M \n" (current-time)))
(backward-char))))
(define-key my-map "wl" 'my-work-log-add)
(defun my-buffer-xray ()
"Display text properties and overlays of current buffer by adding markups."
(interactive)
(let* ((newbuf (get-buffer-create (format "*xray-buffer*/%s" (buffer-name))))
(s (buffer-substring (point-min) (point-max))) ;; (buffer-string) -no-properties
(overlays (sort (overlays-in (point-min) (point-max))
(lambda (a b) (< (overlay-start a)
(overlay-start b)))))
(oi 0)
;; ‘ois’ is indexes of overlays sorted by start positions
(ois (mapcar (lambda (o) (setq oi (1+ oi)) (cons o oi))
overlays))
;; ‘poss’ is list of positions of boundaries of text properties
;; and start and end positions of overlays
(poss (sort
(append
(let ((p (point-min)) (pp))
(while p
(setq pp (cons (cons p (text-properties-at p)) pp))
(setq p (next-property-change p)))
pp)
(mapcar (lambda (o)
(list (overlay-start o) 'os (cdr (assq o ois))))
overlays)
(mapcar (lambda (o)
(list (overlay-end o) 'oe (cdr (assq o ois))))
overlays))
;; Sort positions in the descending order
(lambda (a b) (if (= (car a) (car b))
;; for equal positions first no prop
(or (null (cadr b))
(and (eq (cadr a) 'os) (eq (cadr b) 'os)
(> (caddr a) (caddr b)))
(and (eq (cadr a) 'oe) (eq (cadr b) 'oe)
(< (caddr a) (caddr b))))
(> (car a) (car b))))))
(p (point)))
(switch-to-buffer newbuf)
(insert s)
(goto-char p)
(save-excursion
(mapc (lambda (pos)
(goto-char (car pos))
;; Insert markup from buffer end to the beginning
(cond
((eq (cadr pos) 'os)
(insert (format "<o%s>" (caddr pos))))
((eq (cadr pos) 'oe)
(insert (format "</o%s>" (caddr pos))))
((null (cdr pos))
(insert "</p>"))
(t (let ((props (cdr pos)))
(insert "<p")
(while props
(insert (format " %s=\"" (car props)))
(insert
(cond
((overlayp (cadr props))
(format "o%s" (cdr (assq (cadr props) ois))))
(t
(format "%s" (cadr props)))))
(insert "\"")
(setq props (cddr props)))
(insert ">")))))
poss))
(run-hooks 'my-buffer-xray)))
(add-hook 'my-buffer-xray 'html-mode)
;;; wincows
;; Standalone wincows.el is replaced by `tab-switcher' above now.
(when nil ;; (require 'wincows nil t)
(define-key global-map [(meta ?\xa7)] 'wincows)
;; (define-key global-map [(meta ?\x8a7)] 'wincows)
(define-key global-map [(meta ?`)] 'wincows)
(define-key global-map [(super ?`)] 'wincows)
(with-eval-after-load 'wincows
(define-key wincows-mode-map [(meta ?\xa7)] 'wincows-select)
;; (define-key wincows-mode-map [(meta ?\x8a7)] 'wincows-select)
(define-key wincows-mode-map [(meta ?`)] 'wincows-select)
(define-key wincows-mode-map [(super ?`)] 'wincows-select)
(define-key wincows-mode-map [( ?\xa7)] 'wincows-next-line)
;; (define-key wincows-mode-map [(?\x8a7)] 'wincows-next-line)
(define-key wincows-mode-map [( ?`)] 'wincows-next-line)
(define-key wincows-mode-map [( ?\xbd)] 'wincows-prev-line)
;; (define-key wincows-mode-map [(?\x8bd)] 'wincows-prev-line)
(define-key wincows-mode-map [( ?~)] 'wincows-prev-line)))
;;; lisp
(define-key emacs-lisp-mode-map "\C-xF" 'find-function)
(define-key emacs-lisp-mode-map "\C-x4F" 'find-function-other-window)
(define-key emacs-lisp-mode-map "\C-x5F" 'find-function-other-frame)
(define-key emacs-lisp-mode-map "\C-xK" 'find-function-on-key)
(define-key emacs-lisp-mode-map "\C-xV" 'find-variable)
(define-key emacs-lisp-mode-map "\C-x4V" 'find-variable-other-window)
(define-key emacs-lisp-mode-map "\C-x5V" 'find-variable-other-frame)
(tempo-define-template "emacs-lisp-print-message" '("(message \"%s\" " p ")"))
(define-key emacs-lisp-mode-map "\C-zim" 'tempo-template-emacs-lisp-print-message)
(tempo-define-template "emacs-lisp-print-defun"
'("(defun " p " ()\n (interactive)\n\n)\n"))
(define-key emacs-lisp-mode-map "\C-zid" 'tempo-template-emacs-lisp-print-defun)
;; Lisp mode
(tempo-define-template "lisp-print-map" '("(map (lambda (x) ) " p ")"))
(define-key lisp-mode-map "\C-zim" 'tempo-template-lisp-print-map)
;; Emacs Lisp mode
;; use C-M-i instead of
;; (define-key emacs-lisp-mode-map [(control meta tab)] 'lisp-complete-symbol)
;; use C-M-i instead of
;; (define-key emacs-lisp-mode-map "\C-ze\t" 'lisp-complete-symbol)
;; Lisp Interaction mode
;; (define-key lisp-interaction-mode-map [(control backspace)]
;; 'my-join-line-and-indent-sexp-or-backward-kill-word)
;; use C-M-i instead of
;; (define-key lisp-interaction-mode-map [(control meta tab)] 'lisp-complete-symbol)
(tempo-define-template "lisp-print-map" '("(map (lambda (x) ) " p ")"))
(define-key lisp-interaction-mode-map "\C-zim" 'tempo-template-emacs-lisp-print-message)
(font-lock-add-keywords
nil ;; 'emacs-lisp-mode
`(("\\<lambda\\>"
(0 (progn (compose-region (match-beginning 0) (match-end 0)
,(make-char 'greek-iso8859-7 107))
nil)))))
;;; clojure
(with-eval-after-load 'clojure-mode
(add-hook 'clojure-mode-hook
(lambda ()
(setq-local inferior-lisp-program
;; For latest version:
"lein repl"
;; "java -cp /home/work/java/clojure/jar/clojure-1.7.0-alpha1.jar clojure.main"
;; "java -cp /home/work/java/clojure/jar/clojure-1.5.0-RC4.jar clojure.main"
;; For 1.2 with init file:
;; "java clojure.main -i ~/init.clj"
;; "java clojure.main"
;; For OLD version 1.0 (deprecated):
;; "java -cp clojure.jar clojure.lang.Repl"
;; For installed version in Ubuntu:
;; "clojure"
)))
;; FROM https://github.com/weavejester/compojure/wiki/Emacs-indentation
;; (define-clojure-indent
;; (defroutes 'defun)
;; (GET 2)
;; (POST 2)
;; (PUT 2)
;; (DELETE 2)
;; (HEAD 2)
;; (ANY 2)
;; (context 2))
)
;;; snd
(autoload 'sndtr-mode "sndtr" "Major mode for editing Snd transcripts." t)
;; transcripts sndtr files
(add-to-list 'auto-mode-alist '("\\.trs\\'" . sndtr-mode))
;; marks snd files
(add-to-list 'auto-mode-alist '("\\.marks\\'" . scheme-mode))
(defun run-snd ()
(interactive)
(run-scheme "snd -notebook" )
(rename-buffer "*snd*"))
(defvar inferior-lisp-prompt)
;; Added "<" for Scheme "#<unspecified>"
(setq inferior-lisp-prompt "^[^<> \n]*>+:? *")
;(define-key inferior-scheme-mode-map [(meta down)] 'comint-next-prompt)
;(define-key inferior-scheme-mode-map [(meta up)] 'comint-previous-prompt)
(add-hook
'inferior-scheme-mode-hook
(lambda ()
;; no special variable for prompt in cmuscheme.el
(setq comint-prompt-regexp "^[^<>\n]*>+ *") ; added "<"
(define-key global-map "\C-zii"
(lambda ()
(interactive)
(let* ((proc (scheme-proc))
(m (marker-position (process-mark proc)))
(str
(save-excursion
(comint-send-string
proc
"(list (selection-position) (selection-length))\n")
(accept-process-output proc)
(set-buffer "*scheme*")
(buffer-substring
m
(marker-position (process-mark proc))))))
(insert str))))))
;;; dsssl
;; Make font-lock recognise more DSSSL keywords.
;; (setq scheme-font-lock-keywords
;; (cons '("(\\(make\\|element\\|style\\|mode\\|root\\|with-mode\\)[ \t\n]\
;; \\([0-9a-z.-]+\\|([^)]+)\\)"
;; (1 font-lock-keyword-face)
;; (2 font-lock-function-name-face))
;; scheme-font-lock-keywords))
;; Use Scheme mode for DSSSL files.
;; (add-to-list 'auto-mode-alist '("\\.dss?s?l$" . scheme-mode))
(add-to-list 'auto-mode-alist '("\\.ss$" . scheme-mode))
;;; perl
;; Use cperl mode instead of perl mode
;; PS: Don't use over-bloated cperl mode; use default perl mode instead
;; (defalias 'perl-mode 'cperl-mode)
;; (fset 'perl-mode 'cperl-mode)
(with-eval-after-load 'autoinsert
(add-to-list
'auto-insert-alist
'(perl-mode
nil
"#!/usr/bin/perl -w" \n
"# -*- Perl -*-" \n
;; "# $Id$" \n
;; "# $RCSfile$$Revision$$Date$" \n
"# $Revision$" \n
\n
"while (<>) {" \n
> "chomp;" \n
> _ \n
> "print \"$_\\n\";\n"
"}\n")))
(tempo-define-template "perl-skeleton"
'("#!/usr/bin/perl -w\n# -*- Perl -*-\n# $Revision$\n\nwhile (<>) {\n chomp;\n "
p "\n}\n"))
(tempo-define-template "perl-s-skeleton" '("s/" p "//;"))
(tempo-define-template "perl-print-skeleton" '("print \"$_" p "\\n\";"))
(tempo-define-template "perl-while-skeleton" '("while (<>) {\n chomp;\n " p "\n}\n"))
(with-eval-after-load 'perl-mode
;; (define-auto-insert 'perl-mode (lambda () (tempo-template-perl-skeleton)))
(define-key perl-mode-map "\C-ziw" 'tempo-template-perl-while-skeleton)
(define-key perl-mode-map "\C-zip" 'tempo-template-perl-print-skeleton)
(define-key perl-mode-map "\C-zis" 'tempo-template-perl-s-skeleton))
;; Try to distinguish between Perl and Prolog file types
;; TODO: make/use external programs (a-la 'file')
;; but best solution is to use "-*- mode: -*-" in the first line
;; qv http://thread.gmane.org/gmane.emacs.devel/114377/focus=114713
(setq auto-mode-alist
(append '(("\\.perl\\'" . perl-mode)
("\\.pm\\'" . perl-mode)
;; pl files in *perl* dir are Perl files
;; ("perl.*\\.pl\\'" . perl-mode)
("\\.pl\\'" . perl-mode))
auto-mode-alist))
(defun my-pl-find-file-hook ()
;; To distinguish Prolog and Perl files with the same file extension
;; '.pl', it assumes that Perl programs begin with a comment '#',
;; but this doesn't work yet for Prolog shell scripts, so it's more
;; reliable to use file local variables with the needed mode specified.
(if (and (looking-at "#")
(or
;; This works when '.pl' is associated with Prolog mode
(string-match "Prolog" mode-name)
;; BTW, Perl mode fits perfectly for different conf-files
(equal mode-name "Fundamental")))
(perl-mode)))
;; (add-hook 'find-file-hook 'my-pl-find-file-hook)
;; Create Perl links in the *Man* buffer
(with-eval-after-load 'man
(add-hook
'Man-cooked-hook
(lambda ()
;; TODO: add to perl-mode.el? and cperl-mode.el?
;; BAD: it breaks links followed with a dot!
(if (string-match "\\`\\([0-9]+ *\\)?perl" Man-arguments)
(Man-highlight-references0
"DESCRIPTION"
"\\(perl\\(?:[a-z0-9]+[a-z]\\|[a-z][a-z0-9]+\\)\\)[^a-z0-9]"
1 0 'Man-xref-man-page)))))
;;; prolog
(with-eval-after-load 'prolog
(setq prolog-system 'swi)
(setq prolog-indent-width 8)
(setq prolog-electric-dot-flag t)
(setq prolog-program-switches
'((sicstus ("-i"))
(swi ("-G8M"))
(t nil)))
(setq prolog-info-predicate-index "(prolog)Predicates188"))
;; Use better prolog-mode from http://www.emacswiki.org/emacs/PrologMode
;; renamed here to prolog2.el
;; (load "progmodes/prolog2.el")
;; (autoload 'run-prolog "prolog2" "Start a Prolog sub-process." t)
;; (autoload 'prolog-mode "prolog2" "Major mode for editing Prolog programs." t)
;; (autoload 'mercury-mode "prolog2" "Major mode for editing Mercury programs." t)
;; (setq outline-regexp "[0-9]+ \\?-") ; for *prolog*
(setq auto-mode-alist
(append '(
;; ("\\.pl?\\'" . 'prolog-mode) ; SWI Prolog
;; pl files in *prolog* dir are Prolog files
("prolog.*\\.pl?\\'" . prolog-mode) ; SWI Prolog
("\\.[Pp][Rr][Oo]\\'" . prolog-mode)
("\\.ari\\'" . prolog-mode) ; Arity Prolog
)
auto-mode-alist))
;; Resolve file extension conflict between Octave and Mercury Prolog
;; in favor of Mercury Prolog
;; (add-to-list 'auto-mode-alist '("\\.m\\'" . octave-mode))
(add-to-list 'auto-mode-alist '("\\.m\\'" . mercury-mode))
(add-hook
'prolog-mode-hook
(lambda ()
(require 'prolog)
(setq prolog-system 'swi)
(define-key prolog-mode-map [(control f1)]
(lambda () (interactive) (my-search-prolog-doc-at-point)))
;;(fset 'prolog-add-predicate-comment
;; [C-f5 up up ?\M-3 ?% ? ?\M-2 C-right ?\C-k ?\C-m ?\M-2 ?% ? ? ])
(fset 'prolog-add-predicate-comment
[?\C-n ?\C-o C-f5 ?\C-a up ?\M-3 ?% ? ?\M-2 C-right ?\C-k ?\C-m ?\M-2 ?% ? ? ])
(define-key prolog-mode-map "\C-zic" 'prolog-add-predicate-comment)
;; (define-key prolog-mode-map "\C-zic"
;; (lambda () (interactive) (end-of-line) (insert-string " :- ")))
;; (define-key prolog-mode-map "\C-zi,"
;; (lambda () (interactive) (end-of-line) (insert-string ", ")))
;; (define-key prolog-mode-map "\C-zi."
;; (lambda () (interactive) (end-of-line) (insert-string ".") (newline)))
;; (defun prolog-outline-level () (- 4 (outline-level)))
(setq-local outline-regexp "%%%+")
(setq-local outline-level (lambda () (- 5 (outline-level))))
;; (setq outline-level 'prolog-outline-level)
;; global-font-lock-mode doesn't work with prolog.el, but works with prolog2.el
;; (font-lock-mode 1)
))
(add-hook
'prolog-inferior-mode-hook
(lambda ()
;; (setq comint-input-ring-file-name "~/.pl_history")
;; (comint-read-input-ring t)
;; THIS CAUSED TRANSIENT-MODE NOT-WORKING !!!
;; -> (add-hook 'pre-command-hook 'comint-write-input-ring)
(define-key prolog-inferior-mode-map [(control f1)]
(lambda () (interactive) (my-search-prolog-doc-at-point)))
(define-key prolog-inferior-mode-map "\C-zo" 'comint-kill-output-since-last-prompt)
(setq-local outline-regexp "^[1-9][0-9]* \\?- ")
(setq-local outline-level (lambda () 1))))
(defun my-search-prolog-doc-at-point ()
(let* (;;(wordchars "a-zA-Z_0-9")
(str
(concat "\^L\n\n"
(current-word)
;; (buffer-substring-no-properties
;; (save-excursion (skip-chars-backward wordchars) (point))
;; (save-excursion (skip-chars-forward wordchars) (point)))
"(")))
(view-file "~/doc/prog/prolog/PROLOG")
;; (setq-local outline-regexp "^\\(Chapter [0-9]\\|\\)")
;; (make-local-variable 'outline-level)
(if (not (re-search-forward str nil t))
(progn
(goto-char (point-min))
(re-search-forward str nil t)))
(outline-show-entry) ;?
(message "%s" str)))
;; for PROLOG manual:
;; outline-regexp: "Chapter\\|[0-9]\\.[0-9]+ .....\\|[0-9]+\\.[0-9]+\\.[0-9]+ ....."
;; outline-level: outline-level-for-prolog-manual
;; mode: outline-minor
;; (setq outline-regexp "Chapter\\|[0-9]+\\.[0-9]+ .....\\|[0-9]+\\.[0-9]+\\.[0-9]+ .....")
;; (setq outline-level (lambda ()
;; (save-excursion
;; (cond
;; ((looking-at "Chapter") 1)
;; ((looking-at "[0-9]+\\.[0-9]+ ") 2)
;; ((looking-at "[0-9]+\\.[0-9]+\\.[0-9]+ ") 3)))))
;; (defun outline-level-for-prolog-manual ()
;; (save-excursion
;; (cond
;; ((looking-at "Chapter") 1)
;; ((looking-at "[0-9]+\\.[0-9]+ ") 2)
;; ((looking-at "[0-9]+\\.[0-9]+\\.[0-9]+ ") 3))))
;;; erlang
;; TODO: for Yaws templates use mumamo with erlang-mode and html-mode
(add-to-list 'auto-mode-alist '("\\.yaws\\'" . erlang-mode))
(with-eval-after-load 'erlang
(setq erlang-inferior-shell-split-window nil)
(add-hook 'erlang-mode-hook
(lambda ()
(setq tab-width 2)
(alchemist-mode 1))))
(add-to-list 'auto-mode-alist '("\\.eex\\'" . html-erb-mode))
(with-eval-after-load 'alchemist
;; (global-company-mode)
;; (define-key elixir-mode-map "\M-\t" 'company-complete)
;; (define-key company-active-map [escape] 'company-abort)
)
;;; haskell
;; also qv comment in (qv "files.el" "^(defvar interpreter-mode-alist")
(add-to-list 'interpreter-mode-alist '("runhugs" . literate-haskell-mode))
;;; html
(add-to-list 'auto-mode-alist '("\\.mustache\\'" . html-mode))
(add-to-list 'auto-mode-alist '("\\.ejs\\'" . html-mode))
;; These are needed to set before loading sgml-mode.el:
;; (setq sgml-quick-keys t)
(with-eval-after-load 'sgml-mode
(setq html-quick-keys t)
(defvar sgml-mode-syntax-table)
(modify-syntax-entry ?. "." sgml-mode-syntax-table)
(modify-syntax-entry ?: "." sgml-mode-syntax-table)
(defvar html-tag-face-alist)
(setq html-tag-face-alist (append '(("a" . underline))
html-tag-face-alist)))
(with-eval-after-load 'sgml-mode
(define-skeleton html-headline-1
"HTML level 1 headline tags."
nil
"<h1><a name=\"" (setq str (read-string "Name: "))
"\" id=\"" str "\">" _ "</a></h1>")
(define-skeleton html-headline-2
"HTML level 2 headline tags."
nil
"<h2><a name=\"" (setq str (read-string "Name: "))
"\" id=\"" str "\">" _ "</a></h2>"))
(add-hook 'html-mode-hook 'turn-off-auto-fill)
(add-hook 'html-mode-hook
(lambda ()
;; (define-key html-mode-map [?\x8a0] (lambda))
(define-key html-mode-map "\C-c&" 'sgml-name-char)
;; (define-key html-mode-map "\C-z" my-map)
))
(add-hook 'html-mode-hook
(lambda ()
;; Because `sgml-mode' overrides the user customization
;; sgml-xml-mode=t with the value from `sgml-xml-guess'.
(setq sgml-xml-mode t)
))
(defvar my-auto-insert-html-mode-language "en")
(add-to-list
'auto-insert-alist
'(html-mode
nil
(when (string-match "\\.\\([^.][^.]\\)\\.html$" buffer-file-name)
(setq my-auto-insert-html-mode-language
(match-string 1 buffer-file-name))
"")
;; "<?xml version=\"1.0\" encoding=\""
;; (if (equal my-auto-insert-html-mode-language "ru") "KOI8-R" "ISO-8859-1")
;; "\"?>\n"
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\""
my-auto-insert-html-mode-language "\" lang=\""
my-auto-insert-html-mode-language "\">\n"
"<head>\n"
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset="
(if (equal my-auto-insert-html-mode-language "ru") "koi8-r" "iso-8859-1")
"\" />\n"
"<meta http-equiv=\"Content-Language\" content=\""
my-auto-insert-html-mode-language "\" />\n"
"<meta name=\"description\" content=\"\" />\n"
"<meta name=\"keywords\" content=\"\" />\n"
"<title>" (capitalize (setq str (downcase (read-string "Title: ")))) "</title>\n"
"<link rel=\"stylesheet\" type=\"text/css\" href=\"/jurta.css\" />\n"
"</head>\n"
"<body>\n<h1><a name=\"" str "\" id=\"" str "\">" str "</a></h1>\n"
_
"\n"
"</body>\n"
"</html>\n"))
;;; htmlize
;; (global-set-key [print] 'htmlize-buffer)
(global-set-key [print] 'htmlfontify-buffer)
;;; web development
(with-eval-after-load 'cc-mode
(add-hook 'java-mode-hook
(lambda ()
(setq tab-width 4))))
(with-eval-after-load 'css-mode
(add-hook 'css-mode-hook
(lambda ()
(setq tab-width 2))))
(with-eval-after-load 'js
(add-hook 'js-mode-hook
(lambda ()
(setq js-indent-level 2)
(setq tab-width 2))))
;; (defvar ruby-use-smie nil)
(with-eval-after-load 'ruby-mode
;; (setq ruby-use-smie nil)
(define-key ruby-mode-map [(control left)] 'ruby-backward-sexp)
(define-key ruby-mode-map [(control right)] 'ruby-forward-sexp)
(when delete-selection-mode
(put 'ruby-end-return 'delete-selection t)
(put 'ruby-end-space 'delete-selection t))
(add-hook 'ruby-mode-hook
(lambda ()
(setq-local require-final-newline nil)
;; Don't enable flymake-mode in read-only buffers
(flymake-mode 1)
(add-hook 'view-mode-hook
(lambda ()
(flymake-mode (if view-mode -1 1)))
nil t))))