You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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