25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

emacs.el 57 KiB

6 yıl önce
13 yıl önce
12 yıl önce
13 yıl önce
13 yıl önce
11 yıl önce
8 yıl önce
6 yıl önce
6 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
11 yıl önce
13 yıl önce
6 yıl önce
13 yıl önce
12 yıl önce
13 yıl önce
6 yıl önce
6 yıl önce
13 yıl önce
12 yıl önce
13 yıl önce
12 yıl önce
12 yıl önce
13 yıl önce
13 yıl önce
13 yıl önce
8 yıl önce
8 yıl önce
12 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
8 yıl önce
6 yıl önce
12 yıl önce
12 yıl önce
11 yıl önce
11 yıl önce
12 yıl önce
12 yıl önce
11 yıl önce
13 yıl önce
12 yıl önce
13 yıl önce
13 yıl önce
6 yıl önce
13 yıl önce
13 yıl önce
13 yıl önce
13 yıl önce
11 yıl önce
13 yıl önce
13 yıl önce
13 yıl önce
12 yıl önce
13 yıl önce
12 yıl önce
13 yıl önce
12 yıl önce
6 yıl önce
8 yıl önce
8 yıl önce
13 yıl önce
11 yıl önce
11 yıl önce
6 yıl önce
6 yıl önce
12 yıl önce
13 yıl önce
13 yıl önce
13 yıl önce
13 yıl önce
6 yıl önce
6 yıl önce
6 yıl önce
6 yıl önce
6 yıl önce
12 yıl önce
12 yıl önce
6 yıl önce
12 yıl önce
12 yıl önce
6 yıl önce
12 yıl önce
6 yıl önce
6 yıl önce
6 yıl önce
6 yıl önce
6 yıl önce
11 yıl önce
11 yıl önce
6 yıl önce
6 yıl önce
6 yıl önce
6 yıl önce
12 yıl önce
6 yıl önce
13 yıl önce
13 yıl önce
13 yıl önce
13 yıl önce
13 yıl önce
13 yıl önce
9 yıl önce
13 yıl önce
13 yıl önce
13 yıl önce
13 yıl önce
13 yıl önce
8 yıl önce
10 yıl önce
13 yıl önce
13 yıl önce
12 yıl önce
13 yıl önce
13 yıl önce
13 yıl önce
13 yıl önce
13 yıl önce
6 yıl önce
13 yıl önce
13 yıl önce
12 yıl önce
13 yıl önce
6 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
6 yıl önce
6 yıl önce
12 yıl önce
12 yıl önce
12 yıl önce
8 yıl önce
11 yıl önce
6 yıl önce
6 yıl önce
11 yıl önce
6 yıl önce
6 yıl önce
11 yıl önce
11 yıl önce
6 yıl önce
6 yıl önce
6 yıl önce
6 yıl önce
6 yıl önce
6 yıl önce
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747
  1. ;;; emacs.el --- 10sr emacs initialization
  2. ;;; Code:
  3. ;; SETUP_LOAD: (let ((file "DOTFILES_DIR/emacs.el"))
  4. ;; SETUP_LOAD: (and (file-readable-p file)
  5. ;; SETUP_LOAD: (byte-recompile-file file nil 0 t)))
  6. (setq debug-on-error t)
  7. ;; make directories
  8. (unless (file-directory-p (expand-file-name user-emacs-directory))
  9. (make-directory (expand-file-name user-emacs-directory)))
  10. (require 'cl-lib)
  11. (require 'simple)
  12. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13. ;; Some macros for internals
  14. (defun call-after-init (func)
  15. "If `after-init-hook' has been run, call FUNC immediately.
  16. Otherwize hook it."
  17. (if after-init-time
  18. (funcall func)
  19. (add-hook 'after-init-hook
  20. func)))
  21. (defmacro safe-require-or-eval (feature)
  22. "Require FEATURE if available.
  23. At compile time the feature will be loaded immediately."
  24. `(eval-and-compile
  25. (message "safe-require-or-eval: Trying to require %s" ,feature)
  26. (require ,feature nil t)))
  27. (defmacro autoload-eval-lazily (feature &optional functions &rest body)
  28. "Define autoloading FEATURE that defines FUNCTIONS.
  29. FEATURE is a symbol. FUNCTIONS is a list of symbols. If FUNCTIONS is nil,
  30. the function same as FEATURE is defined as autoloaded function. BODY is passed
  31. to `eval-after-load'.
  32. After this macro is expanded, this returns the path to library if FEATURE
  33. found, otherwise returns nil."
  34. (declare (indent 2) (debug t))
  35. (let* ((libname (symbol-name (eval feature)))
  36. (libpath (locate-library libname)))
  37. `(progn
  38. (when (locate-library ,libname)
  39. ,@(mapcar (lambda (f)
  40. `(unless (fboundp ',f)
  41. (progn
  42. (message "Autoloaded function `%S' defined (%s)"
  43. (quote ,f)
  44. ,libpath)
  45. (autoload (quote ,f)
  46. ,libname
  47. ,(concat "Autoloaded function defined in \""
  48. libpath
  49. "\".")
  50. t))))
  51. (or (eval functions)
  52. `(,(eval feature)))))
  53. (eval-after-load ,feature
  54. (quote (progn
  55. ,@body)))
  56. (locate-library ,libname))))
  57. (when (autoload-eval-lazily 'tetris nil
  58. (message "Tetris loaded!"))
  59. (message "Tetris found!"))
  60. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  61. ;; package
  62. (set (defvar 10sr-package-list)
  63. '(
  64. vimrc-mode
  65. markdown-mode
  66. yaml-mode
  67. gnuplot-mode
  68. php-mode
  69. erlang
  70. js2-mode
  71. js-doc
  72. git-commit
  73. gitignore-mode
  74. adoc-mode
  75. go-mode
  76. ;; It seems malabar has been merged into jdee and this package
  77. ;; already removed
  78. ;; malabar-mode
  79. ;; ack
  80. color-moccur
  81. ggtags
  82. flycheck
  83. auto-highlight-symbol
  84. hl-todo
  85. ;; Currently not available
  86. ;; pp-c-l
  87. xclip
  88. foreign-regexp
  89. multi-term
  90. term-run
  91. editorconfig
  92. git-ps1-mode
  93. restart-emacs
  94. fill-column-indicator
  95. pkgbuild-mode
  96. minibuffer-line
  97. which-key
  98. ;; I think this works in place of my autosave lib
  99. super-save
  100. pipenv
  101. imenu-list
  102. page-break-lines
  103. sync-recentf
  104. aggressive-indent
  105. fancy-narrow
  106. scala-mode
  107. ;;ensime
  108. editorconfig
  109. editorconfig-custom-majormode
  110. git-command
  111. prompt-text
  112. ;; 10sr repository
  113. ;; 10sr-extras
  114. terminal-title
  115. recentf-show
  116. dired-list-all-mode
  117. pack
  118. set-modeline-color
  119. read-only-only-mode
  120. smart-revert
  121. autosave
  122. ;;window-organizer
  123. remember-major-modes-mode
  124. ilookup
  125. pasteboard
  126. end-mark
  127. sl
  128. gosh-mode
  129. ))
  130. (when (safe-require-or-eval 'package)
  131. (setq package-archives
  132. `(,@package-archives
  133. ("melpa" . "https://melpa.org/packages/")
  134. ;; Somehow fails to download via https
  135. ("10sr-el" . "http://10sr.github.io/emacs-lisp/elpa/")))
  136. (package-initialize)
  137. (defun my-auto-install-package ()
  138. "Install packages semi-automatically."
  139. (interactive)
  140. (package-refresh-contents)
  141. (mapc (lambda (pkg)
  142. (or (package-installed-p pkg)
  143. (package-install pkg)))
  144. 10sr-package-list))
  145. )
  146. ;; (lazy-load-eval 'sudoku)
  147. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  148. ;; my-idle-hook
  149. (defvar my-idle-hook nil
  150. "Hook run when idle for several secs.")
  151. (defvar my-idle-hook-sec 5
  152. "Second to run `my-idle-hook'.")
  153. (run-with-idle-timer my-idle-hook-sec
  154. t
  155. (lambda ()
  156. (run-hooks 'my-idle-hook)))
  157. ;; (add-hook 'my-idle-hook
  158. ;; (lambda ()
  159. ;; (message "idle hook message")))
  160. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  161. ;; start and quit
  162. (setq inhibit-startup-message t)
  163. (setq confirm-kill-emacs 'y-or-n-p)
  164. (setq gc-cons-threshold (* 1024 1024 4))
  165. (setq garbage-collection-messages t)
  166. (when window-system
  167. (add-to-list 'default-frame-alist '(cursor-type . box))
  168. (add-to-list 'default-frame-alist '(background-color . "white"))
  169. (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
  170. ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))
  171. ;; does not work?
  172. )
  173. ;; (add-to-list 'default-frame-alist '(cursor-type . box))
  174. (if window-system (menu-bar-mode 1) (menu-bar-mode 0))
  175. (and (fboundp 'tool-bar-mode)
  176. (tool-bar-mode 0))
  177. (and (fboundp 'set-scroll-bar-mode)
  178. (set-scroll-bar-mode nil))
  179. (call-after-init
  180. (lambda ()
  181. (message "%s %s" invocation-name emacs-version)
  182. (message "Invocation directory: %s" default-directory)
  183. (message "%s was taken to initialize emacs." (emacs-init-time))
  184. (view-echo-area-messages)
  185. ;; (view-emacs-news)
  186. ))
  187. (cd ".") ; when using windows use / instead of \ in `default-directory'
  188. ;; locale
  189. (set-language-environment "Japanese")
  190. (set-default-coding-systems 'utf-8-unix)
  191. (prefer-coding-system 'utf-8-unix)
  192. (setq system-time-locale "C")
  193. ;; my prefix map
  194. (defvar my-prefix-map nil
  195. "My prefix map.")
  196. (define-prefix-command 'my-prefix-map)
  197. (define-key ctl-x-map (kbd "C-x") 'my-prefix-map)
  198. (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
  199. (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
  200. ;; (comint-show-maximum-output)
  201. ;; kill scratch
  202. (call-after-init (lambda ()
  203. (let ((buf (get-buffer "*scratch*")))
  204. (when buf
  205. (kill-buffer buf)))))
  206. ;; modifier keys
  207. ;; (setq mac-option-modifier 'control)
  208. ;; display
  209. (setq visible-bell t)
  210. (setq ring-bell-function 'ignore)
  211. (mouse-avoidance-mode 'banish)
  212. (setq echo-keystrokes 0.1)
  213. (defun reload-init-file ()
  214. "Reload Emacs init file."
  215. (interactive)
  216. (when (and user-init-file
  217. (file-readable-p user-init-file))
  218. (load-file user-init-file)))
  219. (safe-require-or-eval 'session)
  220. ;; server
  221. (set-variable 'server-name (concat "server"
  222. (number-to-string (emacs-pid))))
  223. ;; In Cygwin Environment `server-runnning-p' stops when server-use-tcp is nil
  224. ;; In Darwin environment, init fails with message like 'Service name too long'
  225. ;; when server-use-tcp is nil
  226. (when (or (eq system-type
  227. 'cygwin)
  228. (eq system-type
  229. 'darwin))
  230. (set-variable 'server-use-tcp t))
  231. ;; MSYS2 fix
  232. (when (eq system-type
  233. 'windows-nt)
  234. (setq shell-file-name
  235. (executable-find "bash"))
  236. '(setq function-key-map
  237. `(,@function-key-map ([pause] . [?\C-c])
  238. ))
  239. (define-key key-translation-map
  240. (kbd "<pause>")
  241. (kbd "C-c"))
  242. '(keyboard-translate [pause]
  243. (kbd "C-c")p)
  244. ;; TODO: move to other place later
  245. (when (not window-system)
  246. (setq interprogram-paste-function nil)
  247. (setq interprogram-cut-function nil)))
  248. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  249. ;; global keys
  250. (global-set-key (kbd "<up>") 'scroll-down-line)
  251. (global-set-key (kbd "<down>") 'scroll-up-line)
  252. (global-set-key (kbd "<left>") 'scroll-down)
  253. (global-set-key (kbd "<right>") 'scroll-up)
  254. ;; (define-key my-prefix-map (kbd "C-h") help-map)
  255. (global-set-key (kbd "C-\\") help-map)
  256. (define-key ctl-x-map (kbd "DEL") help-map)
  257. (define-key ctl-x-map (kbd "C-h") help-map)
  258. (define-key help-map "a" 'apropos)
  259. ;; disable annoying keys
  260. (global-set-key [prior] 'ignore)
  261. (global-set-key (kbd "<next>") 'ignore)
  262. (global-set-key [menu] 'ignore)
  263. (global-set-key [down-mouse-1] 'ignore)
  264. (global-set-key [down-mouse-2] 'ignore)
  265. (global-set-key [down-mouse-3] 'ignore)
  266. (global-set-key [mouse-1] 'ignore)
  267. (global-set-key [mouse-2] 'ignore)
  268. (global-set-key [mouse-3] 'ignore)
  269. (global-set-key (kbd "<eisu-toggle>") 'ignore)
  270. (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
  271. (when (safe-require-or-eval 'which-key)
  272. (which-key-mode))
  273. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  274. ;; editting
  275. (setq kill-whole-line t)
  276. (setq scroll-conservatively 35
  277. scroll-margin 2)
  278. (setq-default major-mode 'text-mode)
  279. (setq next-line-add-newlines nil)
  280. (setq kill-read-only-ok t)
  281. (setq truncate-partial-width-windows nil) ; when splitted horizontally
  282. ;; (setq-default line-spacing 0.2)
  283. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  284. ;; (setq-default tab-width 4)
  285. (setq-default indent-tabs-mode nil)
  286. (setq-default indent-line-function 'indent-to-left-margin)
  287. ;; (setq-default indent-line-function nil)
  288. (setq-default truncate-lines nil)
  289. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  290. (delete-selection-mode 1)
  291. (cua-mode 0)
  292. (setq line-move-visual nil)
  293. ;; key bindings
  294. ;; moving around
  295. ;;(keyboard-translate ?\M-j ?\C-j)
  296. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  297. (define-key esc-map "p" 'backward-paragraph)
  298. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  299. (define-key esc-map "n" 'forward-paragraph)
  300. (global-set-key (kbd "C-<up>") 'scroll-down-line)
  301. (global-set-key (kbd "C-<down>") 'scroll-up-line)
  302. (global-set-key (kbd "C-<left>") 'scroll-down)
  303. (global-set-key (kbd "C-<right>") 'scroll-up)
  304. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  305. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  306. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  307. ;; C-h and DEL
  308. (global-set-key (kbd "C-h") (kbd "DEL"))
  309. ;;(global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  310. (global-set-key (kbd "C-m") 'newline-and-indent)
  311. ;; (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  312. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  313. (define-key esc-map "u" 'undo)
  314. (define-key esc-map "i" (kbd "ESC TAB"))
  315. ;; (global-set-key (kbd "C-r") 'query-replace-regexp)
  316. (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  317. (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  318. (define-key my-prefix-map (kbd "C-o") 'occur)
  319. (require 'page-ext nil t)
  320. (when (safe-require-or-eval 'page-break-lines)
  321. (global-page-break-lines-mode 1))
  322. (when (safe-require-or-eval 'fancy-narrow)
  323. (fancy-narrow-mode 1))
  324. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  325. ;; title and mode-line
  326. (when (safe-require-or-eval 'terminal-title)
  327. ;; if TERM is not screen use default value
  328. (if (getenv "TMUX")
  329. ;; if use tmux locally just basename of current dir
  330. (set-variable 'terminal-title-format
  331. '((file-name-nondirectory (directory-file-name
  332. default-directory))))
  333. (if (and (let ((tty-type (frame-parameter nil
  334. 'tty-type)))
  335. (and tty-type
  336. (equal (car (split-string tty-type
  337. "-"))
  338. "screen")))
  339. (not (getenv "SSH_CONNECTION")))
  340. (set-variable 'terminal-title-format
  341. '((file-name-nondirectory (directory-file-name
  342. default-directory))))
  343. ;; seems that TMUX is used locally and ssh to remote host
  344. (set-variable 'terminal-title-format
  345. `("em:"
  346. ,user-login-name
  347. "@"
  348. ,(car (split-string (system-name)
  349. "\\."))
  350. ":"
  351. default-directory))
  352. )
  353. )
  354. (terminal-title-mode))
  355. (setq eol-mnemonic-dos "\\r\\n")
  356. (setq eol-mnemonic-mac "\\r")
  357. (setq eol-mnemonic-unix "")
  358. (which-function-mode 0)
  359. (line-number-mode 0)
  360. (column-number-mode 0)
  361. (size-indication-mode 0)
  362. (setq mode-line-position
  363. '(:eval (format "L%%l/%d:C%%c"
  364. (count-lines (point-max)
  365. (point-min)))))
  366. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  367. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  368. ;; minibuffer
  369. (setq insert-default-directory t)
  370. (setq completion-ignore-case t
  371. read-file-name-completion-ignore-case t
  372. read-buffer-completion-ignore-case t)
  373. (setq resize-mini-windows t)
  374. (temp-buffer-resize-mode 1)
  375. (savehist-mode 1)
  376. (defvar display-time-format "%Y/%m/%d %a %H:%M")
  377. (set-variable 'help-at-pt-display-when-idle t)
  378. (fset 'yes-or-no-p 'y-or-n-p)
  379. ;; complete symbol when `eval'
  380. (define-key read-expression-map (kbd "TAB") 'completion-at-point)
  381. (define-key minibuffer-local-map (kbd "C-u")
  382. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  383. ;; I dont know these bindings are good
  384. (define-key minibuffer-local-map (kbd "C-p") (kbd "ESC p"))
  385. (define-key minibuffer-local-map (kbd "C-n") (kbd "ESC n"))
  386. (when (safe-require-or-eval 'minibuffer-line)
  387. (set-face-underline 'minibuffer-line nil)
  388. (set-variable 'minibuffer-line-refresh-interval
  389. 25)
  390. ;; Set idle timer
  391. (defvar my-minibuffer-line--idle-timer nil)
  392. (defvar minibuffer-line-mode)
  393. (add-hook 'minibuffer-line-mode-hook
  394. (lambda ()
  395. (when my-minibuffer-line--idle-timer
  396. (cancel-timer my-minibuffer-line--idle-timer)
  397. (setq my-minibuffer-line--idle-timer nil))
  398. (when minibuffer-line-mode
  399. (setq my-minibuffer-line--idle-timer
  400. (run-with-idle-timer 0.5
  401. t
  402. 'minibuffer-line--update)))))
  403. (set-variable 'minibuffer-line-format
  404. `(,(concat user-login-name
  405. "@"
  406. (car (split-string (system-name)
  407. "\\."))
  408. ":")
  409. (:eval (abbreviate-file-name (or buffer-file-name
  410. default-directory)))
  411. (:eval (and (fboundp 'git-ps1-mode-get-current)
  412. (git-ps1-mode-get-current " [GIT:%s]")))
  413. " "
  414. (:eval (format-time-string display-time-format))))
  415. (minibuffer-line-mode 1)
  416. )
  417. (when (safe-require-or-eval 'prompt-text)
  418. (set-variable 'prompt-text-format
  419. `(,(concat ""
  420. user-login-name
  421. "@"
  422. (car (split-string (system-name)
  423. "\\."))
  424. ":")
  425. (:eval (abbreviate-file-name (or buffer-file-name
  426. default-directory)))
  427. (:eval (and (fboundp 'git-ps1-mode-get-current)
  428. (git-ps1-mode-get-current " [GIT:%s]")))
  429. " "
  430. (:eval (format-time-string display-time-format))
  431. "\n"
  432. (:eval (symbol-name this-command))
  433. ": "))
  434. (prompt-text-mode 1))
  435. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  436. ;; letters, font-lock mode and fonts
  437. (setq text-quoting-style 'grave)
  438. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  439. ;; (set-window-margins (selected-window) 1 1)
  440. (unless window-system
  441. (setq frame-background-mode 'dark))
  442. (and (or (eq system-type 'Darwin)
  443. (eq system-type 'darwin))
  444. (fboundp 'mac-set-input-method-parameter)
  445. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  446. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  447. (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
  448. (boundp 'input-method-inactivate-hook))
  449. (add-hook 'input-method-activate-hook
  450. (lambda () (set-cursor-color "red")))
  451. (add-hook 'input-method-inactivate-hook
  452. (lambda () (set-cursor-color "black"))))
  453. (when (safe-require-or-eval 'paren)
  454. (show-paren-mode 1)
  455. (setq show-paren-delay 0.5
  456. show-paren-style 'parenthesis) ; mixed is hard to read
  457. ;; (set-face-background 'show-paren-match
  458. ;; "black")
  459. ;; ;; (face-foreground 'default))
  460. ;; (set-face-foreground 'show-paren-match
  461. ;; "white")
  462. ;; (set-face-inverse-video-p 'show-paren-match
  463. ;; t)
  464. )
  465. (transient-mark-mode 1)
  466. (global-font-lock-mode 1)
  467. (setq font-lock-global-modes
  468. '(not
  469. help-mode
  470. eshell-mode
  471. ;;term-mode
  472. Man-mode))
  473. ;; (standard-display-ascii ?\n "$\n")
  474. ;; (defvar my-eol-face
  475. ;; '(("\n" . (0 font-lock-comment-face t nil)))
  476. ;; )
  477. ;; (defvar my-tab-face
  478. ;; '(("\t" . '(0 highlight t nil))))
  479. (defvar my-jspace-face
  480. '(("\u3000" . '(0 highlight t nil))))
  481. (add-hook 'font-lock-mode-hook
  482. (lambda ()
  483. ;; (font-lock-add-keywords nil my-eol-face)
  484. (font-lock-add-keywords nil my-jspace-face)
  485. ))
  486. (when (safe-require-or-eval 'whitespace)
  487. (add-to-list 'whitespace-display-mappings
  488. ;; We need t since last one takes precedence
  489. `(tab-mark ?\t ,(vconcat "^I\t")) t)
  490. ;; (add-to-list 'whitespace-display-mappings
  491. ;; `(newline-mark ?\n ,(vconcat "$\n")))
  492. (setq whitespace-style '(face
  493. trailing ; trailing blanks
  494. ;; tabs
  495. ;; spaces
  496. ;; lines
  497. lines-tail ; lines over 80
  498. newline ; newlines
  499. empty ; empty lines at beg or end of buffer
  500. ;; big-indent
  501. ;; space-mark
  502. tab-mark
  503. newline-mark ; use display table for newline
  504. ))
  505. ;; (setq whitespace-newline 'font-lock-comment-face)
  506. ;; (setq whitespace-style (delq 'newline-mark whitespace-style))
  507. (defun my-whitesspace-mode-reload ()
  508. "Reload whitespace-mode config."
  509. (interactive)
  510. (when whitespace-mode
  511. (whitespace-mode 0)
  512. (whitespace-mode 1)))
  513. (set-variable 'whitespace-line-column nil)
  514. (global-whitespace-mode t)
  515. (add-hook 'dired-mode-hook
  516. (lambda ()
  517. (set (make-local-variable 'whitespace-style) nil)))
  518. (if (eq (display-color-cells)
  519. 256)
  520. (set-face-foreground 'whitespace-newline "color-109")
  521. ;; (progn
  522. ;; (set-face-bold-p 'whitespace-newline
  523. ;; t))
  524. ))
  525. (and nil
  526. '(safe-require-or-eval 'fill-column-indicator)
  527. (setq fill-column-indicator))
  528. ;; highlight current line
  529. ;; http://wiki.riywo.com/index.php?Meadow
  530. (face-spec-set 'hl-line
  531. '((((min-colors 256)
  532. (background dark))
  533. (:background "color-234"))
  534. (((min-colors 256)
  535. (background light))
  536. (:background "color-234"))
  537. (t
  538. (:underline "black"))))
  539. (set-variable 'hl-line-global-modes
  540. '(not
  541. term-mode))
  542. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  543. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  544. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  545. ;;(safe-require-or-eval 'set-modeline-color)
  546. ;; (let ((fg (face-foreground 'default))
  547. ;; (bg (face-background 'default)))
  548. ;; (set-face-background 'mode-line-inactive
  549. ;; (if (face-inverse-video-p 'mode-line) fg bg))
  550. ;; (set-face-foreground 'mode-line-inactive
  551. ;; (if (face-inverse-video-p 'mode-line) bg fg)))
  552. ;; (set-face-underline 'mode-line-inactive
  553. ;; t)
  554. ;; (set-face-underline 'vertical-border
  555. ;; nil)
  556. (when (safe-require-or-eval 'end-mark)
  557. (global-end-mark-mode))
  558. ;; M-x highlight-* to highlight things
  559. (global-hi-lock-mode 1)
  560. (unless (fboundp 'highlight-region-text)
  561. (defun highlight-region-text (beg end)
  562. "Highlight text between BEG and END."
  563. (interactive "r")
  564. (highlight-regexp (regexp-quote (buffer-substring-no-properties beg
  565. end)))
  566. (setq deactivate-mark t)))
  567. (when (safe-require-or-eval 'auto-highlight-symbol)
  568. (set-variable 'ahs-idle-interval 0.6)
  569. (global-auto-highlight-symbol-mode 1))
  570. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  571. ;; file handling
  572. (when (safe-require-or-eval 'editorconfig)
  573. ;; (set-variable 'editorconfig-get-properties-function
  574. ;; 'editorconfig-core-get-properties-hash)
  575. (editorconfig-mode 1)
  576. (set-variable 'editorconfig-mode-lighter " EC")
  577. (with-eval-after-load 'org-src
  578. ;; [*.org\[\*Org Src*\[ c \]*\]]
  579. (add-hook 'org-src-mode-hook
  580. 'editorconfig-mode-apply t)))
  581. (when (fboundp 'editorconfig-custom-majormode)
  582. (add-hook 'editorconfig-custom-hooks
  583. 'editorconfig-custom-majormode))
  584. ;; Add readonly=true to set read-only-mode
  585. (add-hook 'editorconfig-custom-hooks
  586. (lambda (props)
  587. (let ((r (gethash 'readonly props)))
  588. (when (and (string= r "true")
  589. (not buffer-read-only))
  590. (read-only-mode 1)))))
  591. ;; (when (fboundp 'editorconfig-charset-extras)
  592. ;; (add-hook 'editorconfig-custom-hooks
  593. ;; 'editorconfig-charset-extras))
  594. (setq revert-without-query '(".+"))
  595. ;; save cursor position
  596. (when (safe-require-or-eval 'saveplace)
  597. (setq-default save-place t)
  598. (setq save-place-file (concat user-emacs-directory
  599. "places")))
  600. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  601. (setq make-backup-files t)
  602. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  603. (setq backup-directory-alist
  604. (cons (cons "\\.*$" (expand-file-name (concat user-emacs-directory
  605. "backup")))
  606. backup-directory-alist))
  607. (setq version-control 'never)
  608. (setq delete-old-versions t)
  609. (setq auto-save-list-file-prefix (expand-file-name (concat user-emacs-directory
  610. "auto-save/")))
  611. (setq delete-auto-save-files t)
  612. (add-to-list 'completion-ignored-extensions ".bak")
  613. (set-variable 'completion-cycle-threshold nil) ;; NEVER use
  614. (setq delete-by-moving-to-trash t)
  615. ;; trash-directory "~/.emacs.d/trash")
  616. (add-hook 'after-save-hook
  617. 'executable-make-buffer-file-executable-if-script-p)
  618. (set-variable 'bookmark-default-file
  619. (expand-file-name (concat user-emacs-directory
  620. "bmk")))
  621. (set-variable 'bookmark-save-flag
  622. 1)
  623. (with-eval-after-load 'recentf
  624. (defvar recentf-exclude)
  625. (defvar bookmark-default-file)
  626. (add-to-list 'recentf-exclude
  627. (regexp-quote bookmark-default-file)))
  628. (when (safe-require-or-eval 'smart-revert)
  629. (smart-revert-on))
  630. ;; autosave
  631. (when (safe-require-or-eval 'autosave)
  632. (autosave-set 8))
  633. ;; bookmarks
  634. (define-key ctl-x-map "m" 'list-bookmarks)
  635. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  636. ;; buffer killing
  637. ;; (defun my-delete-window-killing-buffer () nil)
  638. (defun my-query-kill-current-buffer ()
  639. "Interactively kill current buffer."
  640. (interactive)
  641. (if (y-or-n-p (concat "kill current buffer? :"))
  642. (kill-buffer (current-buffer))))
  643. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  644. (substitute-key-definition 'kill-buffer
  645. 'my-query-kill-current-buffer
  646. global-map)
  647. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  648. ;; share clipboard with x
  649. ;; this page describes this in details, but only these sexps seem to be needed
  650. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  651. (and nil
  652. (not window-system)
  653. (not (eq window-system 'mac))
  654. (getenv "DISPLAY")
  655. (not (equal (getenv "DISPLAY") ""))
  656. (executable-find "xclip")
  657. ;; (< emacs-major-version 24)
  658. '(safe-require-or-eval 'xclip)
  659. nil
  660. (turn-on-xclip))
  661. (and (eq system-type 'darwin)
  662. (safe-require-or-eval 'pasteboard)
  663. (turn-on-pasteboard))
  664. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  665. ;; some modes and hooks
  666. ;; Include some extra modes
  667. (require 'generic-x)
  668. (when (safe-require-or-eval 'aggressive-indent)
  669. (defvar aggressive-indent-excluded-modes)
  670. (add-to-list 'aggressive-indent-excluded-modes
  671. 'diff-mode)
  672. (global-aggressive-indent-mode 1))
  673. (when (autoload-eval-lazily 'ggtags)
  674. (add-hook 'c-mode-common-hook
  675. (lambda ()
  676. (when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
  677. (ggtags-mode 1))))
  678. (add-hook 'python-mode-hook
  679. (lambda ()
  680. (ggtags-mode 1))))
  681. (when (autoload-eval-lazily 'imenu-list)
  682. ;; (set-variable 'imenu-list-auto-resize t)
  683. (set-variable 'imenu-list-focus-after-activation t)
  684. (define-key ctl-x-map "l" 'imenu-list-smart-toggle))
  685. (with-eval-after-load 'compile
  686. (defvar compilation-filter-start)
  687. (defvar compilation-error-regexp-alist)
  688. (require 'ansi-color)
  689. (add-hook 'compilation-filter-hook
  690. (lambda ()
  691. (let ((inhibit-read-only t))
  692. (ansi-color-apply-on-region compilation-filter-start
  693. (point)))))
  694. (add-to-list 'compilation-error-regexp-alist
  695. ;; ansible-lint
  696. '("^\\([^ \n]+\\):\\([0-9]+\\)$" 1 2)))
  697. ;; Workaround to avoid ensime error
  698. (defvar ensime-mode-key-prefix nil)
  699. ;; http://qiita.com/sune2/items/b73037f9e85962f5afb7
  700. (when (safe-require-or-eval 'company)
  701. (global-company-mode)
  702. (set-variable 'company-idle-delay 0.5)
  703. (set-variable 'company-minimum-prefix-length 2)
  704. (set-variable 'company-selection-wrap-around t))
  705. ;; https://github.com/lunaryorn/flycheck
  706. (when (safe-require-or-eval 'flycheck)
  707. (call-after-init 'global-flycheck-mode))
  708. (when (autoload-eval-lazily 'ilookup)
  709. (define-key ctl-x-map "d" 'ilookup-open-word))
  710. (set-variable 'ac-ignore-case nil)
  711. (when (autoload-eval-lazily 'term-run '(term-run-shell-command term-run))
  712. (define-key ctl-x-map "t" 'term-run-shell-command))
  713. (add-to-list 'safe-local-variable-values
  714. '(encoding utf-8))
  715. (setq enable-local-variables :safe)
  716. ;; (when (safe-require-or-eval 'remember-major-modes-mode)
  717. ;; (remember-major-modes-mode 1))
  718. ;; Detect file type from shebang and set major-mode.
  719. (add-to-list 'interpreter-mode-alist
  720. '("python3" . python-mode))
  721. (add-to-list 'interpreter-mode-alist
  722. '("python2" . python-mode))
  723. (with-eval-after-load 'python
  724. (defvar python-mode-map (make-sparse-keymap))
  725. (define-key python-mode-map (kbd "C-m") 'newline-and-indent))
  726. (when (autoload-eval-lazily 'pipenv)
  727. (add-hook 'python-mode-hook
  728. (lambda ()
  729. (pipenv-mode 1)
  730. (pipenv-projectile-after-switch-default)))
  731. )
  732. (set-variable 'flycheck-python-pycompile-executable "python3")
  733. ;; http://fukuyama.co/foreign-regexp
  734. '(and (safe-require-or-eval 'foreign-regexp)
  735. (progn
  736. (setq foreign-regexp/regexp-type 'perl)
  737. '(setq reb-re-syntax 'foreign-regexp)
  738. ))
  739. (autoload-eval-lazily 'sql '(sql-mode)
  740. (require 'sql-indent nil t))
  741. (when (autoload-eval-lazily 'git-command)
  742. (define-key ctl-x-map "g" 'git-command))
  743. (when (safe-require-or-eval 'git-commit)
  744. (global-git-commit-mode 1))
  745. (with-eval-after-load 'git-commit
  746. (add-hook 'git-commit-setup-hook
  747. 'turn-off-auto-fill t))
  748. (autoload-eval-lazily 'sl)
  749. (with-eval-after-load 'rst
  750. (defvar rst-mode-map)
  751. (define-key rst-mode-map (kbd "C-m") 'newline-and-indent))
  752. (with-eval-after-load 'jdee
  753. (add-hook 'jdee-mode-hook
  754. (lambda ()
  755. (make-local-variable 'global-mode-string)
  756. (add-to-list 'global-mode-string
  757. mode-line-position))))
  758. ;; Cannot enable error thrown. Why???
  759. ;; https://github.com/m0smith/malabar-mode#Installation
  760. ;; (when (autoload-eval-lazily 'malabar-mode)
  761. ;; (add-to-list 'load-path
  762. ;; (expand-file-name (concat user-emacs-directory "/cedet")))
  763. ;; (safe-require-or-eval 'cedet-devel-load)
  764. ;; (call-after-init 'activate-malabar-mode))
  765. (with-eval-after-load 'make-mode
  766. (defvar makefile-mode-map (make-sparse-keymap))
  767. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
  768. ;; this functions is set in write-file-functions, i cannot find any
  769. ;; good way to remove this.
  770. (fset 'makefile-warn-suspicious-lines 'ignore))
  771. (with-eval-after-load 'verilog-mode
  772. (defvar verilog-mode-map (make-sparse-keymap))
  773. (define-key verilog-mode-map ";" 'self-insert-command))
  774. (setq diff-switches "-u")
  775. (with-eval-after-load 'diff-mode
  776. ;; (when (and (eq major-mode
  777. ;; 'diff-mode)
  778. ;; (not buffer-file-name))
  779. ;; ;; do not pass when major-mode is derived mode of diff-mode
  780. ;; (view-mode 1))
  781. (set-face-attribute 'diff-header nil
  782. :foreground nil
  783. :background nil
  784. :weight 'bold)
  785. (set-face-attribute 'diff-file-header nil
  786. :foreground nil
  787. :background nil
  788. :weight 'bold)
  789. (set-face-foreground 'diff-index "blue")
  790. (set-face-attribute 'diff-hunk-header nil
  791. :foreground "cyan"
  792. :weight 'normal)
  793. (set-face-attribute 'diff-context nil
  794. ;; :foreground "white"
  795. :foreground nil
  796. :weight 'normal)
  797. (set-face-foreground 'diff-removed "red")
  798. (set-face-foreground 'diff-added "green")
  799. (set-face-background 'diff-removed nil)
  800. (set-face-background 'diff-added nil)
  801. (set-face-attribute 'diff-changed nil
  802. :foreground "magenta"
  803. :weight 'normal)
  804. (set-face-attribute 'diff-refine-changed nil
  805. :foreground nil
  806. :background nil
  807. :weight 'bold
  808. :inverse-video t)
  809. ;; Annoying !
  810. ;;(diff-auto-refine-mode)
  811. )
  812. ;; (ffap-bindings)
  813. (set-variable 'browse-url-browser-function
  814. 'eww-browse-url)
  815. (set-variable 'sh-here-document-word "__EOC__")
  816. (when (autoload-eval-lazily 'adoc-mode
  817. nil
  818. (defvar adoc-mode-map (make-sparse-keymap))
  819. (define-key adoc-mode-map (kbd "C-m") 'newline))
  820. (setq auto-mode-alist
  821. `(("\\.adoc\\'" . adoc-mode)
  822. ("\\.asciidoc\\'" . adoc-mode)
  823. ,@auto-mode-alist)))
  824. (with-eval-after-load 'markup-faces
  825. ;; Is this too match ?
  826. (set-face-foreground 'markup-meta-face
  827. "color-245")
  828. (set-face-foreground 'markup-meta-hide-face
  829. "color-245")
  830. )
  831. ;; TODO: check if this is required
  832. (when (autoload-eval-lazily 'groovy-mode nil
  833. (defvar groovy-mode-map (make-sparse-keymap))
  834. (define-key groovy-mode-map "(" 'self-insert-command)
  835. (define-key groovy-mode-map ")" 'self-insert-command)
  836. (define-key groovy-mode-map (kbd "C-m") 'newline-and-indent)
  837. )
  838. (add-to-list 'auto-mode-alist
  839. '("build\\.gradle\\'" . groovy-mode)))
  840. (with-eval-after-load 'yaml-mode
  841. (defvar yaml-mode-map (make-sparse-keymap))
  842. (define-key yaml-mode-map (kbd "C-m") 'newline))
  843. (with-eval-after-load 'html-mode
  844. (defvar html-mode-map (make-sparse-keymap))
  845. (define-key html-mode-map (kbd "C-m") 'reindent-then-newline-and-indent))
  846. (with-eval-after-load 'text-mode
  847. (define-key text-mode-map (kbd "C-m") 'newline))
  848. (autoload-eval-lazily 'info nil
  849. (defvar Info-additional-directory-list)
  850. (dolist (dir (directory-files (concat user-emacs-directory
  851. "info")
  852. t
  853. "^[^.].*"))
  854. (when (file-directory-p dir)
  855. (add-to-list 'Info-additional-directory-list
  856. dir)))
  857. (let ((dir (expand-file-name "~/.brew/share/info")))
  858. (when (file-directory-p dir)
  859. (add-to-list 'Info-additional-directory-list
  860. dir))))
  861. (with-eval-after-load 'apropos
  862. (defvar apropos-mode-map (make-sparse-keymap))
  863. (define-key apropos-mode-map "n" 'next-line)
  864. (define-key apropos-mode-map "p" 'previous-line))
  865. ;; `isearch' library does not call `provide' so cannot use with-eval-after-load
  866. ;; (define-key isearch-mode-map
  867. ;; (kbd "C-j") 'isearch-other-control-char)
  868. ;; (define-key isearch-mode-map
  869. ;; (kbd "C-k") 'isearch-other-control-char)
  870. ;; (define-key isearch-mode-map
  871. ;; (kbd "C-h") 'isearch-other-control-char)
  872. (define-key isearch-mode-map (kbd "C-h") 'isearch-delete-char)
  873. (define-key isearch-mode-map (kbd "M-r")
  874. 'isearch-query-replace-regexp)
  875. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  876. (setq lazy-highlight-cleanup nil)
  877. ;; face for isearch highlighing
  878. (set-face-attribute 'lazy-highlight
  879. nil
  880. :foreground `unspecified
  881. :background `unspecified
  882. :underline t
  883. ;; :weight `bold
  884. )
  885. (add-hook 'outline-mode-hook
  886. (lambda ()
  887. (when (string-match "\\.md\\'" buffer-file-name)
  888. (set (make-local-variable 'outline-regexp) "#+ "))))
  889. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  890. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  891. (when (autoload-eval-lazily 'markdown-mode
  892. '(markdown-mode gfm-mode)
  893. (defvar gfm-mode-map (make-sparse-keymap))
  894. (define-key gfm-mode-map (kbd "C-m") 'electric-indent-just-newline))
  895. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'gfm-mode))
  896. (set-variable 'markdown-command (or (executable-find "markdown")
  897. (executable-find "markdown.pl")
  898. ""))
  899. (add-hook 'markdown-mode-hook
  900. (lambda ()
  901. (outline-minor-mode 1)
  902. (flyspell-mode)
  903. (set (make-local-variable 'comment-start) ";")))
  904. )
  905. ;; c-mode
  906. ;; http://www.emacswiki.org/emacs/IndentingC
  907. ;; http://en.wikipedia.org/wiki/Indent_style
  908. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  909. ;; http://seesaawiki.jp/whiteflare503/d/Emacs%20%a5%a4%a5%f3%a5%c7%a5%f3%a5%c8
  910. (with-eval-after-load 'cc-vars
  911. (defvar c-default-style nil)
  912. (add-to-list 'c-default-style
  913. '(c-mode . "k&r"))
  914. (add-to-list 'c-default-style
  915. '(c++-mode . "k&r")))
  916. (autoload-eval-lazily 'js2-mode nil
  917. ;; currently do not use js2-mode
  918. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  919. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  920. ;; (defvar js2-mode-map (make-sparse-keymap))
  921. ;; (define-key js2-mode-map (kbd "C-m") (lambda ()
  922. ;; (interactive)
  923. ;; (js2-enter-key)
  924. ;; (indent-for-tab-command)))
  925. ;; (add-hook (kill-local-variable 'before-save-hook)
  926. ;; 'js2-before-save)
  927. ;; (add-hook 'before-save-hook
  928. ;; 'my-indent-buffer
  929. ;; nil
  930. ;; t)
  931. )
  932. (add-to-list 'interpreter-mode-alist
  933. '("node" . js-mode))
  934. (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  935. (with-eval-after-load 'uniquify
  936. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  937. (setq uniquify-ignore-buffers-re "*[^*]+*")
  938. (setq uniquify-min-dir-content 1))
  939. (with-eval-after-load 'view
  940. (defvar view-mode-map (make-sparse-keymap))
  941. (define-key view-mode-map "j" 'scroll-up-line)
  942. (define-key view-mode-map "k" 'scroll-down-line)
  943. (define-key view-mode-map "v" 'toggle-read-only)
  944. (define-key view-mode-map "q" 'bury-buffer)
  945. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  946. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  947. ;; (define-key view-mode-map
  948. ;; "n" 'nonincremental-repeat-search-forward)
  949. ;; (define-key view-mode-map
  950. ;; "N" 'nonincremental-repeat-search-backward)
  951. (define-key view-mode-map "/" 'isearch-forward-regexp)
  952. (define-key view-mode-map "?" 'isearch-backward-regexp)
  953. (define-key view-mode-map "n" 'isearch-repeat-forward)
  954. (define-key view-mode-map "N" 'isearch-repeat-backward)
  955. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point))
  956. (global-set-key "\M-r" 'view-mode)
  957. ;; (setq view-read-only t)
  958. (with-eval-after-load 'term
  959. (defvar term-raw-map (make-sparse-keymap))
  960. (define-key term-raw-map (kbd "C-x")
  961. (lookup-key (current-global-map)
  962. (kbd "C-x"))))
  963. (add-hook 'term-mode-hook
  964. (lambda ()
  965. ;; Stop current line highlighting
  966. (set (make-local-variable (defvar hl-line-range-function))
  967. (lambda () '(0 . 0)))
  968. (set (make-local-variable 'scroll-margin)
  969. 0)))
  970. (add-hook 'Man-mode-hook
  971. (lambda ()
  972. (view-mode 1)
  973. (setq truncate-lines nil)))
  974. (set-variable 'Man-notify-method (if window-system
  975. 'newframe
  976. 'aggressive))
  977. (set-variable 'woman-cache-filename (expand-file-name (concat user-emacs-directory
  978. "woman_cache.el")))
  979. ;; not work because man.el will be loaded when man called
  980. (defalias 'man 'woman)
  981. (add-to-list 'auto-mode-alist
  982. '("tox\\.ini\\'" . conf-unix-mode))
  983. (when (autoload-eval-lazily 'toml-mode)
  984. (add-to-list 'auto-mode-alist
  985. '("/Pipfile\\'" . toml-mode)))
  986. (when (autoload-eval-lazily 'json-mode)
  987. (add-to-list 'auto-mode-alist
  988. '("/Pipfile\\.lock\\'" . json-mode)))
  989. (add-hook 'go-mode-hook
  990. (lambda()
  991. (defvar go-mode-map)
  992. (add-hook 'before-save-hook' 'gofmt-before-save)
  993. (define-key go-mode-map (kbd "M-.") 'godef-jump)))
  994. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  995. ;; buffer switching
  996. (defvar bs-configurations)
  997. (when (autoload-eval-lazily 'bs '(bs-show)
  998. (add-to-list 'bs-configurations
  999. '("specials" "^\\*" nil ".*" nil nil))
  1000. (add-to-list 'bs-configurations
  1001. '("files-and-specials" "^\\*" buffer-file-name ".*" nil nil))
  1002. (defvar bs-mode-map)
  1003. (defvar bs-current-configuration)
  1004. (define-key bs-mode-map (kbd "t")
  1005. ;; TODO: fix toggle feature
  1006. (lambda ()
  1007. (interactive)
  1008. (if (string= "specials"
  1009. bs-current-configuration)
  1010. (bs-set-configuration "files")
  1011. (bs-set-configuration "specials"))
  1012. (bs-refresh)
  1013. (bs-message-without-log "%s"
  1014. (bs--current-config-message))))
  1015. ;; (setq bs-configurations (list
  1016. ;; '("processes" nil get-buffer-process ".*" nil nil)
  1017. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  1018. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  1019. )
  1020. (defalias 'list-buffers 'bs-show)
  1021. (set-variable 'bs-default-configuration "files-and-specials")
  1022. (set-variable 'bs-default-sort-name "by nothing")
  1023. (add-hook 'bs-mode-hook
  1024. (lambda ()
  1025. (set (make-local-variable 'scroll-margin) 0))))
  1026. ;;(iswitchb-mode 1)
  1027. (icomplete-mode)
  1028. (defun iswitchb-buffer-display-other-window ()
  1029. "Do iswitchb in other window."
  1030. (interactive)
  1031. (let ((iswitchb-default-method 'display))
  1032. (call-interactively 'iswitchb-buffer)))
  1033. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1034. ;; vc
  1035. (set-variable 'vc-handled-backends '())
  1036. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1037. ;; recentf-mode
  1038. (set-variable 'recentf-save-file (expand-file-name (concat user-emacs-directory
  1039. "recentf")))
  1040. (set-variable 'recentf-max-menu-items 20)
  1041. (set-variable 'recentf-max-saved-items 30)
  1042. (set-variable 'recentf-show-file-shortcuts-flag nil)
  1043. (set-variable 'recentf-auto-cleanup 3)
  1044. (safe-require-or-eval 'sync-recentf)
  1045. (when (safe-require-or-eval 'recentf)
  1046. (add-to-list 'recentf-exclude
  1047. (regexp-quote recentf-save-file))
  1048. (add-to-list 'recentf-exclude
  1049. (regexp-quote (expand-file-name user-emacs-directory)))
  1050. (add-to-list 'recentf-exclude
  1051. "/sync-recentf-marker\\'")
  1052. (define-key ctl-x-map (kbd "C-r") 'recentf-open-files)
  1053. (remove-hook 'find-file-hook
  1054. 'recentf-track-opened-file)
  1055. (defun my-recentf-load-track-save-list ()
  1056. "Load current recentf list from file, track current visiting file, then save
  1057. the list."
  1058. (recentf-load-list)
  1059. (recentf-track-opened-file)
  1060. (recentf-save-list))
  1061. (add-hook 'find-file-hook
  1062. 'my-recentf-load-track-save-list)
  1063. (add-hook 'kill-emacs-hook
  1064. 'recentf-load-list)
  1065. ;;(run-with-idle-timer 5 t 'recentf-save-list)
  1066. ;; (add-hook 'find-file-hook
  1067. ;; (lambda ()
  1068. ;; (recentf-add-file default-directory)))
  1069. (when (autoload-eval-lazily 'recentf-show)
  1070. (define-key ctl-x-map (kbd "C-r") 'recentf-show)
  1071. ;; (add-hook 'recentf-show-before-listing-hook
  1072. ;; 'recentf-load-list)
  1073. )
  1074. (recentf-mode 1)
  1075. (define-key recentf-dialog-mode-map (kbd "<up>") 'previous-line)
  1076. (define-key recentf-dialog-mode-map (kbd "<down>") 'next-line)
  1077. (define-key recentf-dialog-mode-map "p" 'previous-line)
  1078. (define-key recentf-dialog-mode-map "n" 'next-line)
  1079. (add-hook 'recentf-dialog-mode-hook
  1080. (lambda ()
  1081. ;; (recentf-save-list)
  1082. ;; (define-key recentf-dialog-mode-map (kbd "C-x C-f")
  1083. ;; 'my-recentf-cd-and-find-file)
  1084. (cd "~/"))))
  1085. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1086. ;; dired
  1087. (defun my-dired-echo-file-head (arg)
  1088. "Echo head of current file.
  1089. ARG is num to show, or defaults to 7."
  1090. (interactive "P")
  1091. (let ((f (dired-get-filename)))
  1092. (message "%s"
  1093. (apply 'concat
  1094. (my-file-head f
  1095. 7)))))
  1096. (defun my-dired-diff ()
  1097. "Show diff of marked file and file of current line."
  1098. (interactive)
  1099. (let ((files (dired-get-marked-files nil nil nil t)))
  1100. (if (eq (car files)
  1101. t)
  1102. (diff (cadr files) (dired-get-filename))
  1103. (message "One file must be marked!"))))
  1104. (defun dired-get-file-info ()
  1105. "Print information of current line file."
  1106. (interactive)
  1107. (let ((f (shell-quote-argument (dired-get-filename t))))
  1108. (if (file-directory-p f)
  1109. (progn
  1110. (message "Calculating disk usage...")
  1111. (shell-command (concat "du -hsD "
  1112. f)))
  1113. (shell-command (concat "file "
  1114. f)))))
  1115. (defun my-dired-scroll-up ()
  1116. "Scroll up."
  1117. (interactive)
  1118. (my-dired-previous-line (- (window-height) 1)))
  1119. (defun my-dired-scroll-down ()
  1120. "Scroll down."
  1121. (interactive)
  1122. (my-dired-next-line (- (window-height) 1)))
  1123. ;; (defun my-dired-forward-line (arg)
  1124. ;; ""
  1125. ;; (interactive "p"))
  1126. (defun my-dired-previous-line (arg)
  1127. "Move ARG lines up."
  1128. (interactive "p")
  1129. (if (> arg 0)
  1130. (progn
  1131. (if (eq (line-number-at-pos)
  1132. 1)
  1133. (goto-char (point-max))
  1134. (forward-line -1))
  1135. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1136. (dired-get-subdir))
  1137. (- arg 1)
  1138. arg)))
  1139. (dired-move-to-filename)))
  1140. (defun my-dired-next-line (arg)
  1141. "Move ARG lines down."
  1142. (interactive "p")
  1143. (if (> arg 0)
  1144. (progn
  1145. (if (eq (point)
  1146. (point-max))
  1147. (goto-char (point-min))
  1148. (forward-line 1))
  1149. (my-dired-next-line (if (or (dired-get-filename nil t)
  1150. (dired-get-subdir))
  1151. (- arg 1)
  1152. arg)))
  1153. (dired-move-to-filename)))
  1154. (defun my-dired-tramp-open (host)
  1155. "Open HOST home directory."
  1156. (interactive "sHostname: ")
  1157. (find-file (format "/scp:%s:" host)))
  1158. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1159. (if (eq window-system 'mac)
  1160. (setq dired-listing-switches "-lhF")
  1161. (setq dired-listing-switches "-lhF --time-style=long-iso")
  1162. )
  1163. (setq dired-listing-switches "-lhF")
  1164. (put 'dired-find-alternate-file 'disabled nil)
  1165. ;; when using dired-find-alternate-file
  1166. ;; reuse current dired buffer for the file to open
  1167. (set-variable 'dired-ls-F-marks-symlinks t)
  1168. (set-variable 'ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1169. (set-variable 'ls-lisp-dirs-first t)
  1170. (set-variable 'ls-lisp-use-localized-time-format t)
  1171. (set-variable 'ls-lisp-format-time-list
  1172. '("%Y-%m-%d %H:%M"
  1173. "%Y-%m-%d "))
  1174. (set-variable 'dired-dwim-target t)
  1175. (set-variable 'dired-isearch-filenames t)
  1176. (set-variable 'dired-hide-details-hide-symlink-targets nil)
  1177. (set-variable 'dired-hide-details-hide-information-lines nil)
  1178. (set-variable 'dired-deletion-confirmer 'y-or-n-p)
  1179. (set-variable 'dired-recursive-deletes 'always)
  1180. ;; (add-hook 'dired-after-readin-hook
  1181. ;; 'my-replace-nasi-none)
  1182. (with-eval-after-load 'dired
  1183. (safe-require-or-eval 'ls-lisp)
  1184. (defvar dired-mode-map (make-sparse-keymap))
  1185. (define-key dired-mode-map "i" 'dired-get-file-info)
  1186. (define-key dired-mode-map "f" 'find-file)
  1187. (define-key dired-mode-map "!" 'shell-command)
  1188. (define-key dired-mode-map "&" 'async-shell-command)
  1189. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1190. (define-key dired-mode-map "=" 'my-dired-diff)
  1191. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1192. (define-key dired-mode-map "b" 'gtkbm)
  1193. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1194. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1195. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1196. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1197. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1198. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  1199. (substitute-key-definition 'dired-next-line
  1200. 'my-dired-next-line
  1201. dired-mode-map)
  1202. (substitute-key-definition 'dired-previous-line
  1203. 'my-dired-previous-line
  1204. dired-mode-map)
  1205. ;; (define-key dired-mode-map (kbd "C-p") 'my-dired-previous-line)
  1206. ;; (define-key dired-mode-map (kbd "p") 'my-dired-previous-line)
  1207. ;; (define-key dired-mode-map (kbd "C-n") 'my-dired-next-line)
  1208. ;; (define-key dired-mode-map (kbd "n") 'my-dired-next-line)
  1209. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  1210. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  1211. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  1212. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  1213. (add-hook 'dired-mode-hook
  1214. (lambda ()
  1215. (when (fboundp 'dired-hide-details-mode)
  1216. (dired-hide-details-mode t)
  1217. (local-set-key "l" 'dired-hide-details-mode))
  1218. (let ((file "._Icon\015"))
  1219. (when nil
  1220. '(file-readable-p file)
  1221. (delete-file file)))))
  1222. (when (autoload-eval-lazily 'pack '(dired-do-pack-or-unpack pack-pack))
  1223. (with-eval-after-load 'dired
  1224. (define-key dired-mode-map "P" 'pack-dired-dwim)))
  1225. (when (autoload-eval-lazily 'dired-list-all-mode)
  1226. (setq dired-listing-switches "-lhF")
  1227. (with-eval-after-load 'dired
  1228. (define-key dired-mode-map "a" 'dired-list-all-mode))))
  1229. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1230. ;; misc funcs
  1231. (defalias 'qcalc 'quick-calc)
  1232. (defun memo (&optional dir)
  1233. "Open memo.txt in DIR."
  1234. (interactive)
  1235. (pop-to-buffer (find-file-noselect (concat (if dir
  1236. (file-name-as-directory dir)
  1237. "")
  1238. "memo.txt"))))
  1239. (set (defvar my-rgrep-alist nil
  1240. "Alist of rgrep command.
  1241. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  1242. condition to choose COMMAND when evaluated.")
  1243. `(
  1244. ;; ripgrep
  1245. ("rg"
  1246. (executable-find "rg")
  1247. "rg --hidden --no-heading --smart-case ")
  1248. ;; git grep
  1249. ("gitgrep"
  1250. (eq 0
  1251. (shell-command "git rev-parse --git-dir"))
  1252. "git --no-pager -c color.grep=always grep -nH -e ")
  1253. ;; sift
  1254. ("sift"
  1255. (executable-find "sift")
  1256. ("sift --binary-skip --filename --line-number --git --smart-case "))
  1257. ;; the silver searcher
  1258. ("ag"
  1259. (executable-find "ag")
  1260. "ag --nogroup --nopager --filename ")
  1261. ;; ack
  1262. ("ack"
  1263. (executable-find "ack")
  1264. "ack --nogroup --nopager --with-filename ")
  1265. ;; gnu global
  1266. ("global"
  1267. (and (require 'ggtags nil t)
  1268. (executable-find "global")
  1269. (ggtags-current-project-root))
  1270. "global --result grep ")
  1271. ;; grep
  1272. ("grep"
  1273. t
  1274. ,(concat "find . "
  1275. "-path '*/.git' -prune -o "
  1276. "-path '*/.svn' -prune -o "
  1277. "-type f -print0 | "
  1278. "xargs -0 grep -nH -e "))
  1279. )
  1280. )
  1281. (defvar my-rgrep-default nil
  1282. "Default command name for my-rgrep.")
  1283. (defun my-rgrep-grep-command (&optional name alist)
  1284. "Return recursive grep command for current directory or nil.
  1285. If NAME is given, use that without testing.
  1286. Commands are searched from ALIST."
  1287. (if alist
  1288. (if name
  1289. ;; if name is given search that from alist and return the command
  1290. (nth 2 (assoc name
  1291. alist))
  1292. ;; if name is not given try test in 1th elem
  1293. (let ((car (car alist))
  1294. (cdr (cdr alist)))
  1295. (if (eval (nth 1 car))
  1296. ;; if the condition is true return the command
  1297. (nth 2 car)
  1298. ;; try next one
  1299. (and cdr
  1300. (my-rgrep-grep-command name cdr)))))
  1301. ;; if alist is not given set default value
  1302. (my-rgrep-grep-command name my-rgrep-alist)))
  1303. (defun my-rgrep (command-args)
  1304. "My recursive grep. Run COMMAND-ARGS.
  1305. If prefix argument is given, use current symbol as default search target
  1306. and search from projectile root (if projectile is available)."
  1307. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  1308. nil)))
  1309. (if cmd
  1310. (list (read-shell-command "grep command: "
  1311. (concat cmd
  1312. (if current-prefix-arg
  1313. (thing-at-point 'symbol t)
  1314. ""))
  1315. 'grep-find-history))
  1316. (error "My-Rgrep: Command for rgrep not found")
  1317. )))
  1318. (if (and current-prefix-arg
  1319. (safe-require-or-eval 'projectile)
  1320. (projectile-project-p))
  1321. (projectile-with-default-dir (projectile-project-root)
  1322. (compilation-start command-args
  1323. 'grep-mode))
  1324. (compilation-start command-args
  1325. 'grep-mode)))
  1326. (defun my-rgrep-thing-at-point-projectile-root ()
  1327. "My recursive grep to find thing at point from project root."
  1328. (interactive)
  1329. (let* ((cmd (my-rgrep-grep-command my-rgrep-default
  1330. nil))
  1331. (command-args
  1332. (if cmd
  1333. (concat cmd
  1334. (or (thing-at-point 'symbol t)
  1335. (error "No symbol at point")))
  1336. (error "My-Rgrep: Command for rgrep not found"))))
  1337. (if (safe-require-or-eval 'projectile)
  1338. (projectile-with-default-dir (projectile-project-root)
  1339. (compilation-start command-args
  1340. 'grep-mode))
  1341. (compilation-start command-args
  1342. 'grep-mode))))
  1343. (defmacro define-my-rgrep (name)
  1344. "Define rgrep for NAME."
  1345. `(defun ,(intern (concat "my-rgrep-"
  1346. name)) ()
  1347. ,(format "My recursive grep by %s."
  1348. name)
  1349. (interactive)
  1350. (let ((my-rgrep-default ,name))
  1351. (if (called-interactively-p 'any)
  1352. (call-interactively 'my-rgrep)
  1353. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  1354. )
  1355. (define-my-rgrep "ack")
  1356. (define-my-rgrep "ag")
  1357. (define-my-rgrep "rg")
  1358. (define-my-rgrep "sift")
  1359. (define-my-rgrep "gitgrep")
  1360. (define-my-rgrep "grep")
  1361. (define-my-rgrep "global")
  1362. (define-key ctl-x-map "s" 'my-rgrep)
  1363. (define-key ctl-x-map "." 'my-rgrep-thing-at-point-projectile-root)
  1364. (defalias 'make 'compile)
  1365. (define-key ctl-x-map "c" 'compile)
  1366. ;;;;;;;;;;;;;;;;;;;;;;;
  1367. ;; adoc-simple-mode
  1368. (when (safe-require-or-eval 'adoc-mode)
  1369. (defvar adoc-simple-font-lock-keywords
  1370. nil)
  1371. (define-derived-mode adoc-simple-mode adoc-mode
  1372. "Adoc-Simple"
  1373. "Major mode for editing AsciiDoc text files.
  1374. This mode is a simplified version of `adoc-mode'."
  1375. '(set (make-local-variable 'font-lock-defaults)
  1376. '(adoc-simple-font-lock-keywords
  1377. nil nil nil nil
  1378. (font-lock-multiline . t)
  1379. (font-lock-mark-block-function . adoc-font-lock-mark-block-function))))
  1380. (add-to-list 'auto-mode-alist
  1381. '("\\.adoc\\'" . adoc-simple-mode)))
  1382. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1383. ;; awk-preview
  1384. (defgroup awk-preview nil
  1385. "Awk previewer."
  1386. :tag "Awk Preview"
  1387. :prefix "awk-preview-"
  1388. :group 'tools)
  1389. (defcustom awk-preview-program
  1390. (or (executable-find "gawk")
  1391. (executable-find "awk")
  1392. "awk")
  1393. "Awk program to execute."
  1394. :type 'string
  1395. :group 'awk-preview)
  1396. (defcustom awk-preview-switches
  1397. '("--sandbox" "--" "{print}")
  1398. "String of awk options appended when running awk preview."
  1399. :type '(repeat string)
  1400. :group 'awk-preview)
  1401. (defun awk-preview--invoke (start end output)
  1402. "Execute awk process and get result."
  1403. (let ((proc (apply 'start-process
  1404. "awk-preview"
  1405. output
  1406. awk-preview-program
  1407. awk-preview-switches)))
  1408. (message "%S" proc)
  1409. (process-send-region proc start end)
  1410. (process-send-eof proc)
  1411. (accept-process-output proc)
  1412. )
  1413. output)
  1414. (defun awk-preview (start end)
  1415. "Run awk and preview result."
  1416. (interactive "r")
  1417. (let ((output (with-current-buffer (get-buffer-create "*awk-preview output*")
  1418. (erase-buffer)
  1419. (current-buffer))))
  1420. (awk-preview--invoke start end output)
  1421. (message "awk-preview: %s" (with-current-buffer output
  1422. (buffer-substring-no-properties (point-min) (point-max))))
  1423. ))
  1424. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1425. ;; editorconfig-auto-apply
  1426. (define-minor-mode editorconfig-auto-apply-mode
  1427. "When saving .editorconfig file update buffer configs."
  1428. :global t
  1429. :lighter ""
  1430. (if editorconfig-auto-apply-mode
  1431. (add-hook 'after-save-hook
  1432. 'editorconfig-auto-apply-mode--when-save)
  1433. (remove-hook 'after-save-hook
  1434. 'editorconfig-auto-apply-mode--when-save)))
  1435. (defun editorconfig-auto-apply-mode--when-save ()
  1436. "When saving .editorconfig file walk all buffers and update configs."
  1437. (when (eq major-mode
  1438. 'editorconfig-conf-mode)
  1439. (let ((dir (file-name-directory buffer-file-name)))
  1440. (cl-dolist (buf (buffer-list))
  1441. (when (and (buffer-file-name buf)
  1442. (file-in-directory-p (buffer-file-name buf)
  1443. dir))
  1444. (with-current-buffer buf
  1445. (editorconfig-mode-apply)))))))
  1446. (editorconfig-auto-apply-mode 1)
  1447. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1448. (defun my-file-head (filename &optional n)
  1449. "Return list of first N lines of file FILENAME."
  1450. ;; Work with japanese text?
  1451. (let ((num (or n 10))
  1452. (size 100)
  1453. (beg 0)
  1454. (end 0)
  1455. (result '()))
  1456. (with-temp-buffer
  1457. (erase-buffer)
  1458. (while (<= (count-lines (point-min)
  1459. (point-max))
  1460. num)
  1461. (setq end (+ beg size))
  1462. (insert-file-contents-literally filename
  1463. nil
  1464. beg
  1465. end)
  1466. (goto-char (point-max))
  1467. (setq beg (+ beg size)))
  1468. (goto-char (point-min))
  1469. (while (< (length result) num)
  1470. (let ((start (point)))
  1471. (forward-line 1)
  1472. (setq result
  1473. `(,@result ,(buffer-substring-no-properties start
  1474. (point))))))
  1475. result
  1476. ;; (buffer-substring-no-properties (point-min)
  1477. ;; (progn
  1478. ;; (forward-line num)
  1479. ;; (point)))
  1480. )))
  1481. ;; (apply 'concat (my-file-head "./shrc" 10)
  1482. (set-variable 'dumb-jump-prefer-searcher 'rg)
  1483. ;; Local Variables:
  1484. ;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
  1485. ;; flycheck-checker: emacs-lisp
  1486. ;; End:
  1487. ;;; emancs.el ends here