-
Notifications
You must be signed in to change notification settings - Fork 0
/
emacs-common.el
3915 lines (3225 loc) · 149 KB
/
emacs-common.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-common -- Pascal J. Bourguignon's emacs startup files.
;;; -*- mode:emacs-lisp;lexical-binding:t;coding:utf-8; -*-
;;; Commentary:
;;; Code:
;;;;
;;;; Pascal J. Bourguignon's emacs startup file.
;;;;
;;;; We only run GNU emacs.
;;;;
;;; Code:
;; Emacs Makes All Computing Simple.
;; Eine Is Not Emacs.
;; Zwei Was Eine Initially.
;; Drei Ressembled Emacs Intelligently.
;; Vier Integrates Emacs Regexps.
;; Vier Is Emacs Rewritten.
;; Vier Improves Eine's Revisions.
;; Fünf Überly New Framework.
;; Sechs Sechs Emacs Can Handle Strings.
;; Sieben Is Even Better Emacs Now
;; Acht Can Handle Text.
;; Neun Emacs Usually .
;; Zehn Emacs Handles News.
;; Hemlock Emacs Made Laughically Overly Capably Kidding.
;; Climacs Common Lisp Interface Manager Application Creating Sources.
;; Mince Is Not Complete Emacs.
;; FRED Resembles Emacs Deliberately
(when (= (user-uid) 0)
;; (load "/root/.emacs" pjb:*load-noerror* pjb:*load-silent*)
;; (error "~/.emacs: Cannot load ~/.emacs under root account.")
(set-face-background 'fringe "red"))
;; tramp hops: /ssh:bird@bastion|ssh:you@remotehost:/path
;; tramp hops: /ssh:you@remotehost:/path
;;;----------------------------------------------------------------------------
;;; Start up.
;;;----------------------------------------------------------------------------
(setq-default lexical-binding t)
(setq byte-compile-warnings '(not obsolete))
(defvar *emacs-start-time* (current-time) "For (emacs-uptime).")
(require 'cl)
(defun first-existing-file (list-of-files)
"Find the first file in LIST-OF-FILES that exists."
(find-if (lambda (file) (and file (file-exists-p file))) list-of-files))
(setq source-directory
(first-existing-file (list (format "/usr/local/src/emacs-%s/src" emacs-version)
(format "/opt/local/src/emacs-%s/src" emacs-version)
(expand-file-name (format "~/opt/src/emacs-%s/src" emacs-version)))))
;;;----------------------------------------------------------------------------
;;; Message Log
;;;----------------------------------------------------------------------------
(defvar *pjb-load-noerror* t)
(defvar *pjb-load-silent* nil)
(defvar *pjb-light-emacs* nil "pjb-loader will load the minimum.")
(defvar *pjb-pvs-is-running* (and (boundp 'x-resource-name)
(string-equal x-resource-name "pvs")))
(defvar shell-file-name "/bin/bash")
(defvar *tempdir* (format "/tmp/emacs%d" (user-uid)))
(defvar *rundir* (format "/run/emacs/%d" (user-uid)))
(defvar *pjb-save-log-file-p* nil "Whether .EMACS must save logs to /tmp/messages.txt")
(defun .EMACS (fctl &rest args)
(when (file-exists-p "--version.lock")
(message "Deleting version lock!")
(delete-file "--version.lock"))
;; (if (file-exists-p "--version.lock")
;; (error "version lock"))
(let ((text (apply (function format) (concat ".EMACS: " fctl) args)))
(when *pjb-save-log-file-p*
(with-current-buffer (get-buffer-create " .EMACS temporary buffer")
(erase-buffer)
(insert text "\n")
(append-to-file (point-min) (point-max) (format "%s/messages.txt" *tempdir*))))
(message text)))
(.EMACS "~/rc/emacs-common.el %s" "Pascal J. Bourguignon's emacs startup file.")
(load "~/rc/emacs-package.el")
;;;----------------------------------------------------------------------------
;;; Life saver
;;;----------------------------------------------------------------------------
;;; Essential configuration I want to have even when .emacs breaks.
;;;
(.EMACS "REQUIRE CL...")
(require 'cl)
(require 'parse-time)
(require 'tramp nil t)
(require 'cc-mode)
(require 'bytecomp)
(when (fboundp 'byte-compile-disable-warning)
(byte-compile-disable-warning 'cl-functions))
(when (boundp 'byte-compile-warning-types)
(setq byte-compile-warning-types (remove 'cl-functions byte-compile-warning-types)))
;; byte-compile-warning-types
;; (redefine callargs free-vars unresolved obsolete noruntime cl-functions interactive-only make-local mapcar constants suspicious lexical)
;; byte-compile-warnings
;; (not cl-functions)
(require 'tramp-sh nil t)
;; (defvar tramp-ssh-controlmaster-options "")
;; -o SendEnv has become useless since now OpenSSH filters them in the server configuration.
;; (setf tramp-ssh-controlmaster-options (concat "-o 'SendEnv TRAMP=yes' -o 'SendEnv TERM=dumb' " tramp-ssh-controlmaster-options))
(setf shell-prompt-pattern "^[^#$%>\n]*[#$%>] *")
(setf shell-prompt-pattern "^\\[.*\\][#$%>] *")
(setf tramp-shell-prompt-pattern "\\(?:^\\|\r\\)[^]#$%>\n]*#?[]#$%>].* *\\(\e\\[[0-9;]*[a-zA-Z] *\\)*")
;; (setf tramp-shell-prompt-pattern shell-prompt-pattern)
(.EMACS "STARTING...")
(mapc (lambda (f) (when (fboundp (car f)) (apply (function funcall) f)))
'((scroll-bar-mode -1)
(menu-bar-mode -1)
(tool-bar-mode -1)
(transient-mark-mode +1)
(goto-address-mode +1)))
;; (progn (scroll-bar-mode -1) (menu-bar-mode -1) (tool-bar-mode -1) (transient-mark-mode +1))
(defun mac-adjust-full-screen ()
(interactive)
(tool-bar-mode +1)
(tool-bar-mode -1)
(ff -1))
(defun mac-vnc-keys ()
(interactive)
(setf mac-command-modifier 'alt ; emacsformacosx
mac-option-modifier 'meta
one-buffer-one-frame nil)
(setf mac-command-key-is-meta nil ; which emacs?
mac-reverse-ctrl-meta nil))
(defun mac-vanilla-keys ()
(interactive)
(setf mac-command-modifier 'meta ; emacsformacosx
mac-option-modifier 'alt
one-buffer-one-frame nil)
(setf mac-command-key-is-meta t ; which emacs?
mac-reverse-ctrl-meta nil))
;; MacOSX Modifiers:
;; C-
;; S- S-
;; C- A- M- SPC M- A- C-p C-
(when (or (boundp 'aquamacs-version) (eq window-system 'ns))
(mac-vanilla-keys)
;; (if 'thru-vnc
;; (mac-vnc-keys)
;; (mac-vanilla-keys))
(cua-mode 0))
(when (boundp 'x-toolkit-scroll-bars)
(setf x-toolkit-scroll-bars nil))
;;;----------------------------------------------------------------------------
(defvar *lac-functions* '()
"A list of functions to be called after elpa is loaded.
please, use `add-lac' and `remove-lac' instead of accessing this list directly.")
(defun add-lac (&rest lac-functions)
(setf *lac-functions* (union lac-functions *lac-functions*)))
(defun remove-lac (&rest lac-functions)
(setf *lac-functions* (set-difference *lac-functions* lac-functions)))
(defun run-lac-functions ()
"Runs each lac function in *lac-functions*."
(interactive)
(dolist (lac *lac-functions*)
(ignore-errors (funcall lac))))
;;;----------------------------------------------------------------------------
(when t
(.EMACS "emacs-major-version = %S" emacs-major-version)
(.EMACS "emacs-minor-version = %S" emacs-minor-version)
(.EMACS "emacs-version = %S" emacs-version)
(.EMACS "system-type = %S" system-type)
(.EMACS "system-name = %S" system-name)
(.EMACS "system-configuration = %S" system-configuration)
(.EMACS "window-system = %S" window-system)
(when (boundp 'aquamacs-version)
(.EMACS "aquamacs-version = %S" aquamacs-version)))
;; (window-system system-type system-configuration system-name)
;; (emacs-major-version emacs-minor-version emacs-version)
;; system-type darwin gnu/linux cygwin windows-nt
;; system-name "naiad.informatimago.com" "hermes.afaa.asso.fr"
;; system-configuration "i686-pc-linux-gnu" "i686-pc-cygwin" "i386-apple-darwin9.8.0"
;; window-system nil x mac ns w32
;; emacs-major-version 18 19 20 21 23
;; emacs-minor-version 0 1 2 3
;; emacs-version "20.7.2" "21.2.1"
;; NO emacs-type! We won't run on anything else than GNU emacs.
;; window-system ==> (display-multi-frame-p)
;; xterm-mouse-mode ;; To use the mouse inside xterm!
(.EMACS "enabling features")
(put 'narrow-to-region 'disabled nil)
(put 'narrow-to-page 'disabled nil)
(put 'downcase-region 'disabled nil)
(put 'upcase-region 'disabled nil)
(put 'mh-rmail 'disabled t)
(put 'scroll-left 'disabled nil)
(put 'set-goal-column 'disabled t)
(put 'erase-buffer 'disabled nil)
(display-time-mode 1)
(set-default-file-modes #o755)
(setf open-paren-in-column-0-is-defun-start nil)
(setf minibuffer-max-depth nil)
(setf print-circle t
print-quoted t)
(require 'server)
(with-temp-buffer
(insert (format "export EMACS_SERVER_FILE=%s/%s\n"
server-socket-dir
server-name))
(write-file (format "~/.bash_env-emacs-%s" (hostname)) nil))
(server-start)
;; server-socket-dir
;; ;; --> "/var/folders/pq/82920zm125n09frk81rrtp200000gn/T/emacs501"
;; server-name
;; ;; --> "server"
;; (setf server-socket-dir *tempdir*
;; server-name (format "server-%d" (emacs-pid)))
;;
;; (setf server-socket-dir (if internal--daemon-sockname
;; (file-name-directory internal--daemon-sockname)
;; (and (featurep 'make-network-process '(:family local))
;; (let ((xdg_runtime_dir (getenv "XDG_RUNTIME_DIR")))
;; (if xdg_runtime_dir
;; (format "%s/emacs" xdg_runtime_dir)
;; (format "%s/emacs%d" (or (getenv "TMPDIR") "/tmp") (user-uid))))))
;; server-name (if internal--daemon-sockname
;; (file-name-nondirectory internal--daemon-sockname)
;; "server"))
;; server-name "server"
;; server-socket-dir "/run/user/87743/emacs"
;; (getenv "XDG_RUNTIME_DIR") "/run/user/87743"
;; export EMACS_SERVER_FILE=/run/user/87743/emacs/server
(setf tetris-score-file "~/.tetris-scores")
(setf fancy-splash-text '(
(:face (variable-pitch :weight bold) "
WELCOME TO EMACS!
"
;; :face variable-pitch "Text"
;; :face (variable-pitch :weight bold :slant oblique) "Text"
;; :face variable-pitch function
)
(:face (variable-pitch :weight bold) "
-%- WELCOME TO EMACS -%-
")))
(setf fancy-splash-text nil)
(case system-type
((darwin)
(setf browse-url-netscape-program "/sw/bin/mozilla"
browse-url-firefox-program "/opt/local/bin/firefox"))
((gnu/linux)
(setf browse-url-netscape-program "/usr/local/apps/netscape-7.02/netscape"
browse-url-firefox-program "/usr/bin/firefox")))
(setf visible-bell nil)
(when (eq window-system 'x)
(setf ring-bell-function
(lambda ()
(call-process-shell-command "xset led;sleep 0.1;xset -led;sleep 0.05;xset led;sleep 0.1;xset -led;sleep 0.05;xset led;sleep 0.2;xset -led" nil 0 nil))))
;;;----------------------------------------------------------------------------
;;; Language & character encoding stuff:
;;;----------------------------------------------------------------------------
;; (standard-display-european 1) ;;is semi-obsolete, but it works better than:
;; (standard-display-8bit 128 255)
(set-input-mode nil nil t nil) ;; INTERRUPT FLOW META [QUIT]
;; (setq meta-prefix-char nil) ; to split ESC from M-
(when (fboundp 'unify-8859-on-encoding-mode)
(unify-8859-on-encoding-mode 1))
(when (fboundp 'unify-8859-on-decoding-mode)
(unify-8859-on-decoding-mode 1))
(setq default-enable-multibyte-characters t
unibyte-display-via-language-environment nil)
;; (setq my-latin (if (assoc-ignore-case "Latin-9" language-info-alist) 9 1))
;; ;; For coding-system we don't specify *-unix to allow it to load DOS files.
;; (cond
;; ((= my-latin 1) (setq my-lenv "Latin-1"
;; my-encoding 'iso-8859-1
;; x-encoding "iso8859-1"))
;; ((= my-latin 9) (setq my-lenv "Latin-9"
;; my-encoding 'iso-8859-15
;; x-encoding "iso8859-15"))
;; (t (error "Invalid value for my-latin variable.")))
(unless (fboundp 'digit-char-p)
(defun digit-char-p (ch)
"Return the value of the digit if ch is a digit character, or nil."
(case ch
((?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9) (- ch ?0))
(otherwise nil))))
(progn
(case system-type
(darwin
(set-language-environment "utf-8")
(prefer-coding-system 'utf-8-unix)
;; prefer-coding-system does the 3 following:
;; (set-file-name-coding-system 'utf-8-unix)
;; (set-keyboard-coding-system 'utf-8-unix)
;; (set-terminal-coding-system 'utf-8-unix)
(set-clipboard-coding-system 'utf-8-unix)
(set-selection-coding-system 'utf-8-unix)
(set-next-selection-coding-system 'utf-8-unix)
;; (set-buffer-file-coding-system 'utf-8-unix)
;; (set-buffer-process-coding-system 'utf-8-unix)
(setq default-buffer-file-coding-system 'utf-8-unix
default-file-name-coding-system 'utf-8-unix
default-terminal-coding-system 'utf-8-unix
default-keyboard-coding-system 'utf-8-unix
default-sendmail-coding-system 'utf-8-unix
default-process-coding-system '(utf-8-unix . utf-8-unix))
(modify-coding-system-alist 'process ".*shell\\'" 'utf-8-unix)
(modify-coding-system-alist 'process "\\*shell\\*\\'" 'utf-8-unix)
(modify-coding-system-alist 'process ".*lisp\\'" 'utf-8-unix))
(otherwise
(set-language-environment "utf-8")
(prefer-coding-system 'utf-8-unix)
(set-default-coding-systems 'utf-8-unix)
(set-keyboard-coding-system 'utf-8-unix) ; 'iso-8859-1-unix)
(set-terminal-coding-system 'utf-8-unix) ; 'iso-8859-1-unix)
(set-clipboard-coding-system 'utf-8-unix)
(set-selection-coding-system 'utf-8-unix)
(setq default-buffer-file-coding-system 'utf-8-unix
default-file-name-coding-system 'utf-8-unix
default-terminal-coding-system 'utf-8-unix ; 'iso-8859-1-unix
default-keyboard-coding-system 'utf-8-unix ; 'iso-8859-1-unix
default-sendmail-coding-system 'utf-8-unix
default-process-coding-system '(utf-8-unix . utf-8-unix))
(modify-coding-system-alist 'process ".*shell\\'" 'utf-8-unix)
(modify-coding-system-alist 'process "\\*shell\\*\\'" 'utf-8-unix)
(modify-coding-system-alist 'process ".*lisp\\'" 'utf-8-unix)))
(dolist (cs coding-system-list nil)
(modify-coding-system-alist 'file (format "\\.%s\\'" cs) cs)))
;; and/or set locales like LC_ALL, LC_CTYPE, LANG to contain UTF-8 as for
;; example: LANG=de_DE.UTF-8. Modern Emacsen, I think 21.3 at least,
;; derive their mode of operation from this.
;; You can start your text files à la: ;;; -*- mode: Text; coding: utf-8 -*-
;; Once you've done that you can C-x RET r:
;; revert-buffer-with-coding-system.
;; (set-language-environment 'German)
;; (setq default-file-name-coding-system 'utf-8)
;; (setq file-name-coding-system 'utf-8)
;; (setq default-buffer-file-coding-system 'iso-latin-9-unix))
;; (set-default-coding-systems 'mac-roman-unix)
;; ;(setq mac-keyboard-text-encoding kTextEncodingISOLatin1)
;; (set-keyboard-coding-system 'sjis-mac)
;; (set-clipboard-coding-system 'sjis-mac)
;; (prefer-coding-system 'mac-roman-unix)
;; (modify-coding-system-alist 'file "\\.tex\\'" 'iso-latin-9-unix)
;; (modify-coding-system-alist 'process
;; "\\*[Ss][Hh][Ee][Ll][Ll].*\\'" 'utf-8-unix)
;; ;(set-buffer-process-coding-system 'utf-8 'utf8)
(standard-display-ascii #o200 (vector (decode-char 'ucs #x253c)))
(standard-display-ascii #o201 (vector (decode-char 'ucs #x251c)))
(standard-display-ascii #o202 (vector (decode-char 'ucs #x252c)))
(standard-display-ascii #o203 (vector (decode-char 'ucs #x250c)))
(standard-display-ascii #o204 (vector (decode-char 'ucs #x2524)))
(standard-display-ascii #o205 (vector (decode-char 'ucs #x2502)))
(standard-display-ascii #o206 (vector (decode-char 'ucs #x2510)))
(standard-display-ascii #o210 (vector (decode-char 'ucs #x2534)))
(standard-display-ascii #o211 (vector (decode-char 'ucs #x2514)))
(standard-display-ascii #o212 (vector (decode-char 'ucs #x2500)))
(standard-display-ascii #o214 (vector (decode-char 'ucs #x2518)))
(standard-display-ascii #o220 [?\ ])
(standard-display-ascii #o221 [?\` ])
(standard-display-ascii #o222 [?\'])
(standard-display-ascii #o223 [?\"])
(standard-display-ascii #o224 [?\"])
(standard-display-ascii #o225 "* ")
(standard-display-ascii #o226 "--")
(standard-display-ascii #o227 " -- ")
;;;----------------------------------------------------------------------------
;;; Setting up load-path & exec-path
;;;----------------------------------------------------------------------------
;;;
;;; When we start, emacs has already filled load-path with
;;; installation-local directories.
;;;
;;; So we only need to add the directories of specific packages (that
;;; could be used in the various emacs installations). It also means
;;; that installing an emacs package must occur either in an emacs
;;; specific installation (notably if .elc are compiled for this
;;; specific version), or in the package specific directory.
;;;
;;; If any of these directories contain one of the site or subdir el
;;; files, then it is loaded too.
;;;
(defun print-load-path ()
"Insert the paths in load-path one per line."
(interactive)
(dolist (x load-path)
(princ x)
(terpri)))
(defalias 'dump-load-path 'print-load-path)
(defun clean-path (path)
"Clean the paths in `load-path'.
- Remove slashes at the end of the path in load-path.
- Expand ~/.
- Remove double-slashes in the paths."
(expand-file-name (if (string-match "^\\(.*[^/]\\)/*$" path)
(match-string 1 path)
path)))
(defun clean-load-path ()
"Clean the paths in `load-path' and remove duplicates."
(setf load-path (remove-duplicates
(mapcar (function clean-path) load-path)
:test (function string=))))
(defun add-to-load-path (path)
(push path load-path)
(clean-load-path))
(defun load-pathname (file &optional nosuffix must-suffix)
"Return the pathname of the file that would be loaded by (load file)."
(let* ((file (substitute-in-file-name file))
(size (length file)))
(unless (zerop size)
(when (and must-suffix
(or (and (< 3 size) (string= ".el" (substring file (- size 3))))
(and (< 4 size) (string= ".elc" (substring file (- size 4))))
(file-name-directory file)))
(setf must-suffix nil))
(if (fboundp 'locate-file-internal)
(locate-file-internal file
load-path
(cond (nosuffix '())
(must-suffix (get-load-suffixes))
(t (append (get-load-suffixes)
load-file-rep-suffixes)))
nil)
(error "Missing locate-file-internal in version %s" emacs-version)
;; (let ((suffixes (append (get-load-suffixes) "")))
;; (dolist (dir load-path)
;; (dolist (suffix suffixes)
;; (format "%s/%s%s" dir file suffix))))
))))
(defun pjb-setup-load-path ()
"Set up my load-path."
(let ((new-paths '())
(base-load-path (copy-list load-path)))
(flet ((add-if-good (site-lisp)
(let ((site-lisp (expand-file-name site-lisp)))
(when (file-exists-p site-lisp)
(pushnew site-lisp new-paths)
(mapc (lambda (file)
(let ((file (concat site-lisp "/" file)))
(when (file-exists-p file)
(let ((default-directory site-lisp))
(.EMACS "%s FOUND" file)
(load file)))))
'("site-start.el" "site-gentoo.el" "subdirs.el"))
t))))
(dolist (directories (append
(list
;; -----------------
;; PJB emacs sources
;; -----------------
;; Since we may have several emacs version running
;; on the same system, for now we will avoid
;; compiling pjb sources, and we will load them
;; directly from ~/src/public/emacs/. Later we
;; will see how we can install elc in version
;; specific directories, but keeping references to
;; the same source directory.
;; (get-directory :share-lisp "packages/com/informatimago/emacs")
'("~/src/public/emacs")
'("~/.emacs.d/site-lisp"))
'(("/opt/lisp/emacs")
("/opt/share/emacs/site-lisp")
("/opt/local/share/emacs/site-lisp")
("/usr/local/share/emacs/site-lisp")
("/usr/share/emacs/site-lisp"))))
(if (listp directories)
(find-if (function add-if-good) directories)
(add-if-good directories)))
(setf load-path (append new-paths
(set-difference load-path base-load-path :test (function equal))
base-load-path)))))
(.EMACS "Loading my personal files -- My own stuff.")
(pjb-setup-load-path)
(load "~/rc/emacs-directories")
(unless (load "pjb-loader.el")
(.EMACS "ERROR: Could not find and load 'My own stuff'!"))
(defun pjb-setup-exec-path ()
(map-existing-files (lambda (dir) (pushnew dir exec-path))
(list (expand-file-name "~/bin/")
(expand-file-name "~/opt/bin/")
"/sw/sbin/" "/sw/bin/"
"/usr/local/sbin" "/usr/local/bin"
"/opt/local/sbin" "/opt/local/bin"))
(setf (getenv "PATH") (mapconcat (function identity) exec-path ":")))
(pjb-setup-exec-path)
(setf *pjb-tab-width-alist*
'(("^/Applications/Emacs.app/Contents/Resources/" . 8)
("^/usr/local/src/ccl-.*/" . 8)
("^/usr/local/src/emacs-.*/" . 8)
("/pjb/works/mts/Harag/" . 8)))
;;------------------------------------------------------------------------
(unless (let ((hostname (hostname)))
(and (< 2 (length hostname))
(string= "fr" (subseq hostname 0 2))))
;; not "frprld7818008" "frdark", etc
(.EMACS "setting up fonts")
(load "~/rc/emacs-font.el"))
;;------------------------------------------------------------------------
;; (message "old load-path = %S" (with-output-to-string (dump-load-path)))
;; (message "new load-path = %S" (with-output-to-string (dump-load-path)))
;; (autoload 'd-mode "/usr/local/src/languages/clisp/clisp-cvs/clisp/emacs/d-mode"
;; "Mode to edit clisp sources." t)
(deletef auto-mode-alist 'd-mode :key (function cdr))
;; (setq auto-mode-alist (append '(("\\.c\\'" . c-mode)) auto-mode-alist))
(appendf auto-mode-alist '(("\\.pp\\'" . pascal-mode)
("\\.\\(m[id]\\|mod\\|def\\)$" . modula-2-mode)
("-MIB$\\|-SMI$" . snmp-mode)
("\\.bison\\'" . c-mode)
("\\.lex\\'" . c-mode)
("\\.d\\'" . makefile-mode)))
(appendf auto-mode-alist '(("\\.jmf$" . java-mode)
("\\.j$" . java-mode)))
(appendf auto-mode-alist '(("\\.pl1$" . pl1-mode)))
(appendf auto-mode-alist '(("\\.html\\.in$" . html-mode)))
;;;----------------------------------------------------------------------------
;;; Other packages.
;;;----------------------------------------------------------------------------
(require 'epa-file)
(epa-file-enable)
(require 'highlight-flet nil t)
(require 'rst nil t)
(require 'rst-mode nil t)
(when window-system
(mouse-avoidance-mode 'cat-and-mouse))
;;;----------------------------------------------------------------------------
;;; CEDET / EIEIO
;;;----------------------------------------------------------------------------
(when (and nil
(require 'eieio nil t)
(require 'cedet nil t))
;; Enabling various SEMANTIC minor modes. See semantic/INSTALL for more ideas.
;; Select one of the following:
;; * This enables the database and idle reparse engines
;;(semantic-load-enable-minimum-features)
;; * This enables some tools useful for coding, such as summary mode
;; imenu support, and the semantic navigator
;; (semantic-load-enable-code-helpers)
;; * This enables even more coding tools such as the nascent intellisense mode
;; decoration mode, and stickyfunc mode (plus regular code helpers)
;; (semantic-load-enable-guady-code-helpers)
;; * This turns on which-func support (Plus all other code helpers)
;; (semantic-load-enable-excessive-code-helpers)
;; This turns on modes that aid in grammar writing and semantic tool
;; development. It does not enable any other features such as code
;; helpers above.
;; (semantic-load-enable-semantic-debugging-helpers)
(setf eieio-skip-typecheck t))
;;;----------------------------------------------------------------------------
;;; Emacs-CL
;;;----------------------------------------------------------------------------
(defvar *pjb-emacs-cl-present-p* nil)
;; We cannot load old emacs-cl in emacs-24 with lexical-binding, since
;; it overrides new emacs functions.
;; (when (load "load-cl" t)
;; (setf *pjb-emacs-cl-present-p* t)
;; (message "emacs-cl streams = %S" (list *STANDARD-INPUT*
;; *STANDARD-OUTPUT*
;; *TERMINAL-IO*))
;; (let ((stream (make-buffer-output-stream "*scratch*")))
;; (setf *STANDARD-INPUT* stream
;; *STANDARD-OUTPUT* stream
;; *TERMINAL-IO* stream)))
;;;----------------------------------------------------------------------------
;;; On Macintosh
;;;----------------------------------------------------------------------------
(when (or (boundp 'aquamacs-version)
(eq window-system 'ns))
(setf initial-frame-alist '((background-color . "#ddffee")
(left . 76)
(top . 20)
(width . 80)
(height . 60))
default-frame-alist (append initial-frame-alist default-frame-alist)
cursor-type 'box)
(when (fboundp 'smart-frame-positioning-mode)
(smart-frame-positioning-mode nil))
(when (load "scroll-bar" nil t)
(defun scroll-bar-columns (side)
"Return the width, measured in columns, of the vertical scrollbar on SIDE.
SIDE must be the symbol `left' or `right'."
(let* ((wsb (window-scroll-bars))
(vtype (nth 2 wsb))
(cols (nth 1 wsb)))
(cond
((not (memq side '(left right nil)))
(error "`left' or `right' expected instead of %S" side))
((and (eq vtype side) cols))
((eq (frame-parameter nil 'vertical-scroll-bars) side)
;; nil means it's a non-toolkit scroll bar, and its width in
;; columns is 14 pixels rounded up.
(ceiling (or (frame-parameter nil 'scroll-bar-width) 14)
(frame-char-width)))
(0))))))
;;;----------------------------------------------------------------------------
;;; Global key map
;;;----------------------------------------------------------------------------
(.EMACS "Setting global key map")
(when (< emacs-major-version 22)
;; feature simple is not provided on emacs < 22, so we use load-library:
(load-library "simple"))
(require 'iso-transl)
(define-key ctl-x-map "." nil)
(define-key iso-transl-ctl-x-8-map "E" [342604])
;; For control, there's no distinction between shift and plain!
;; The only control keys are: @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
;; \C-^ is free.
;; Cannot use \C-i because it's TAB
;; Cannot use \C-m because it's CR
;; Cannot use \C-[ because it's ESC!
;; Cannot use \C-{ or \C-} (no distinction between shift and plain)
;;
;; [?\C-c f5]
;; [(control c) f5]
;; (kbd "C-c <f5>")
;;
;; C-z is used now by elscreen.
(defun disabled ()
(interactive)
(beep))
(defun insert-sharp-brace ()
(interactive)
(insert "#[]")
(forward-char -1))
(defun reset-movement-keypad ()
"Locally set the keys <insert>, <suppr>, <home>, <end>, <prior> and <next>."
(interactive)
(local-set-key (kbd "<home>") 'beginning-of-buffer)
(local-set-key (kbd "<end>") 'end-of-buffer)
(local-set-key (kbd "<prior>") 'scroll-down)
(local-set-key (kbd "<next>") 'scroll-up)
(global-set-key (kbd "<home>") 'beginning-of-buffer)
(global-set-key (kbd "<end>") 'end-of-buffer)
(global-set-key (kbd "<prior>") 'scroll-down)
(global-set-key (kbd "<next>") 'scroll-up))
(defalias 'pjb-movement-keybindings 'reset-movement-keypad)
;; http://paste.lisp.org/display/10157
(defun swap-brackets-parens ()
(interactive)
(keyboard-translate ?\( ?\[)
(keyboard-translate ?\) ?\])
(keyboard-translate ?\[ ?\()
(keyboard-translate ?\] ?\)))
(defun normal-brackets-parens ()
(interactive)
(keyboard-translate ?\( ?\()
(keyboard-translate ?\) ?\))
(keyboard-translate ?\[ ?\[)
(keyboard-translate ?\] ?\]))
(defun translate-mac-keyboard ()
(interactive)
(keyboard-translate ?\§ ?\`)
(keyboard-translate ?\± ?\~))
(defun reset-keyboard ()
"Reset the X keyboard to PJB's preferences."
(interactive)
(shell-command "setxkbmap -layout us -option ctrl:nocaps -option caps:none -option shift:breaks_caps -option compose:lctrl"))
(defalias 'pjb-reset-keyboard 'reset-keyboard)
(global-set-key (kbd "<pause>") 'pjb-reset-keyboard)
(defmacro define-justification-functions (direction)
`(progn
(defun ,(intern (format "pjb-set-justification-%s" direction)) (start end)
(interactive "r")
(let ((mode major-mode))
(if (and start end (/= start end))
(save-excursion
(narrow-to-region start end)
(unwind-protect
(,(intern (format "set-justification-%s" direction)) start end)
(widden)
(funcall mode)))
(,(intern (format "set-justification-%s" direction)) start end))))
(defun ,(intern (format "pjb-force-set-justification-%s" direction)) (start end)
(interactive "r")
(let ((mode major-mode))
(save-excursion
(narrow-to-region start end)
(unwind-protect
(progn (text-mode)
(,(intern (format "set-justification-%s" direction)) start end))
(widden)
(funcall mode)))))))
(defun pjb-terminal-key-bindings ()
(interactive)
;; http://paste.lisp.org/display/131216
(global-set-key "OF" 'end-of-buffer)
(global-set-key "OH" 'beginning-of-buffer)
(global-set-key "" 'backward-delete-char-untabify)
(global-unset-key "[")
(global-set-key "[15~" 'set-justification-left) ; <f5>
(global-set-key "[17~" 'set-justification-center) ; <f6>
(global-set-key "[18~" 'set-justification-right) ; <f7>
(global-set-key "[19~" 'disabled) ; <f8>
(global-set-key "[20~" 'disabled) ; <f9>
(global-set-key "[21~" 'disabled) ; <f10>
(global-set-key "[23~" 'disabled) ; <f11>
(global-set-key "[24~" #'copilot-accept-completion-by-paragraph) ; <f12>
(define-key input-decode-map "\M-[A" [up])
(define-key input-decode-map "\M-[B" [down])
(define-key input-decode-map "\M-[C" [right])
(define-key input-decode-map "\M-[D" [left])
(define-key input-decode-map "\M-[1;5A" [C-up])
(define-key input-decode-map "\M-[1;5B" [C-down])
(define-key input-decode-map "\M-[1;5C" [C-right])
(define-key input-decode-map "\M-[1;5D" [C-left])
(define-key input-decode-map "\M-[1;3A" [M-up])
(define-key input-decode-map "\M-[1;3B" [M-down])
(define-key input-decode-map "\M-[1;3C" [M-right])
(define-key input-decode-map "\M-[1;3D" [M-left])
(define-key input-decode-map "\M-[1;9A" [M-up])
(define-key input-decode-map "\M-[1;9B" [M-down])
(define-key input-decode-map "\M-[1;9C" [M-right])
(define-key input-decode-map "\M-[1;9D" [M-left])
nil)
(defun russian (&optional alternate)
(interactive "P")
(set-input-method (if alternate
'russian-typewriter
'russian-computer)))
(defun chinese () (interactive) (set-input-method 'chinese-py-b5))
(defun greek () (interactive) (set-input-method 'greek))
(defun hebrew () (interactive) (set-input-method 'hebrew))
(defun pjb-global-key-bindings ()
(interactive)
(define-justification-functions left)
(define-justification-functions center)
(define-justification-functions right)
(define-justification-functions full)
;; Advance key map setting: get a sane keyboard when loading this file fails.
(global-set-key (kbd "C-x RET C-h") 'describe-prefix-bindings)
;; (global-set-key (kbd "C-x 5 o") 'other-frame-non-excluded)
(global-set-key (kbd "<home>") 'beginning-of-buffer)
(global-set-key (kbd "<end>") 'end-of-buffer)
(global-set-key (kbd "<prior>") 'scroll-down)
(global-set-key (kbd "<next>") 'scroll-up)
(global-set-key (kbd "A-<prior>") 'beginning-of-buffer)
(global-set-key (kbd "A-<next>") 'end-of-buffer)
(global-set-key (kbd "C-c C-s") 'search-forward-regexp)
(global-set-key (kbd "C-c C-r") 'search-backward-regexp)
(global-set-key (kbd "<f5>") 'pjb-set-justification-left)
(global-set-key (kbd "<f6>") 'pjb-set-justification-full)
(global-set-key (kbd "<f7>") 'pjb-set-justification-right)
(global-set-key (kbd "C-c <f5>") 'pjb-force-set-justification-left)
(global-set-key (kbd "C-c <f6>") 'pjb-force-set-justification-full)
(global-set-key (kbd "C-c <f7>") 'pjb-force-set-justification-right)
(global-set-key (kbd "M-g g") 'goto-char)
(global-set-key (kbd "<f8>") 'pjb-show-lisp-repl)
(global-set-key (kbd "C-<f8>") 'pjb-show-lisp-repl-jump-in)
(global-set-key (kbd "C-c .") 'forward-sexp)
(global-set-key (kbd "C-c ,") 'backward-sexp)
(global-set-key (kbd "C-x DEL") 'disabled)
(global-set-key (kbd "C-<delete>") 'disabled)
(global-set-key (kbd "C-<backspace>") 'disabled)
(global-set-key (kbd "A-x") 'insert-sharp-brace)
(global-set-key (kbd "M-[") 'insert-parentheses)
(global-set-key (kbd "M-]") 'move-past-close-and-reindent)
;; (global-set-key "\M-[" 'insert-parentheses)
;; (global-set-key "\M-]" 'move-past-close-and-reindent)
(global-set-key (kbd "C-<f9>") 'chinese)
(global-set-key (kbd "C-<f10>") 'russian)
(global-set-key (kbd "C-<f11>") 'greek)
(global-set-key (kbd "C-<f12>") 'hebrew)
;; (autoload 'hebr-switch "hebwork" "Toggle Hebrew mode.")
;; (global-set-key (kbd "C-<f12>") 'hebr-switch)
(when (and (fboundp 'pjb-search-backward-region)
(fboundp 'pjb-search-forward-region))
(global-set-key (kbd "<f9>") 'pjb-search-backward-region)
(global-set-key (kbd "<f10>") 'pjb-search-forward-region))
(when (and (fboundp 's2p-calculette)
(fboundp 's2p-calculette-to-lisp))
(global-set-key (kbd "C-c =") 's2p-calculette)
(global-set-key (kbd "C-c +") 's2p-calculette-to-lisp))
(global-set-key (kbd "C-c _") 'google-search-region)
(when (fboundp 'invoke-ding-dictionary)
(global-set-key (kbd "C-c -") 'invoke-ding-dictionary))
;; (delete-selection-mode t)
(if (fboundp 'delete-region-and-yank)
(global-set-key (kbd "C-y") 'delete-region-and-yank)
(global-set-key (kbd "C-y") 'yank))
;; A strange configuration with a narrow frame...
(when (< (frame-parameter (selected-frame) 'width) 42)
(global-set-key (kbd "C-h") 'backward-delete-char-untabify))
(case window-system
((nil)
(.EMACS "Setting terminal keyboard")
(pjb-terminal-key-bindings)
(set-keyboard-coding-system 'iso-8859-15)
(normal-erase-is-backspace-mode 0)
(.EMACS "C-h = %S" (key-binding "\C-h"))
(.EMACS "DEL = %S" (key-binding "\C-?")))
((x)
(.EMACS "Setting X keyboard")
(define-key global-map [(delete)] "\C-d")
(make-face-bold 'bold-italic))
((mac ns)
(.EMACS "Setting Macintosh keyboard")
(setq *window-manager-y-offset* (+ 24 24))
(set-keyboard-coding-system 'mac-roman)
(translate-mac-keyboard)))
(global-set-key (kbd "H-<up>") 'backward-same-indent)
(global-set-key (kbd "H-<down>") 'forward-same-indent)
(global-set-key (kbd "H-`") 'next-error)
(global-set-key (kbd "A-c") "ç")
(global-set-key (kbd "S-A-c") "Ç")
(global-set-key (kbd "¢") "ç")
(global-set-key (kbd "©") "Ç")
(progn
(define-key iso-transl-ctl-x-8-map (kbd "8") "∞")
(define-key iso-transl-ctl-x-8-map (kbd "<") nil)
(define-key iso-transl-ctl-x-8-map (kbd "< =") "≤")
(define-key iso-transl-ctl-x-8-map (kbd "< <") "«")
(define-key iso-transl-ctl-x-8-map (kbd "< >") "≶")
(define-key iso-transl-ctl-x-8-map (kbd ">") nil)
(define-key iso-transl-ctl-x-8-map (kbd "> =") "≥")
(define-key iso-transl-ctl-x-8-map (kbd "> >") "»")
(define-key iso-transl-ctl-x-8-map (kbd "^ -") "⁻")
(define-key iso-transl-ctl-x-8-map (kbd "^ +") "⁺")
(define-key iso-transl-ctl-x-8-map (kbd "^ 0") "⁰")
(define-key iso-transl-ctl-x-8-map (kbd "^ 4") "⁴")
(define-key iso-transl-ctl-x-8-map (kbd "^ 5") "⁵")
(define-key iso-transl-ctl-x-8-map (kbd "^ 6") "⁶")
(define-key iso-transl-ctl-x-8-map (kbd "^ 7") "⁷")