-
Notifications
You must be signed in to change notification settings - Fork 1
/
.emacs
2061 lines (1795 loc) · 88.6 KB
/
.emacs
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
;; dev packages: autoconf automake texinfo libgtk-3-dev libxpm-dev libjpeg-dev libgif-dev libtiff5-dev libgnutls28-dev librsvg2-dev libmagickwand-dev libxml2-dev libcairo2-dev libsystemd-dev libselinux1-dev libgpm-dev libgconf2-dev
(require 'cl)
;;{{{ Variables describing environment Emacs is running in
(defvar running-xemacs (string-match "XEmacs\\|Lucid" emacs-version))
(defvar running-on-windows (eq 'windows-nt system-type))
(defvar running-on-gnu/linux (string-equal system-type "gnu/linux"))
(defvar running-on-darwin (string-equal system-type "darwin"))
(defvar mule-present (featurep 'mule))
(defvar running-on-x (cond (running-xemacs (eq (console-type) 'x)) (t (eq window-system 'x))))
(defvar emacs-flavor
(concat (if running-xemacs "xemacs" "gnuemacs") "."
(int-to-string emacs-major-version) "."
(int-to-string emacs-minor-version)))
;;}}}
;;{{{ load-path setup
(defun package-dir (name)
(let* ((dir1 (file-expand-wildcards (concat custom-dir name)))
(dir2 (file-expand-wildcards (concat custom-dir "quelpa/**/" name)))
(dir3 (file-expand-wildcards (concat custom-dir "elpa/" name)))
(dirs (remove-if-not #'file-accessible-directory-p (append dir1 dir2 dir3)))
(dirp (car dirs)))
(message "Checking for %s pacakge: %s" name (if dirp dirp "not found"))
(when dirp (add-to-list 'load-path dirp))
dirp))
;; Store customization information in file specific for emacs version
(setq custom-dir (expand-file-name "~/.emacs.d/"))
(add-to-list 'load-path (concat custom-dir "/lisp"))
(setq custom-file (concat custom-dir "custom." emacs-flavor ".el"))
(setq recentf-save-file (concat custom-dir "/.recentf"))
;; Save Emacs state for next session.
(require 'saveplace)
(custom-set-variables '(save-place t) `(save-place-file ,(concat custom-dir "save-places")))
;;}}}
;; {{{ Setup ELPA repositories
(require 'package)
(unless (package-installed-p 'quelpa)
(with-temp-buffer
(url-insert-file-contents "https://github.com/quelpa/quelpa/raw/master/quelpa.el")
(eval-buffer)
(quelpa-self-upgrade)))
(require 'quelpa)
(when (>= emacs-major-version 28)
(quelpa '(eff :repo "oxidase/eff" :fetcher github)))
(add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/") t)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)
;; Guarantee all packages are installed on start
(defvar packages-list
'(adoc-mode ag arxiv-mode back-button bazel bitbake bm debian-el dired-single docker
dockerfile-mode elfeed ess fish-mode geiser google-c-style gptel impatient-mode lsp-mode magit
ob-html-chrome ob-http ob-mermaid openwith ox-reveal
protobuf-mode rainbow-mode simple-httpd string-inflection use-package web-mode yaml-mode)
"List of packages needs to be installed at launch")
(defun has-package-not-installed ()
(unless package--initialized
(package-initialize))
(cl-loop for p in packages-list
when (not (package-installed-p p)) do (cl-return t)
finally (cl-return nil)))
(when (has-package-not-installed)
;; Check for new packages (package versions)
(message "%s" "Get latest versions of all packages...")
(package-refresh-contents)
(message "%s" " done.")
;; Install the missing packages
(dolist (p packages-list)
(when (not (package-installed-p p))
(package-install p))))
;; }}}
;; {{{ straight packages
;; Install straight.el
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 6))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage)
(straight-use-package 'use-package))
(use-package lean4-mode
:straight (lean4-mode
:type git
:host github
:repo "leanprover/lean4-mode"
:files ("*.el" "data"))
;; to defer loading the package until required
:commands (lean4-mode))
(use-package dap-mode
:straight (dap-mode
:type git
:host github
:repo "oxidase/dap-mode"
:no-byte-compile t
:files ("*.el" "icons"))
;; to defer loading the package until required
:commands (dap-mode))
(use-package systemd
:straight (systemd-mode
:type git
:host github
:repo "holomorph/systemd-mode"
:no-byte-compile t
:files ("*.el" "*.txt"))
;; to defer loading the package until required
:commands (systemd-mode))
;; }}}
;;{{{ Customization
;; Load customization information if it exists
(if (file-exists-p custom-file)
(load custom-file))
(when (< emacs-major-version 24)
(pc-bindings-mode)
(if (< emacs-major-version 22) (pc-selection-mode) (pc-selection-mode t)))
;; functional keys
(global-set-key [f4] 'query-replace-regexp)
(global-set-key [?\s-s] 'search-forward-regexp)
(global-set-key [f5] 'revert-buffer)
(global-set-key "\M-?" 'goto-line)
(global-set-key [C-x-p] 'bury-buffer)
(global-set-key "\C-c;" 'comment-region)
(global-set-key "\C-c'" 'uncomment-region)
(global-set-key [C-f4] (lambda () (interactive) (kill-buffer (current-buffer))))
(global-set-key [(mouse-4)] #'(lambda () (interactive) (scroll-down (/ (window-height) 2))))
(global-set-key [(mouse-5)] #'(lambda () (interactive) (scroll-up (/ (window-height) 2))))
(global-set-key "\C-x\C-g" 'recentf-open-files)
;; windmove modifier+<> keys
(defun windmove-default-keybindings (&optional modifier)
"Set up keybindings for `windmove'.
Keybindings are of the form MODIFIER-{left,right,up,down}.
Default MODIFIER is 'shift."
(interactive)
(unless modifier (setq modifier 'shift))
(global-set-key (vector (list modifier 'left)) 'windmove-left)
(global-set-key (vector (list modifier 'right)) 'windmove-right)
(global-set-key (vector (list modifier 'up)) 'windmove-up)
(global-set-key (vector (list modifier 'down)) 'windmove-down))
(cond
(running-on-windows
;; #IfWinActive ahk_class Emacs ; AutoHotKey mapping
;; LWin::AppsKey
;; #IfWinActive
(setq w32-pass-apps-to-system nil)
(setq w32-apps-modifier 'hyper)
(windmove-default-keybindings 'hyper))
(t
(windmove-default-keybindings 'super)))
(setq frame-title-format (list user-login-name " on " system-name " - %b - " invocation-name))
(when (> emacs-major-version 22) (setq history-length 1000) (savehist-mode 1))
;(setenv "LANG" "en_US.UTF-8")
;(setenv "LC_ALL" "en_US.UTF-8")
;(setenv "LC_CTYPE" "en_US.UTF-8")
(set-face-attribute 'region nil :background "#b8d8ff")
(menu-bar-enable-clipboard)
(turn-off-auto-fill)
(setq fill-column 120)
(setq split-width-threshold 200)
(recentf-mode 1) ;; Recent files in menu
(setq recentf-max-saved-items nil)
(delete-selection-mode 1) ;; hitting delete will delete the highlighted region
(setq undo-limit 20000000)
(setq revert-without-query '(".*"))
(global-eldoc-mode -1)
(transient-mark-mode 1) ;; When the mark is active, the region is highlighted.
(setq inhibit-startup-screen t) ;; Silent boot
(setq initial-scratch-message nil) ;; Clear scratch buffer
(setq initial-major-mode 'text-mode) ;; text mode is default
(set-scroll-bar-mode 'right) ;; vertical scroll bars on the right side.
(setq scroll-error-top-bottom t) ;; scroll to top or bottom
(global-font-lock-mode t) ;; Turn on font-lock in all modes that support it.
(setq font-lock-maximum-decoration t) ;; use the maximum decoration available
(show-paren-mode t) ;; Highlight matching parentheses.
(setq default-major-mode 'text-mode) ;; Make text mode default major mode.
(setq shell-prompt-pattern "^[^#$%>\n]*[#$%>\)] *") ;; My shell prompt ends on ")".
(setq visible-bell t) ;; Turn off beep.
(setq ring-bell-function 'ignore) ;; Turn the alarm totally off
(standard-display-8bit 128 255) ;; Do not expand unprintable characters to their octal values.
(setq fortran-comment-region "C MKR") ;; Fortran comments prefix.
(line-number-mode 1) ;; Show line-number in the mode line.
(column-number-mode 1) ;; Show column-number in the mode line.
(fset 'yes-or-no-p 'y-or-n-p) ;; Will allow you to type just "y" instead of "yes".
(setq-default tab-width 2) ;; Set Tab-Width.
(setq sh-basic-offset 2) ;; Set tab-width in shell scripts
(setq-default indent-tabs-mode nil) ;; Permanently force Emacs to indent with spaces.
(put 'upcase-region 'disabled nil) ;; Convert the region to upper case.
(put 'downcase-region 'disabled nil) ;; Convert the region to lower case.
(blink-cursor-mode -1) ;; Switch off blinking cursor mode.
(setq large-file-warning-threshold nil) ;; Maximum size of file above which a confirmation is requested
(add-hook 'before-save-hook 'delete-trailing-whitespace) ;; configuration required (remove-hook 'before-save-hook 'delete-trailing-whitespace)
(setq find-file-visit-truename t) ;; Follow symbolic links when file is visited
(setq mode-require-final-newline t)
(setq delete-trailing-lines nil)
(setq printer-name "HP-ENVY-4520-series") ;; lpstat -p -d
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)
(setq vc-follow-symlinks t)
(setq grep-command "grep --exclude-dir=\".svn\" --exclude=TAGS -nHriIZ -e ")
(setq tags-case-fold-search nil)
(if (not (assq 'user-size initial-frame-alist)) ;; Unless we've specified a number of lines, prevent the startup code from
(setq tool-bar-originally-present nil)) ;; shrinking the frame because we got rid of the tool-bar.
;; ediff
(setq ediff-window-setup-function 'ediff-setup-windows-plain)
(setq ediff-split-window-function 'split-window-horizontally)
(defadvice ediff-quit (around advice-ediff-quit activate)
(cl-flet ((yes-or-no-p (&rest args) t) (y-or-n-p (&rest args) t))
ad-do-it))
(add-hook 'comint-exec-hook ;; Don't ask about killing process buffers on exit
#'(lambda () (set-process-query-on-exit-flag (get-buffer-process (current-buffer)) nil)))
;; Place Backup Files in Specific Directory
(setq make-backup-files t) ;; Enable backup files.
(setq version-control t) ;; Enable versioning with default values.
(setq delete-old-versions t)
(setq backup-directory-alist ;; Save all backup file in this directory.
(list `(".*" . ,(concat custom-dir "/.emacs.backups"))))
(defvar insert-time-format "%T" "*Format for \\[insert-time].")
(defvar insert-date-format "%e %B %Y %T" "*Format for \\[insert-date].")
(defadvice save-buffers-kill-emacs (around no-query-kill-emacs activate)
"Prevent annoying \"Active processes exist\" query when you quit Emacs."
(cl-flet ((process-list ())) ad-do-it))
;; Replace some template literals in compilation output
(defun replace-char-type-literals (start end)
(save-excursion
(goto-char start)
(previous-line)
(narrow-to-region (point) (point-max))
(while (re-search-forward "sc::string_constant<\\([^,]+\\)\\(\\(, ([^)]+)[0-9]+\\)+\\)>" nil t)
(progn
(let* ((sc (save-match-data
(condition-case err
(let* ((match (match-string 0))
(type (match-string 1))
(ordinals (split-string (match-string 2) (format ", (%s)" type)))
(characters (mapcar (lambda (num) (let ((x (string-to-number num))) (if (> x 0) (string x) ""))) ordinals)))
(format "\"%s\"_sc" (apply #'concat characters)))
(error
(progn (message "error occurred in replace-char-type-literals: %s\n %s" (error-message-string err) match) nil))))))
(when sc
(replace-match sc t)
(put-text-property (match-beginning 0) (match-end 0) 'font-lock-face `(:background ,(face-attribute 'lazy-highlight :background)))))))))
;; ANSI colorization of a buffer
(require 'ansi-color)
(defun ansi-color ()
(interactive)
(let ((inhibit-read-only t)
(ansi-color-apply-face-function
(lambda (beg end face)
(when face
(put-text-property beg end 'face face)))))
(ansi-color-apply-on-region (point-min) (point-max))))
(add-hook
'compilation-filter-hook
(lambda ()
(ignore-errors
(when (eq major-mode 'compilation-mode)
(replace-char-type-literals compilation-filter-start (point-max))
(ansi-color-apply-on-region compilation-filter-start (point-max))))))
(add-hook
'compilation-filter-hook
(lambda ()
(ignore-errors
(when (eq major-mode 'compilation-mode)
))))
;; calendar settings
(defface calendar-kw `((t (:foreground "black") (:background "pale green"))) "Face for a calendar week number column")
(setq calendar-week-start-day 1)
(setq calendar-intermonth-text '(propertize (format "%2d" (car (calendar-iso-from-absolute (calendar-absolute-from-gregorian (list month day year))))) 'font-lock-face 'calendar-kw))
(setq calendar-intermonth-header (propertize "KW" 'font-lock-face 'calendar-kw))
;; Thema
(add-to-list 'custom-theme-load-path "~/.emacs.d/themes/")
;(load-theme 'solarized-dark t)
;; Start Emacs as a server
(load "server")
(unless (server-running-p) (server-start))
;;}}}
;;{{{ Load local packages
(when (package-dir "adoc-mode*")
(require 'adoc-mode))
(when (package-dir "gradle-mode*")
(require 'gradle-mode))
(when (package-dir "go-mode*")
(require 'go-mode)
(when (file-exists-p (concat custom-dir "/lisp/go-autocomplete.el"))
(require 'go-autocomplete)
(require 'auto-complete-config)))
(when (package-dir "go-direx*")
(require 'go-direx)
(define-key go-mode-map (kbd "C-c C-j") 'go-direx-pop-to-buffer))
(when (package-dir "yaml-mode*")
(require 'yaml-mode)
(add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode)))
(when (package-dir "somafm*")
(require 'somafm))
(when (package-dir "volume*")
(autoload 'volume "volume" "Tweak your sound card volume." t))
(when (package-dir "elfeed*")
(require 'elfeed)
(global-set-key (kbd "C-x w") (lambda () (interactive) (elfeed) (elfeed-update)))
(setq elfeed-feeds
'("http://nullprogram.com/feed/"
"http://arxiv.org/rss/cs.CV"
;;"http://arxiv.org/rss/cs.RO"
;;"http://arxiv.org/rss/cs.SY"
;;"http://arxiv.org/rss/eess.SP"
"https://openai.com/blog/rss.xml"
"https://towardsdatascience.com/feed"
"https://news.mit.edu/rss/topic/artificial-intelligence2"
"https://bair.berkeley.edu/blog/feed.xml"
"https://machinelearning.apple.com/rss.xml"
"https://www.sciencedaily.com/rss/computers_math/artificial_intelligence.xml"
"https://www.deepmind.com/blog/rss.xml"
"https://ai2people.com/feed/"
"https://machinelearningmastery.com/blog/feed/"
"https://aws.amazon.com/blogs/machine-learning/feed/"
"https://www.reddit.com/r/Cyberpunk/.rss"
"https://www.reddit.com/r/cpp/.rss"
"https://www.reddit.com/r/robotics/.rss"
"https://www.reddit.com/r/SelfDrivingCars/.rss"
"https://www.reddit.com/r/Driverless/.rss"
"https://xkcd.com/rss.xml"
"https://hnrss.org/newest"
;; "https://www.wired.com/feed/rss"
;; "https://www.wired.com/feed/category/science/latest/rss"
;; "https://www.wired.com/feed/category/security/latest/rss"
;; "https://www.wired.com/feed/category/transportation/latest/rss"
;; "https://www.wired.com/feed/category/ideas/latest/rss"
;; "https://www.wired.com/feed/category/gear/latest/rss"
;; "https://habr.com/ru/rss/best/daily/?fl=ru"
))
(defun elfeed-show-quick-url-note ()
"Fastest way to capture entry link to org agenda from elfeed show mode"
(interactive)
(let* ((link (elfeed-entry-link elfeed-show-entry))
(title (replace-regexp-in-string "[][]" "" (elfeed-entry-title elfeed-show-entry)))
(tags `(,(when (string-match-p "arxiv.org" link) ":ARXIV:")))
(note (format "[[%s][%s]] %s" link title (mapconcat 'identity (remove-if 'not tags) " "))))
(kill-new note)
(org-capture nil "n")
(yank)
(org-capture-finalize)))
(define-key elfeed-show-mode-map "v" 'elfeed-show-quick-url-note))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Smooth scrolling
(when (package-dir "smooth-scrolling*")
(require 'smooth-scrolling)
(setq smooth-scroll-margin 2))
(global-set-key (kbd "<C-up>") 'scroll-down-command)
(global-set-key (kbd "<C-down>") 'scroll-up-command)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Fontlocking modes
(require 'doc-mode)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Dired mode
(load-library "dired")
(when running-on-darwin
(setq dired-use-ls-dired nil))
(setenv "LANG" "POSIX")
(defvar dired-sort-map (make-sparse-keymap))
;; sort keys
(define-key dired-mode-map "s" dired-sort-map)
(define-key dired-sort-map "s" (lambda () "sort by Size" (interactive) (dired-sort-other (concat dired-listing-switches "S"))))
(define-key dired-sort-map "x" (lambda () "sort by eXtension" (interactive) (dired-sort-other (concat dired-listing-switches "X"))))
(define-key dired-sort-map "t" (lambda () "sort by Time" (interactive) (dired-sort-other (concat dired-listing-switches "t"))))
(define-key dired-sort-map "n" (lambda () "sort by Name" (interactive) (dired-sort-other dired-listing-switches)))
(define-key dired-sort-map "d" (lambda () "sort by name grouping Dirs" (interactive) (dired-sort-other (concat dired-listing-switches " --group-directories-first"))))
;; humanized output
(setq dired-listing-switches-styles '("-alh" "-al"))
;(setq dired-listing-switches-styles
; (if (string-match ".tm.ro." system-name) '("-alh" "-al")
; '("-alh --group-directories-first" "-al --group-directories-first")))
(setq dired-listing-switches-idx 0)
(setq dired-listing-switches (nth dired-listing-switches-idx dired-listing-switches-styles))
(define-key dired-mode-map "h" (lambda () (interactive)
(setq dired-listing-switches-idx (% (1+ dired-listing-switches-idx) (length dired-listing-switches-styles)))
(setq dired-listing-switches (nth dired-listing-switches-idx dired-listing-switches-styles))
(setq dired-actual-switches dired-listing-switches)
(revert-buffer)))
(define-key dired-mode-map "z" (lambda () (interactive)
(let* ((name (or (dired-get-filename nil t) default-directory))
(localname (or (file-remote-p name 'localname) name)))
(kill-new localname)
(x-set-selection nil localname))))
;; additional faces
(defface dired-compressed-file
'((t (:foreground "violet")))
"*Face used for compressed files in dired buffers."
:group 'dired :group 'font-lock-highlighting-faces)
(defvar dired-compressed-file 'dired-compressed-file)
(defface dired-image-file
'((t (:foreground "magenta4")))
"*Face used for image files in dired buffers."
:group 'dired :group 'font-lock-highlighting-faces)
(defvar dired-image-file 'dired-image-file)
(defface dired-exe-file
'((t (:foreground "lime green")))
"*Face used for executable files in dired buffers."
:group 'dired :group 'font-lock-highlighting-faces)
(defvar dired-exe-file 'dired-exe-file)
(defun mark-filename (re face) (list re `(".+" (dired-move-to-filename) nil (0 ,face))))
(setq dired-font-lock-keywords (append dired-font-lock-keywords
(list
(mark-filename "[^ .]\\.\\([bgx]?[zZ]2?\\|[bg]?zip\\|rar\\)[*]?$" dired-compressed-file)
(mark-filename "[^ .]\\.\\(jpg\\|png\\|eps\\)[*]?$" dired-image-file)
(mark-filename dired-re-exe dired-exe-file))))
;; use a single buffer for dired mode
(when (package-dir "dired-single*")
(require 'dired-single)
(defun my-dired-init ()
"Bunch of stuff to run for dired, either immediately or when it'sloaded."
(require 'dired-sort-menu)
(setq mouse-1-click-follows-link 200)
;; TODO: add call stack
(add-hook 'before-change-major-mode-hook
#'(lambda () (when (eq major-mode 'dired-mode)
(make-local-variable 'dired-stack)
(setq dired-stack '('hello)))))
;; global stack works, but local stack can not be saved
(defvar dired-single-stack '())
(defun dired-single-buffer-down ()
(interactive)
(let ((name (dired-get-filename nil t)))
(cond
((file-accessible-directory-p name)
(push (file-name-nondirectory name) dired-single-stack)
(dired-single-buffer name))
(t (dired-single-buffer)))))
(defun dired-single-buffer-up ()
(interactive)
(let ((name (pop dired-single-stack)) pos)
(dired-single-buffer "..")
(when name
(setq pos (search-forward-regexp (concat name "$") nil t))
(if pos
(goto-char (- pos (length name)))
(setq dired-single-stack '())))))
(define-key dired-mode-map [return] 'dired-single-buffer-down)
(define-key dired-mode-map [mouse-1] 'dired-single-buffer-down)
(define-key dired-mode-map (read-kbd-macro "<backspace>") 'dired-single-buffer-up))
(if (boundp 'dired-mode-map) (my-dired-init) (add-hook 'dired-load-hook 'my-dired-init))
(define-key dired-mode-map (read-kbd-macro "<f8>") 'dired-do-delete))
; use openwith minor mode
(when (package-dir "openwith*")
(require 'openwith)
(openwith-mode t)
(setq pdf-app "evince")
(setq openwith-associations
(cond
(running-on-gnu/linux
'(("[^_]?\\.\\(ps\\|pdf\\|djvu\\|epub\\)\\'" "evince" (file))
("\\.\\(docx?\\|odt\\|pptx?\\|rtf\\|xlsx?\\)\\'" "libreoffice" (file))
("\\.\\(ai\\)\\'" "inkscape" (file))
("\\.\\(svg\\)\\'" "eog" (file))
("\\.\\(?:mpe?g\\|avi\\|wmv\\|mp4\\)\\'" "smplayer" (file))))
(running-on-windows
'("\\.\\(dll\\|pyd\\)\\'" "depends.exe" (file)))
(running-on-darwin
'(("\\.\\(ps\\|pdf\\|djvu\\docx?\\|epub\\|tif\\|jp2\\|mov\\|drawio\\|pptx?\\|rtf\\|xlsx?\\)$" "open" (file))
("\\.\\(ai\\)\\'" "/Applications/Inkscape.app/Contents/MacOS/inkscape" (file))))
)))
;; open file in alternative editor
(defvar alternate-editor "gedit"
"Editor to use when visiting a buffer outside of emacs.")
(defun open-in-alternate-editor (&optional arg)
"Open buffer in alternative editor. If buffer is unsaved,
bring it up in a temporary file. With prefix argument, ask for
the editor to use."
(interactive "P")
(let ((edit (executable-find (if arg
(read-from-minibuffer
"Enter editor to use: "
alternate-editor)
alternate-editor)))
(file (or (buffer-file-name)
(make-temp-file "unsaved-emacs-buffer-")))
(buff (unless (buffer-file-name)
(save-restriction (widen) (buffer-string)))))
(when (null edit)
(error "Can't find alternate editor"))
(unless (buffer-file-name)
(with-temp-file file
(insert buff)))
(start-process "Alternate Editor" nil edit file (format "+%d" (line-number-at-pos)))))
;;; Shell mode
(setq ansi-color-names-vector ["black" "red4" "green4" "yellow4" "blue3" "magenta4" "cyan4" "white"])
(add-hook 'shell-mode-hook 'ansi-color-for-comint-mode-on)
(add-hook 'fish-mode-hook (lambda () (modify-syntax-entry ?_ "w" fish-mode-syntax-table)))
(add-hook 'sh-mode-hook (lambda () (modify-syntax-entry ?_ "w" sh-mode-syntax-table)))
;; Extend execution paths with fish paths
(let*
((fish-path (split-string (shell-command-to-string "/opt/homebrew/bin/fish -c 'printf \"%s\\n\" $PATH' 2>/dev/null") "\n"))
(full-path (append fish-path (cl-remove-if (lambda (item) (member item fish-path)) exec-path))))
(setenv "PATH" (string-join full-path ":"))
(setq exec-path full-path))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Translator (google)
(when (package-dir "google-translate*")
(require 'google-translate)
(global-set-key "\C-xt"
(lambda ()
(interactive)
(let ((bnd (bounds-of-thing-at-point 'word))
(src google-translate-default-source-language)
(dst google-translate-default-target-language)
beg end)
(cond
(mark-active (setq beg (region-beginning) end (region-end)))
(bnd (setq beg (car bnd) end (cdr bnd))))
(when (and beg end)
(goto-char end)
(setq orig (buffer-substring-no-properties beg end))
(setq str orig)
;; remove TeX comamnds
(setq str (replace-regexp-in-string "\\\\[a-zA-Z]+\\({[a-zA-Z]+}\\)?" "" str))
(setq str (replace-regexp-in-string "[{}]" "" str))
(google-translate-translate src dst str 'kill-ring)
(insert (format " "))
(insert (car kill-ring-yank-pointer))))))
(setq google-translate-default-source-language "en")
(setq google-translate-default-target-language "ru"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Git mode
(when (package-dir "magit*")
(require 'magit)
(require 'magit-blame)
(setq magit-refs-pad-commit-counts t)
(setq magit-last-seen-setup-instructions "1.4.0")
(setq magit-save-repository-buffers nil)
(custom-set-variables '(git-commit-summary-max-length 80))
(global-set-key "\C-cs" 'magit-status)
(global-set-key "\C-cb" 'magit-blame)
(global-set-key "\C-cl" 'magit-log-buffer-file)
(global-set-key "\C-cg" 'gh-lines)
;; in .dir-locals.el
;; ((json-mode . ((js-indent-level . 2)))
;; (magit-refs-mode . ((eval . (remove-hook 'magit-refs-sections-hook 'magit-insert-remote-branches)))))
(defun gh-lines (ref)
"Open the current line in GitHub"
(interactive (list (magit-read-starting-point "Show line for" nil (magit-get-current-branch))))
(let* ((remotes (magit-list-remotes))
(remote (cond
((null remotes) "origin")
((member "upstream" remotes) "upstream")
((member "origin" remotes) "origin")
((t (car remotes)))))
(remote-url
(replace-regexp-in-string "\\(.git\\|/+\\)$" "" ; remove trailing slashes or .git suffix
(replace-regexp-in-string "://[^@]+@" "://" ; remove user name
(replace-regexp-in-string "^git@\\(.*\\):\\(.*\\)\\.git$" "https://\\1/\\2" ; most general case
(replace-regexp-in-string "^git@github.\\([^:]+\\):" "https://github.\\1/" ; change protocol to https
(replace-regexp-in-string "^git://sourceware.org/git/\\(.*+\\)" "https://sourceware.org/git/?p=\\1.git" ; change protocol to https
(magit-get "remote" remote "url")))))))
(from (line-number-at-pos (if (and transient-mark-mode mark-active) (region-beginning) (point)))) ; or (format-mode-line "%l")
(to (line-number-at-pos (if (and transient-mark-mode mark-active) (- (region-end) (if (= (current-column) 0) 1 0)) (point))))
(lines (if (>= from to) (format "L%d" from) (format "L%d-L%d" from to)))
(gh-url
(cond
((cl-search "gitlab" remote-url) (format "%s/-/blob/%s/%s?#%s" remote-url (substring (or (magit-rev-verify ref) (magit-rev-parse "HEAD")) 0 8) (magit-file-relative-name) lines))
((cl-search "github" remote-url) (format "%s/blob/%s/%s#%s" remote-url (substring (or (magit-rev-verify ref) (magit-rev-parse "HEAD")) 0 8) (magit-file-relative-name) lines))
((cl-search "sourceware.org" remote-url) (format "%s;a=blob;f=%s#l%d" remote-url (magit-file-relative-name) from))
(t remote-url))))
(kill-new gh-url)
(browse-url gh-url)))
(defun bb-lines (ref)
"Open the current line in Bitbucket"
(interactive (list (magit-read-starting-point "Show line for" nil (magit-get-current-branch))))
(let* ((remotes (magit-list-remotes))
(remote (cond
((null remotes) "origin")
((member "upstream" remotes) "upstream")
((member "origin" remotes) "origin")
((t (car remotes)))))
(remote-url
(replace-regexp-in-string "/+$" "" ; remove trailing slashes
(replace-regexp-in-string ":[0-9]+/" "/" ; remove port number
(replace-regexp-in-string "://[^@]+@" "://" ; remove user name
(magit-get "remote" remote "url")))))
(proj-url (replace-regexp-in-string ".git" "/browse" (replace-regexp-in-string "scm/werk" "projects/WERK/repos" remote-url)))
(from (line-number-at-pos (if (and transient-mark-mode mark-active) (region-beginning) (point)))) ; or (format-mode-line "%l")
(to (line-number-at-pos (if (and transient-mark-mode mark-active) (- (region-end) (if (= (current-column) 0) 1 0)) (point))))
(lines (if (>= from to) (format "%d" from) (format "%d-%d" from to)))
(gh-url (format "%s/%s?at=%s#%s" proj-url (magit-file-relative-name) (substring (magit-rev-parse ref) 0 8) lines)))
(kill-new gh-url)
(browse-url gh-url)))
;; Add magit process buffer ANSI colorization
(defun magit-color-buffer (proc &rest args)
(interactive)
(with-current-buffer (process-buffer proc)
(read-only-mode -1)
(ansi-color-apply-on-region (point-min) (point-max))
(read-only-mode 1)))
(advice-add 'magit-process-filter :after #'magit-color-buffer)
;; Some specific function to show/edit branch descriptions
(defun magit-show-description ()
"Print descriptions"
(interactive)
(magit-section-action info (info)
(branch
(message (magit-git-string "config" (format "branch.%s.description" info))))))
(defun magit-edit-description ()
"Edit descriptions"
(interactive) ; (list (magit-read-rev "Edit branch description" (magit-get-current-branch))))
(magit-section-action info (info)
(branch
(let* ((config (format "branch.%s.description" info))
(current (magit-git-string "config" config))
(description (read-string (format "Descrition of [%s]: " info) current)))
(magit-git-string "config" config description)))))
(eval-after-load "magit-mode"
'(define-key magit-mode-map [C-tab] nil)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Matlab mode
(when (package-dir "matlab-mode*")
(autoload 'matlab-mode "matlab" "Enter MATLAB mode." t)
(autoload 'matlab-shell "matlab" "Interactive MATLAB mode." t)
)
;; (custom-set-variables '(matlab-comment-region-s "% "))
;; (setq matlab-fill-code nil)
;; (custom-set-faces '(matlab-cellbreak-face ((t (:foreground "Firebrick" :weight bold)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ESS
(when (package-dir "ess*")
(require 'ess-site)
(setq ess-ask-for-ess-directory nil))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Gnuplot
(when (package-dir "/gnuplot*")
(autoload 'gnuplot-mode "gnuplot" "gnuplot major mode" t)
(autoload 'gnuplot-make-buffer "gnuplot" "open a buffer in gnuplot-mode" t))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; m4 mode
(load-library "m4-mode")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Remote file editing via ssh
(require 'tramp)
(setq tramp-default-method "ssh")
(setq tramp-debug-buffer t)
(setq tramp-verbose 10)
(setq tramp-histfile-override "/dev/null")
(setq tramp-remote-process-environment (append tramp-remote-process-environment '("LC_ALL=C.UTF-8" "LANG=C.UTF-8")))
(global-set-key "\C-c\C-t" 'tramp-cleanup-all-connections)
(when (package-dir "magit-tramp*")
(require 'magit-tramp))
(when (package-dir "protobuf-mode*")
(require 'protobuf-mode))
(when (package-dir "docker-*")
(require 'docker))
(when (package-dir "twittering-mode-*")
(require 'twittering-mode))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Gentoo ebuild mode
(when (package-dir "ebuild-mode*")
(require 'ebuild-mode)
(require 'eselect-mode))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Visible bookmarks in buffer.
(when (package-dir "bm-*")
(require 'bm)
;; M$ Visual Studio key setup.
(global-set-key (kbd "<C-f2>") 'bm-toggle)
(global-set-key (kbd "<f2>") 'bm-next)
(global-set-key (kbd "<S-f2>") 'bm-previous))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Po files
(autoload 'po-mode "start-po" "PO major mode" t)
(setq auto-mode-alist (cons '("\\.po[tx]?\\'\\|\\.po\\." . po-mode) auto-mode-alist))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; setup spell checker
(when running-on-windows
(add-to-list 'exec-path "C:/Program Files (x86)/Aspell/bin/"))
(if (executable-find "aspell")
(progn
(require 'ispell)
(setq-default ispell-program-name "aspell")
(ispell-change-dictionary "american" t)
(setq ispell-check-comments t)
(global-set-key (kbd "C-`") 'ispell-word)
(add-hook 'text-mode-hook 'flyspell-mode)
(add-hook 'c-mode-hook 'flyspell-mode)
(add-hook 'python-mode-hook 'flyspell-mode)
(add-hook 'org-mode-hook 'flyspell-mode))
(message "Aspell not found."))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Other modes
(add-hook 'js-json-mode-hook (lambda () (setq js-indent-level 2)))
(setq auto-mode-alist (append auto-mode-alist '(("\\.json$" . json-mode) ("\\.geojson$" . json-mode) ("\\.manifest$" . json-mode))))
(when (package-dir "feature-mode*")
(load-library "feature-mode")
(modify-syntax-entry ?_ "w" feature-mode-syntax-table)
(add-to-list 'auto-mode-alist '("\.feature$" . feature-mode)))
(when (package-dir "jade-mode*")
(load-library "jade-mode")
(add-to-list 'auto-mode-alist '("\\.jade\\'" . jade-mode)))
(when (package-dir "bitbake*")
(require 'bitbake))
(when (package-dir "polymode*")
(require 'polymode)
(require 'poly-lock)
(when (package-dir "bitbake*")
(define-innermode poly-bitbake-root-innermode
:mode nil
:fallback-mode 'host
:head-mode 'host
:tail-mode 'host)
(define-innermode poly-bitbake-python-innermode poly-bitbake-root-innermode
"Displayed python { } innermode."
:mode 'python-mode
:head-matcher "^python"
:tail-matcher "^}$"
:head-mode 'host
:tail-mode 'host
:allow-nested nil)))
(when (package-dir "qml-mode*")
(require 'qml-mode)
(add-hook 'qml-mode-hook (lambda () (modify-syntax-entry ?' "|"))))
(when (package-dir "bazel-*")
(require 'bazel)
(add-to-list 'auto-mode-alist '("BUILD\\(\\.[^/]+\\)?$" . bazel-build-mode))
(add-to-list 'auto-mode-alist '("\\.BUILD$" . bazel-build-mode))
(add-to-list 'auto-mode-alist '("WORKSPACE.bzlmod$" . bazel-workspace-mode))
(modify-syntax-entry ?_ "w" bazel-mode-syntax-table)
(modify-syntax-entry ?_ "w" bazel-build-mode-syntax-table)
(modify-syntax-entry ?_ "w" bazel-starlark-mode-syntax-table)
(modify-syntax-entry ?_ "w" bazel-workspace-mode-syntax-table))
(when (package-dir "eff-*")
(require 'eff))
(when (package-dir "string-inflection*")
;; cycle between snake case, camel case, etc.
(require 'string-inflection)
(global-set-key (kbd "C-c i") 'string-inflection-cycle))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; C and C++ modes
(require 'cc-langs)
(require 'cc-mode)
(require 'jam-mode)
(require 'cmake-mode)
(require 'gud)
(require 'gdb-mi)
(require 'osl-mode)
(require 'glsl-mode)
(setq gud-tooltip-mode t)
(setq compilation-ask-about-save nil)
(setq gdb-debuginfod-enable-setting t)
(defun get-bazel-root (dir)
(or (vc-find-root dir "WORKSPACE") (vc-find-root dir "MODULE.bazel")))
(defun get-yarn-root (dir)
(when (member major-mode '(web-mode json-mode)) (vc-find-root dir "package.json")))
(defun get-buffer-file-name()
(or (buffer-file-name) (concat "*" (symbol-name major-mode) "*")))
(defun get-compile-command ()
(let* ((abs (get-buffer-file-name))
(name (file-name-nondirectory abs))
(stem (file-name-sans-extension name))
(ext (file-name-extension name))
(dir (expand-file-name default-directory))
(bazel-root (get-bazel-root dir))
(yarn-root (get-yarn-root dir)))
(cond
(bazel-root (format "bazel test //%s..." (substring dir (length (expand-file-name bazel-root)))))
((eq major-mode 'c++-mode)
(cond
((string-equal ext "nxc") (format "nbc %s -O=%s.rxe; nxt_push %s.rxe" name stem stem))
((string-equal ext "cu") (format "nvcc -O0 -g %s -o %s" name stem))
((string-equal ext "c") (format "gcc -Wall -O0 -g %s -o %s" name stem))
(t (format "g++ -std=c++20 -Wall -O0 -g %s -o %s" name stem))))
((eq major-mode 'python-mode) (format "python3 %s" name))
((eq major-mode 'haskell-mode) ("ghc %s -o %s" name stem))
((member major-mode '(makefile-gmake-mode makefile-bsdmake-mode)) "make")
(yarn-root
(cond
((string-match-p ".+[\\._]test$" stem)
(format "yarn test %s" (substring abs (length (expand-file-name yarn-root)))))
(t "yarn test")))
(t "make -k "))))
(defun do-compile (command)
;; Get compile command and cached it for next invocations
(interactive (list (if (< compiled-times 2) (read-string "Compile command: " compile-command) compile-command)))
(setq-local compiled-times (if (string= compile-command command) (1+ compiled-times) 0))
(setq-local compile-command command)
;; Get compile directory, modify default-directory, compile, and restore default-directory
(let* ((saved-default-directory default-directory)
(bazel (string-match-p "^\s*bazel" command))
(yarn-root (get-yarn-root default-directory))
(project-root (and (fboundp 'ag/project-root) (ag/project-root default-directory)))
(default-directory (or (and bazel (get-bazel-root default-directory)) yarn-root default-directory)))
(compile command)
(setq default-directory saved-default-directory)))
(defun do-run(command)
;; Get run command and cached it for next invocations
(interactive (list (if (< run-times 2) (read-string "Run command: " run-command) run-command)))
(setq-local run-times (if (string= run-command command) (1+ run-times) 0))
(setq-local run-command command)
(let*
((buffer-name "*std output*")
(output-buffer (or (get-buffer buffer-name) (generate-new-buffer buffer-name)))
(output-window (async-shell-command command output-buffer))
(proc (get-buffer-process output-buffer)))
(if (process-live-p proc)
(set-process-sentinel
proc #'(lambda (process signal)
(when (memq (process-status process) '(exit signal))
(message "Process %d exited with code %d" (process-id process) (process-exit-status process))))))
(other-window 1)
(switch-to-buffer output-buffer)
(other-window 1)))
(defun gud-set-clear () (interactive)
(message "gud-set-clear")
(let ((buf (current-buffer))
(pnt (point))
(set-break (not (eq (car (fringe-bitmaps-at-pos (point))) 'breakpoint)))
(pos (car (gdb-line-posns (line-number-at-pos)))))
(if set-break (gud-break nil) (gud-remove nil))
(when (eq major-mode 'python-mode)
(if set-break (gdb-put-breakpoint-icon t 0) (gdb-remove-breakpoint-icons (- pos 1) (+ pos 1)))
(sleep-for .2)
(switch-to-buffer buf) (goto-char pnt)
(delete-other-windows)
(gud-split-window)
)))
(defun gud-split-window () (interactive)
(when (buffer-name gud-comint-buffer)
(delete-other-windows)
(if (eq (current-buffer) gud-comint-buffer)
(gud-refresh)
(progn (split-window-vertically) (other-window 1) (switch-to-buffer gud-comint-buffer) (other-window 1)))))
(defun development-mode-hook ()
;;(print (mapcar (lambda (x) (car x)) (buffer-local-variables)))
;;(print (remove-if-not (lambda (x) (eq 'compile-command (car x))) (buffer-local-variables)))
;;(ggtags-mode 1)
(setq show-trailing-whitespace t)
(unless (eq major-mode 'js-mode)
(defun c-font-lock-invalid-string () t) ;; Turn off invalid string highlight
(c-toggle-auto-newline -1) ;; Turn off auto-newline feature
(c-set-offset 'substatement-open 0)) ;; Project brace indent style
(unless (eq major-mode 'gud-mode)
;; Compile command
(set (make-local-variable 'compiled-times) 0)
(set 'compile-command (get-compile-command))
(local-set-key "\C-c\C-c" 'do-compile)
;; Run command, allow only commands in that starts with "./"
(set (make-local-variable 'run-times) 0)
(set
(make-local-variable 'run-command)
(cond
((eq major-mode 'python-mode) (format "python3 %s" (file-name-nondirectory (get-buffer-file-name))))
(t (format "%s%s" (if running-on-windows "" "./") (file-name-base (get-buffer-file-name))))))
(put 'run-command 'safe-local-variable 'run-command-safe-variable)
(defun run-command-safe-variable (var)
(or
(string-match "^[ \t\n\r]*\\(qml\\(scene\\|viewer\\)\\|optirun\\)[ \t\n\r]*\./.+" var)
(string-match "/usr/bin/curl.+" var)))
(local-set-key "\C-c\C-v" 'do-run))
;; settings depending on the mode
(when (or (eq major-mode 'c++-mode) (eq major-mode 'fortran-mode)
(eq major-mode 'jam-mode) (eq major-mode 'objc-mode))
(setq flyspell-prog-text-faces '(font-lock-comment-face font-lock-doc-face))
(flyspell-prog-mode)
(local-set-key '[C-f8] 'flyspell-buffer)
;; other settings
(setq indent-tabs-mode nil))
;; TAGS lookup
(when (or (eq major-mode 'c++-mode) (eq major-mode 'fortran-mode)
(eq major-mode 'jam-mode) (eq major-mode 'gud-mode))
(local-set-key (kbd "M-/") 'xref-find-references)
(setq-local xref-prompt-for-identifier nil))
(when (eq major-mode 'fortran-mode)
(local-set-key "\C-c'" 'fortran-comment-region))
(when (and (not running-on-windows)
(or (eq major-mode 'c++-mode) (eq major-mode 'fortran-mode)