Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

emacs.el 61 KiB

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