選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

emacs.el 76 KiB

5年前
11年前
6年前
6年前
6年前
6年前
5年前
5年前
11年前
11年前
5年前
5年前
12年前
Remove my-company-lighter-current-length Debugger entered--Lisp error: (error "`global' non-zero exit: global: GTAGS not found.") signal(error ("`global' non-zero exit: global: GTAGS not found.")) error("`%s' non-zero exit: %s" "global" "global: GTAGS not found.") ggtags-process-string("global" "--ignore-case" "-c" "sys") apply(ggtags-process-string "global" ("--ignore-case" "-c" "sys")) #f(compiled-function (prefix) #<bytecode 0x40751ea1>)("sys") #f(compiled-function (string pred action) #<bytecode 0x40751ec9>)("sys" nil t) all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil) completion-pcm--all-completions("" ("sys" point) #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil) completion-basic-all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3) #f(compiled-function (style) #<bytecode 0x4088a97f>)(basic) completion--some(#f(compiled-function (style) #<bytecode 0x4088a97f>) (basic partial-completion emacs22)) completion--nth-completion(2 "sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3 nil) completion-all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3) company-capf(candidates "sys") apply(company-capf (candidates "sys")) company-call-backend-raw(candidates "sys") apply(company-call-backend-raw (candidates "sys")) company--force-sync(company-call-backend-raw (candidates "sys") company-capf) company-call-backend(candidates "sys") company--fetch-candidates("sys") company-calculate-candidates("sys" nil) company--begin-new() company--perform() company-auto-begin() company-manual-begin() my-company-lighter-current-length() eval((my-company-lighter-current-length)) redisplay_internal\ \(C\ function\)()
5年前
Remove my-company-lighter-current-length Debugger entered--Lisp error: (error "`global' non-zero exit: global: GTAGS not found.") signal(error ("`global' non-zero exit: global: GTAGS not found.")) error("`%s' non-zero exit: %s" "global" "global: GTAGS not found.") ggtags-process-string("global" "--ignore-case" "-c" "sys") apply(ggtags-process-string "global" ("--ignore-case" "-c" "sys")) #f(compiled-function (prefix) #<bytecode 0x40751ea1>)("sys") #f(compiled-function (string pred action) #<bytecode 0x40751ec9>)("sys" nil t) all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil) completion-pcm--all-completions("" ("sys" point) #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil) completion-basic-all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3) #f(compiled-function (style) #<bytecode 0x4088a97f>)(basic) completion--some(#f(compiled-function (style) #<bytecode 0x4088a97f>) (basic partial-completion emacs22)) completion--nth-completion(2 "sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3 nil) completion-all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3) company-capf(candidates "sys") apply(company-capf (candidates "sys")) company-call-backend-raw(candidates "sys") apply(company-call-backend-raw (candidates "sys")) company--force-sync(company-call-backend-raw (candidates "sys") company-capf) company-call-backend(candidates "sys") company--fetch-candidates("sys") company-calculate-candidates("sys" nil) company--begin-new() company--perform() company-auto-begin() company-manual-begin() my-company-lighter-current-length() eval((my-company-lighter-current-length)) redisplay_internal\ \(C\ function\)()
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
11年前
11年前
5年前
6年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
5年前
6年前
12年前
6年前
6年前
6年前
6年前
6年前
6年前
5年前
6年前
6年前
5年前
5年前
5年前
Remove my-company-lighter-current-length Debugger entered--Lisp error: (error "`global' non-zero exit: global: GTAGS not found.") signal(error ("`global' non-zero exit: global: GTAGS not found.")) error("`%s' non-zero exit: %s" "global" "global: GTAGS not found.") ggtags-process-string("global" "--ignore-case" "-c" "sys") apply(ggtags-process-string "global" ("--ignore-case" "-c" "sys")) #f(compiled-function (prefix) #<bytecode 0x40751ea1>)("sys") #f(compiled-function (string pred action) #<bytecode 0x40751ec9>)("sys" nil t) all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil) completion-pcm--all-completions("" ("sys" point) #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil) completion-basic-all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3) #f(compiled-function (style) #<bytecode 0x4088a97f>)(basic) completion--some(#f(compiled-function (style) #<bytecode 0x4088a97f>) (basic partial-completion emacs22)) completion--nth-completion(2 "sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3 nil) completion-all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3) company-capf(candidates "sys") apply(company-capf (candidates "sys")) company-call-backend-raw(candidates "sys") apply(company-call-backend-raw (candidates "sys")) company--force-sync(company-call-backend-raw (candidates "sys") company-capf) company-call-backend(candidates "sys") company--fetch-candidates("sys") company-calculate-candidates("sys" nil) company--begin-new() company--perform() company-auto-begin() company-manual-begin() my-company-lighter-current-length() eval((my-company-lighter-current-length)) redisplay_internal\ \(C\ function\)()
5年前
5年前
Remove my-company-lighter-current-length Debugger entered--Lisp error: (error "`global' non-zero exit: global: GTAGS not found.") signal(error ("`global' non-zero exit: global: GTAGS not found.")) error("`%s' non-zero exit: %s" "global" "global: GTAGS not found.") ggtags-process-string("global" "--ignore-case" "-c" "sys") apply(ggtags-process-string "global" ("--ignore-case" "-c" "sys")) #f(compiled-function (prefix) #<bytecode 0x40751ea1>)("sys") #f(compiled-function (string pred action) #<bytecode 0x40751ec9>)("sys" nil t) all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil) completion-pcm--all-completions("" ("sys" point) #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil) completion-basic-all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3) #f(compiled-function (style) #<bytecode 0x4088a97f>)(basic) completion--some(#f(compiled-function (style) #<bytecode 0x4088a97f>) (basic partial-completion emacs22)) completion--nth-completion(2 "sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3 nil) completion-all-completions("sys" #f(compiled-function (string pred action) #<bytecode 0x40751ec9>) nil 3) company-capf(candidates "sys") apply(company-capf (candidates "sys")) company-call-backend-raw(candidates "sys") apply(company-call-backend-raw (candidates "sys")) company--force-sync(company-call-backend-raw (candidates "sys") company-capf) company-call-backend(candidates "sys") company--fetch-candidates("sys") company-calculate-candidates("sys" nil) company--begin-new() company--perform() company-auto-begin() company-manual-begin() my-company-lighter-current-length() eval((my-company-lighter-current-length)) redisplay_internal\ \(C\ function\)()
5年前
6年前
5年前
5年前
5年前
5年前
5年前
6年前
12年前
6年前
6年前
6年前
6年前
6年前
6年前
12年前
12年前
12年前
6年前
5年前
12年前
12年前
5年前
6年前
6年前
5年前
5年前
5年前
5年前
11年前
6年前
11年前
5年前
5年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331
  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. ;; TODO: Use custom-set-variables in place of set-variable
  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. (require 'cl-lib)
  12. (require 'simple)
  13. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  14. ;; Some macros for internals
  15. ;; TODO: Rename to eval-after-init
  16. (defmacro call-after-init (&rest body)
  17. "If `after-init-hook' has been run, run BODY immediately.
  18. Otherwize hook it."
  19. (declare (indent 0) (debug t))
  20. `(if after-init-time
  21. ;; Currently after-init-hook is run just after setting after-init-hook
  22. (progn
  23. ,@body)
  24. (add-hook 'after-init-hook
  25. (lambda ()
  26. ,@body))))
  27. ;; TODO: Remove: Just checking fboundp should be enough for most cases
  28. (defmacro safe-require-or-eval (feature)
  29. "Require FEATURE if available.
  30. At compile time the feature will be loaded immediately."
  31. `(eval-and-compile
  32. (message "safe-require-or-eval: Trying to require %s" ,feature)
  33. (require ,feature nil t)))
  34. ;; TODO: Remove: Defining autoload is no more needed for most cases
  35. (defmacro autoload-eval-lazily (feature &optional functions &rest body)
  36. "Define autoloading FEATURE that defines FUNCTIONS.
  37. FEATURE is a symbol. FUNCTIONS is a list of symbols. If FUNCTIONS is nil,
  38. the function same as FEATURE is defined as autoloaded function. BODY is passed
  39. to `eval-after-load'.
  40. After this macro is expanded, this returns the path to library if FEATURE
  41. found, otherwise returns nil."
  42. (declare (indent 2) (debug t))
  43. (let* ((libname (symbol-name (eval feature)))
  44. (libpath (locate-library libname)))
  45. `(progn
  46. (when (locate-library ,libname)
  47. ,@(mapcar (lambda (f)
  48. `(unless (fboundp ',f)
  49. (progn
  50. (message "Autoloaded function `%S' defined (%s)"
  51. (quote ,f)
  52. ,libpath)
  53. (autoload (quote ,f)
  54. ,libname
  55. ,(concat "Autoloaded function defined in \""
  56. libpath
  57. "\".")
  58. t))))
  59. (or (eval functions)
  60. `(,(eval feature)))))
  61. (eval-after-load ,feature
  62. (quote (progn
  63. ,@body)))
  64. (locate-library ,libname))))
  65. (when (autoload-eval-lazily 'tetris nil
  66. (message "Tetris loaded!"))
  67. (message "Tetris found!"))
  68. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  69. ;; package
  70. (set (defvar 10sr-package-list)
  71. '(
  72. vimrc-mode
  73. markdown-mode
  74. yaml-mode
  75. gnuplot-mode
  76. php-mode
  77. erlang
  78. js2-mode
  79. js-doc
  80. git-commit
  81. gitignore-mode
  82. adoc-mode
  83. go-mode
  84. ;; It seems malabar has been merged into jdee and this package
  85. ;; already removed
  86. ;; malabar-mode
  87. gosh-mode
  88. scala-mode
  89. ;;ensime
  90. web-mode
  91. color-moccur
  92. ggtags
  93. flycheck
  94. auto-highlight-symbol
  95. hl-todo
  96. ;; Currently not available
  97. ;; pp-c-l
  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. ;; I think this works in place of my autosave lib
  110. super-save
  111. pipenv
  112. imenu-list
  113. page-break-lines
  114. aggressive-indent
  115. dired-filter
  116. wgrep
  117. magit
  118. git-gutter
  119. end-mark
  120. sl
  121. ;; TODO: Configure pony-tpl-mode
  122. pony-mode
  123. gited
  124. highlight-indentation
  125. diminish
  126. fzf
  127. fic-mode
  128. term-cursor
  129. pydoc
  130. editorconfig
  131. editorconfig-custom-majormode
  132. git-command
  133. prompt-text
  134. ;; 10sr repository
  135. ;; 10sr-extras
  136. terminal-title
  137. dired-list-all-mode
  138. pack
  139. set-modeline-color
  140. read-only-only-mode
  141. smart-revert
  142. autosave
  143. ;;window-organizer
  144. ilookup
  145. pasteboard
  146. awk-preview
  147. recently
  148. ))
  149. (when (safe-require-or-eval 'package)
  150. (setq package-archives
  151. `(,@package-archives
  152. ("melpa" . "https://melpa.org/packages/")
  153. ;; Somehow fails to download via https
  154. ("10sr-el" . "http://10sr.github.io/emacs-lisp/elpa/")))
  155. (package-initialize)
  156. (defun my-auto-install-package ()
  157. "Install packages semi-automatically."
  158. (interactive)
  159. (package-refresh-contents)
  160. (mapc (lambda (pkg)
  161. (or (package-installed-p pkg)
  162. (package-install pkg)))
  163. 10sr-package-list))
  164. )
  165. ;; (lazy-load-eval 'sudoku)
  166. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  167. ;; my-idle-hook
  168. (defvar my-idle-hook nil
  169. "Hook run when idle for several secs.")
  170. (defvar my-idle-hook-sec 5
  171. "Second to run `my-idle-hook'.")
  172. (run-with-idle-timer my-idle-hook-sec
  173. t
  174. (lambda ()
  175. (run-hooks 'my-idle-hook)))
  176. ;; (add-hook 'my-idle-hook
  177. ;; (lambda ()
  178. ;; (message "idle hook message")))
  179. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  180. ;; start and quit
  181. (setq inhibit-startup-message t)
  182. (setq initial-buffer-choice 'messages-buffer)
  183. (setq confirm-kill-emacs 'y-or-n-p)
  184. (setq gc-cons-threshold (* 1024 1024 16))
  185. (setq garbage-collection-messages nil)
  186. (when window-system
  187. (add-to-list 'default-frame-alist '(cursor-type . box))
  188. (add-to-list 'default-frame-alist '(background-color . "white"))
  189. (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
  190. ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))
  191. ;; does not work?
  192. )
  193. ;; (add-to-list 'default-frame-alist '(cursor-type . box))
  194. (menu-bar-mode 1)
  195. (define-key ctl-x-map "m" 'menu-bar-open)
  196. (and (fboundp 'tool-bar-mode)
  197. (tool-bar-mode 0))
  198. (and (fboundp 'set-scroll-bar-mode)
  199. (set-scroll-bar-mode nil))
  200. (call-after-init
  201. (message "%s %s" invocation-name emacs-version)
  202. (message "Invocation directory: %s" default-directory)
  203. (message "%s was taken to initialize emacs." (emacs-init-time))
  204. ;; (view-echo-area-messages)
  205. ;; (view-emacs-news)
  206. )
  207. (with-current-buffer "*Messages*"
  208. (emacs-lock-mode 'kill))
  209. (cd ".") ; when using windows use / instead of \ in `default-directory'
  210. ;; locale
  211. (set-language-environment "Japanese")
  212. (set-default-coding-systems 'utf-8-unix)
  213. (prefer-coding-system 'utf-8-unix)
  214. (setq system-time-locale "C")
  215. ;; my prefix map
  216. (defvar my-prefix-map nil
  217. "My prefix map.")
  218. (define-prefix-command 'my-prefix-map)
  219. (global-set-key (kbd "C-^") 'my-prefix-map)
  220. ;; (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
  221. ;; (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
  222. ;; (comint-show-maximum-output)
  223. ;; kill scratch
  224. (call-after-init
  225. (let ((buf (get-buffer "*scratch*")))
  226. (when buf
  227. (kill-buffer buf))))
  228. ;; modifier keys
  229. ;; (setq mac-option-modifier 'control)
  230. ;; display
  231. (setq visible-bell t)
  232. (setq ring-bell-function 'ignore)
  233. (mouse-avoidance-mode 'banish)
  234. (setq echo-keystrokes 0.1)
  235. (defun reload-init-file ()
  236. "Reload Emacs init file."
  237. (interactive)
  238. (when (and user-init-file
  239. (file-readable-p user-init-file))
  240. (load-file user-init-file)))
  241. (safe-require-or-eval 'session)
  242. ;; server
  243. (set-variable 'server-name (concat "server"
  244. (number-to-string (emacs-pid))))
  245. ;; In Cygwin Environment `server-runnning-p' stops when server-use-tcp is nil
  246. ;; In Darwin environment, init fails with message like 'Service name too long'
  247. ;; when server-use-tcp is nil
  248. (when (or (eq system-type
  249. 'cygwin)
  250. (eq system-type
  251. 'darwin))
  252. (set-variable 'server-use-tcp t))
  253. ;; MSYS2 fix
  254. (when (eq system-type
  255. 'windows-nt)
  256. (setq shell-file-name
  257. (executable-find "bash"))
  258. '(setq function-key-map
  259. `(,@function-key-map ([pause] . [?\C-c])
  260. ))
  261. (define-key key-translation-map
  262. (kbd "<pause>")
  263. (kbd "C-c"))
  264. '(keyboard-translate [pause]
  265. (kbd "C-c")p)
  266. ;; TODO: move to other place later
  267. (when (not window-system)
  268. (setq interprogram-paste-function nil)
  269. (setq interprogram-cut-function nil)))
  270. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  271. ;; global keys
  272. (global-set-key (kbd "<up>") 'scroll-down-line)
  273. (global-set-key (kbd "<down>") 'scroll-up-line)
  274. (global-set-key (kbd "<left>") 'scroll-down)
  275. (global-set-key (kbd "<right>") 'scroll-up)
  276. ;; (define-key my-prefix-map (kbd "C-h") help-map)
  277. (global-set-key (kbd "C-\\") help-map)
  278. (define-key ctl-x-map (kbd "DEL") help-map)
  279. (define-key ctl-x-map (kbd "C-h") help-map)
  280. (define-key help-map "a" 'apropos)
  281. ;; disable annoying keys
  282. (global-set-key [prior] 'ignore)
  283. (global-set-key (kbd "<next>") 'ignore)
  284. (global-set-key [menu] 'ignore)
  285. (global-set-key [down-mouse-1] 'ignore)
  286. (global-set-key [down-mouse-2] 'ignore)
  287. (global-set-key [down-mouse-3] 'ignore)
  288. (global-set-key [mouse-1] 'ignore)
  289. (global-set-key [mouse-2] 'ignore)
  290. (global-set-key [mouse-3] 'ignore)
  291. (global-set-key (kbd "<eisu-toggle>") 'ignore)
  292. (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
  293. ;; Interactively evaluate Emacs Lisp expressions
  294. (define-key ctl-x-map "i" 'ielm)
  295. (when (safe-require-or-eval 'which-key)
  296. (which-key-mode))
  297. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  298. ;; editor
  299. ;; Basically it should not set globally (instead use something like file local
  300. ;; variables or editorconfig), but for most cases I just need this...
  301. (defun my-set-require-final-newline ()
  302. "Set `require-final-newline'."
  303. (set (make-local-variable 'require-final-newline)
  304. mode-require-final-newline))
  305. (add-hook 'prog-mode-hook
  306. 'my-set-require-final-newline)
  307. (add-hook 'text-mode-hook
  308. 'my-set-require-final-newline)
  309. (add-hook 'conf-mode-hook
  310. 'my-set-require-final-newline)
  311. ;; Used from term-cursor
  312. ;; hbar is too hard to find...
  313. (defun my-cursor-type-change (&rest args)
  314. "ARGS are discarded."
  315. ;; TODO: Support wdired and wgrep
  316. (if buffer-read-only
  317. (setq cursor-type 'hbar)
  318. (setq cursor-type 'box)))
  319. ;; (add-hook 'switch-buffer-functions
  320. ;; 'my-cursor-type-change)
  321. ;; (add-hook 'read-only-mode-hook
  322. ;; 'my-cursor-type-change)
  323. ;; (when (fboundp 'global-term-cursor-mode)
  324. ;; (global-term-cursor-mode 1))
  325. ;; ;; (term-cursor--eval)
  326. (setq kill-whole-line t)
  327. (setq scroll-conservatively 35
  328. scroll-margin 2)
  329. (setq-default major-mode 'text-mode)
  330. (setq next-line-add-newlines nil)
  331. (setq kill-read-only-ok t)
  332. (setq truncate-partial-width-windows nil) ; when splitted horizontally
  333. ;; (setq-default line-spacing 0.2)
  334. (setq-default indicate-empty-lines t) ; when using x indicate empty line
  335. ;; (setq-default tab-width 4)
  336. (setq-default indent-tabs-mode nil)
  337. (setq-default indent-line-function 'indent-to-left-margin)
  338. ;; (setq-default indent-line-function nil)
  339. (setq-default truncate-lines nil)
  340. ;; (pc-selection-mode 1) ; make some already defined keybind back to default
  341. (delete-selection-mode 1)
  342. (cua-mode 0)
  343. (setq line-move-visual nil)
  344. (setq create-lockfiles nil)
  345. (add-hook 'before-save-hook
  346. 'time-stamp)
  347. ;; Add Time-stamp: <> to insert timestamp there
  348. (set-variable 'time-stamp-format
  349. "%:y-%02m-%02d %02H:%02M:%02S %Z 10sr")
  350. ;; key bindings
  351. ;; moving around
  352. ;;(keyboard-translate ?\M-j ?\C-j)
  353. ;; (global-set-key (kbd "M-p") 'backward-paragraph)
  354. (define-key esc-map "p" 'backward-paragraph)
  355. ;; (global-set-key (kbd "M-n") 'forward-paragraph)
  356. (define-key esc-map "n" 'forward-paragraph)
  357. (global-set-key (kbd "C-<up>") 'scroll-down-line)
  358. (global-set-key (kbd "C-<down>") 'scroll-up-line)
  359. (global-set-key (kbd "C-<left>") 'scroll-down)
  360. (global-set-key (kbd "C-<right>") 'scroll-up)
  361. (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
  362. (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
  363. (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
  364. ;; C-h and DEL
  365. (global-set-key (kbd "C-h") (kbd "DEL"))
  366. ;; (normal-erase-is-backspace-mode 1)
  367. ;;(global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
  368. (global-set-key (kbd "C-m") 'newline-and-indent)
  369. ;; (global-set-key (kbd "C-o") (kbd "C-e C-m"))
  370. ;; (global-set-key "\C-z" 'undo) ; undo is M-u
  371. (define-key esc-map "u" 'undo)
  372. (define-key esc-map "i" (kbd "ESC TAB"))
  373. ;; (global-set-key (kbd "C-r") 'query-replace-regexp)
  374. (global-set-key (kbd "C-s") 'isearch-forward-regexp)
  375. (global-set-key (kbd "C-r") 'isearch-backward-regexp)
  376. (require 'page-ext nil t)
  377. (when (safe-require-or-eval 'page-break-lines)
  378. (global-page-break-lines-mode 1))
  379. (when (safe-require-or-eval 'git-gutter)
  380. (declare-function global-git-gutter-mode "git-gutter")
  381. (custom-set-variables
  382. '(git-gutter:lighter " Gttr"))
  383. (custom-set-variables
  384. '(git-gutter:update-interval 2))
  385. (custom-set-variables
  386. '(git-gutter:unchanged-sign " "))
  387. (when (>= (display-color-cells)
  388. 256)
  389. (let ((c "color-233"))
  390. (set-face-background 'git-gutter:modified c)
  391. (set-face-background 'git-gutter:added c)
  392. (set-face-background 'git-gutter:deleted c)
  393. (set-face-background 'git-gutter:unchanged c)))
  394. (global-git-gutter-mode 1)
  395. )
  396. ;; (when (safe-require-or-eval 'fancy-narrow)
  397. ;; (fancy-narrow-mode 1))
  398. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  399. ;; title and mode-line
  400. (when (safe-require-or-eval 'terminal-title)
  401. ;; if TERM is not screen use default value
  402. (if (getenv "TMUX")
  403. ;; if use tmux locally just basename of current dir
  404. (set-variable 'terminal-title-format
  405. '((file-name-nondirectory (directory-file-name
  406. default-directory))))
  407. (if (and (let ((tty-type (frame-parameter nil
  408. 'tty-type)))
  409. (and tty-type
  410. (equal (car (split-string tty-type
  411. "-"))
  412. "screen")))
  413. (not (getenv "SSH_CONNECTION")))
  414. (set-variable 'terminal-title-format
  415. '((file-name-nondirectory (directory-file-name
  416. default-directory))))
  417. ;; seems that TMUX is used locally and ssh to remote host
  418. (set-variable 'terminal-title-format
  419. `("em:"
  420. ,user-login-name
  421. "@"
  422. ,(car (split-string (system-name)
  423. "\\."))
  424. ":"
  425. default-directory))
  426. )
  427. )
  428. (terminal-title-mode))
  429. (setq eol-mnemonic-dos "\\r\\n")
  430. (setq eol-mnemonic-mac "\\r")
  431. (setq eol-mnemonic-unix "")
  432. (which-function-mode 1)
  433. (line-number-mode 0)
  434. (column-number-mode 0)
  435. (size-indication-mode 0)
  436. (setq mode-line-position
  437. '(:eval (format ":%%l:%%c /%d%s"
  438. (count-lines (point-max)
  439. (point-min))
  440. (if (buffer-narrowed-p)
  441. "[N]"
  442. "")
  443. )))
  444. (when (safe-require-or-eval 'diminish)
  445. ;; FIXME: Eval after enabling mode
  446. (call-after-init
  447. (diminish 'recently-mode)
  448. (diminish 'editorconfig-mode)
  449. (diminish 'auto-highlight-symbol-mode)
  450. (diminish 'global-whitespace-mode)
  451. (diminish 'which-key-mode)
  452. (diminish 'page-break-lines-mode)
  453. (diminish 'highlight-indentation-mode)))
  454. (setq mode-line-front-space "")
  455. ;; (setq mode-line-end-spaces "")
  456. ;; Set current frame name to empty string
  457. (setq-default mode-line-format
  458. (let* ((l mode-line-format)
  459. (l (cl-substitute " " " "
  460. l
  461. :test 'equal))
  462. (l (cl-substitute " " " "
  463. l
  464. :test 'equal))
  465. )
  466. l))
  467. (set-frame-parameter nil 'name "")
  468. ;; See color-name-rgb-alist for available color names
  469. ;; http://www.raebear.net/computers/emacs-colors/
  470. ;; https://www.emacswiki.org/emacs/ListColors
  471. ;; (list-colors-display is not a complete list)
  472. (defconst my-mode-line-background-default
  473. (face-background 'mode-line)
  474. "Default color of mode-line at init.")
  475. (defun my-mode-line-color-update (&rest args)
  476. "ARGS are discarded"
  477. (let ((ro "skyblue")
  478. (rw my-mode-line-background-default))
  479. (if (or (not buffer-read-only)
  480. (and (eq major-mode 'wdired-mode)))
  481. (set-face-background 'mode-line
  482. rw)
  483. (set-face-background 'mode-line
  484. ro))))
  485. (add-hook 'switch-buffer-functions
  486. 'my-mode-line-color-update)
  487. (add-hook 'read-only-mode-hook
  488. 'my-mode-line-color-update)
  489. (add-hook 'wdired-mode-hook
  490. 'my-mode-line-color-update)
  491. (advice-add 'wdired-change-to-dired-mode
  492. :after
  493. 'my-mode-line-color-update)
  494. (advice-add 'wgrep-change-to-wgrep-mode
  495. :after
  496. 'my-mode-line-color-update)
  497. (advice-add 'wgrep-to-original-mode
  498. :after
  499. 'my-mode-line-color-update)
  500. (set-face-background 'header-line
  501. my-mode-line-background-default)
  502. ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
  503. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  504. ;; minibuffer
  505. (setq insert-default-directory t)
  506. (setq completion-ignore-case t
  507. read-file-name-completion-ignore-case t
  508. read-buffer-completion-ignore-case t)
  509. (setq resize-mini-windows t)
  510. (temp-buffer-resize-mode 1)
  511. (savehist-mode 1)
  512. (defvar display-time-format "%Y/%m/%d %a %H:%M")
  513. (set-variable 'help-at-pt-display-when-idle t)
  514. (fset 'yes-or-no-p 'y-or-n-p)
  515. ;; complete symbol when `eval'
  516. (define-key read-expression-map (kbd "TAB") 'completion-at-point)
  517. (define-key minibuffer-local-map (kbd "C-u")
  518. (lambda () (interactive) (delete-region (point-at-bol) (point))))
  519. ;; I dont know these bindings are good
  520. (define-key minibuffer-local-map (kbd "C-p") (kbd "ESC p"))
  521. (define-key minibuffer-local-map (kbd "C-n") (kbd "ESC n"))
  522. (when (safe-require-or-eval 'minibuffer-line)
  523. (set-face-underline 'minibuffer-line nil)
  524. (set-variable 'minibuffer-line-refresh-interval
  525. 25)
  526. ;; Set idle timer
  527. (defvar my-minibuffer-line--idle-timer nil)
  528. (defvar minibuffer-line-mode)
  529. (add-hook 'minibuffer-line-mode-hook
  530. (lambda ()
  531. (when my-minibuffer-line--idle-timer
  532. (cancel-timer my-minibuffer-line--idle-timer)
  533. (setq my-minibuffer-line--idle-timer nil))
  534. (when minibuffer-line-mode
  535. (setq my-minibuffer-line--idle-timer
  536. (run-with-idle-timer 0.5
  537. t
  538. 'minibuffer-line--update)))))
  539. (set-variable 'minibuffer-line-format
  540. `(,(concat user-login-name
  541. "@"
  542. (car (split-string (system-name)
  543. "\\."))
  544. ":")
  545. (:eval (abbreviate-file-name (or buffer-file-name
  546. default-directory)))
  547. (:eval (and (fboundp 'git-ps1-mode-get-current)
  548. (git-ps1-mode-get-current " [GIT:%s]")))
  549. " "
  550. (:eval (format-time-string display-time-format))))
  551. (minibuffer-line-mode 1)
  552. )
  553. (when (safe-require-or-eval 'prompt-text)
  554. (set-variable 'prompt-text-format
  555. `(,(concat ""
  556. user-login-name
  557. "@"
  558. (car (split-string (system-name)
  559. "\\."))
  560. ":")
  561. (:eval (abbreviate-file-name (or buffer-file-name
  562. default-directory)))
  563. (:eval (and (fboundp 'git-ps1-mode-get-current)
  564. (git-ps1-mode-get-current " [GIT:%s]")))
  565. " "
  566. (:eval (format-time-string display-time-format))
  567. "\n"
  568. (:eval (symbol-name this-command))
  569. ": "))
  570. (prompt-text-mode 1))
  571. (autoload-eval-lazily 'helm nil
  572. (defvar helm-map)
  573. (define-key helm-map (kbd "C-h") (kbd "DEL")))
  574. (setq-default header-line-format
  575. '(:eval (let ((f (or (buffer-file-name)
  576. default-directory)))
  577. (when f
  578. (abbreviate-file-name f)))))
  579. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  580. ;; letters, font-lock mode and fonts
  581. (setq text-quoting-style 'grave)
  582. ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
  583. ;; (set-window-margins (selected-window) 1 1)
  584. (unless window-system
  585. (setq frame-background-mode 'dark))
  586. (and (or (eq system-type 'Darwin)
  587. (eq system-type 'darwin))
  588. (fboundp 'mac-set-input-method-parameter)
  589. (mac-set-input-method-parameter 'japanese 'cursor-color "red")
  590. (mac-set-input-method-parameter 'roman 'cursor-color "black"))
  591. (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
  592. (boundp 'input-method-inactivate-hook))
  593. (add-hook 'input-method-activate-hook
  594. (lambda () (set-cursor-color "red")))
  595. (add-hook 'input-method-inactivate-hook
  596. (lambda () (set-cursor-color "black"))))
  597. (when (safe-require-or-eval 'paren)
  598. (show-paren-mode 1)
  599. (setq show-paren-delay 0.5
  600. show-paren-style 'parenthesis) ; mixed is hard to read
  601. ;; (set-face-background 'show-paren-match
  602. ;; "black")
  603. ;; ;; (face-foreground 'default))
  604. ;; (set-face-foreground 'show-paren-match
  605. ;; "white")
  606. ;; (set-face-inverse-video-p 'show-paren-match
  607. ;; t)
  608. )
  609. (transient-mark-mode 1)
  610. (global-font-lock-mode 1)
  611. (setq font-lock-global-modes
  612. '(not
  613. help-mode
  614. eshell-mode
  615. ;;term-mode
  616. Man-mode
  617. magit-diff-mode
  618. magit-revision-mode))
  619. ;; (standard-display-ascii ?\n "$\n")
  620. ;; (defvar my-eol-face
  621. ;; '(("\n" . (0 font-lock-comment-face t nil)))
  622. ;; )
  623. ;; (defvar my-tab-face
  624. ;; '(("\t" . '(0 highlight t nil))))
  625. (defvar my-jspace-face
  626. '(("\u3000" . '(0 highlight t nil))))
  627. (add-hook 'font-lock-mode-hook
  628. (lambda ()
  629. ;; (font-lock-add-keywords nil my-eol-face)
  630. (font-lock-add-keywords nil my-jspace-face)
  631. ))
  632. (when (safe-require-or-eval 'whitespace)
  633. (add-to-list 'whitespace-display-mappings
  634. ;; We need t since last one takes precedence
  635. `(tab-mark ?\t ,(vconcat "|>\t")) t)
  636. ;; (add-to-list 'whitespace-display-mappings
  637. ;; `(newline-mark ?\n ,(vconcat "$\n")))
  638. (setq whitespace-style '(face
  639. trailing ; trailing blanks
  640. ;; tabs
  641. ;; spaces
  642. ;; lines
  643. lines-tail ; lines over 80
  644. newline ; newlines
  645. ;; empty ; empty lines at beg or end of buffer
  646. ;; big-indent
  647. ;; space-mark
  648. tab-mark
  649. newline-mark ; use display table for newline
  650. ))
  651. ;; (setq whitespace-newline 'font-lock-comment-face)
  652. ;; (setq whitespace-style (delq 'newline-mark whitespace-style))
  653. (defun my-whitesspace-mode-reload ()
  654. "Reload whitespace-mode config."
  655. (interactive)
  656. (when whitespace-mode
  657. (whitespace-mode 0)
  658. (whitespace-mode 1)))
  659. (set-variable 'whitespace-line-column nil)
  660. (global-whitespace-mode t)
  661. (add-hook 'dired-mode-hook
  662. (lambda ()
  663. (set (make-local-variable 'whitespace-style) nil)))
  664. (if (>= (display-color-cells)
  665. 256)
  666. (set-face-foreground 'whitespace-newline "color-109")
  667. ;; (progn
  668. ;; (set-face-bold-p 'whitespace-newline
  669. ;; t))
  670. ))
  671. (and nil
  672. '(safe-require-or-eval 'fill-column-indicator)
  673. (setq fill-column-indicator))
  674. (defun my-gen-hl-line-color-dark ()
  675. "Generate color for current line in black background."
  676. (let* ((candidates (mapcar 'number-to-string (number-sequence 1 6)))
  677. (limit (length candidates))
  678. (r 0) (g 0) (b 0))
  679. (while (and (<= (abs (- r g)) 1)
  680. (<= (abs (- g b)) 1)
  681. (<= (abs (- b r)) 1))
  682. (setq r (random limit))
  683. (setq g (random limit))
  684. (setq b (random limit)))
  685. (format "#%s%s%s"
  686. (nth r candidates)
  687. (nth g candidates)
  688. (nth b candidates)
  689. )))
  690. ;; (my-gen-hl-line-color-dark)
  691. ;; highlight current line
  692. ;; http://wiki.riywo.com/index.php?Meadow
  693. (face-spec-set 'hl-line
  694. `((((min-colors 256)
  695. (background dark))
  696. ;; Rotate midnightblue
  697. (:background ,(my-gen-hl-line-color-dark)))
  698. (((min-colors 256)
  699. (background light))
  700. ;; TODO: What is should be?
  701. (:background "color-234"))
  702. (t
  703. (:underline "black"))))
  704. (set-variable 'hl-line-global-modes
  705. '(not
  706. term-mode))
  707. (global-hl-line-mode 1) ;; (hl-line-mode 1)
  708. (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
  709. (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
  710. ;;(safe-require-or-eval 'set-modeline-color)
  711. ;; (let ((fg (face-foreground 'default))
  712. ;; (bg (face-background 'default)))
  713. ;; (set-face-background 'mode-line-inactive
  714. ;; (if (face-inverse-video-p 'mode-line) fg bg))
  715. ;; (set-face-foreground 'mode-line-inactive
  716. ;; (if (face-inverse-video-p 'mode-line) bg fg)))
  717. ;; (set-face-underline 'mode-line-inactive
  718. ;; t)
  719. ;; (set-face-underline 'vertical-border
  720. ;; nil)
  721. ;; (when (safe-require-or-eval 'end-mark)
  722. ;; (global-end-mark-mode))
  723. ;; M-x highlight-* to highlight things
  724. (global-hi-lock-mode 1)
  725. (unless (fboundp 'highlight-region-text)
  726. (defun highlight-region-text (beg end)
  727. "Highlight text between BEG and END."
  728. (interactive "r")
  729. (highlight-regexp (regexp-quote (buffer-substring-no-properties beg
  730. end)))
  731. (setq deactivate-mark t)))
  732. (when (safe-require-or-eval 'auto-highlight-symbol)
  733. (set-variable 'ahs-idle-interval 0.6)
  734. (global-auto-highlight-symbol-mode 1))
  735. (when (safe-require-or-eval 'highlight-indentation)
  736. (set-face-background 'highlight-indentation-face "color-236")
  737. (dolist (hook
  738. '(
  739. prog-mode-hook
  740. text-mode-hook
  741. ))
  742. (add-hook hook
  743. 'highlight-indentation-mode)))
  744. ;; (set-face-background 'highlight-indentation-current-column-face "#c3b3b3")
  745. (when (fboundp 'fic-mode)
  746. (add-hook 'prog-mode-hook
  747. 'fic-mode))
  748. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  749. ;; file handling
  750. (auto-insert-mode 1)
  751. ;; fzf
  752. ;; Too slow in term buffer!
  753. ;; (set-variable 'fzf/executable "sk")
  754. ;; (set-variable 'fzf/args "--color bw --print-query")
  755. ;; Modified from hardcoded default to include:
  756. ;; - directories
  757. ;; - hidden files
  758. ;; - root directory (.)
  759. ;; - parent directory (..)
  760. ;; ripgrep cannot list directories...
  761. ;; (setenv "FZF_DEFAULT_COMMAND" "rg --files --hidden --follow --glob '!.git/*' --no-ignore")
  762. (let* ((find (if (executable-find "bfs")
  763. ;; Breadth-first find https://github.com/tavianator/bfs
  764. "bfs"
  765. ;; Use gfind if available?
  766. "find"))
  767. (findcmd (concat "set -eu; set -o pipefail; "
  768. "echo .; "
  769. "echo ..; "
  770. "command " find " -L . "
  771. "-mindepth 1 "
  772. "\\( -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune "
  773. "-o -print "
  774. "2> /dev/null "
  775. "| "
  776. "cut -b3-"))
  777. (fdcmd (concat "set -eu; set -o pipefail; "
  778. "echo .; "
  779. "echo ..; "
  780. "command fd "
  781. "--follow --hidden --no-ignore "
  782. "--color always "
  783. "2>/dev/null")))
  784. (if (executable-find "fd")
  785. (setenv "FZF_DEFAULT_COMMAND" fdcmd)
  786. (setenv "FZF_DEFAULT_COMMAND" findcmd)))
  787. (set-variable 'fzf/window-height 45)
  788. (set-variable 'fzf/args "--print-query --ansi --color='bg+:-1' --inline-info --cycle")
  789. ;; (set-variable 'fzf/args "--print-query --ansi --inline-info --cycle")
  790. ;; (set-variable 'fzf/args "--print-query --ansi --color=bw --inline-info --cycle")
  791. (defun my-fzf-or-find-file ()
  792. "Call fzf if usable or call find-file."
  793. (declare (interactive-only t))
  794. (interactive)
  795. (if (and (executable-find "fzf")
  796. (fboundp 'fzf)
  797. (not (file-remote-p default-directory)))
  798. (fzf)
  799. (call-interactively 'find-file)))
  800. (define-key ctl-x-map "f" 'my-fzf-or-find-file)
  801. (defun my-fzf-all-lines ()
  802. "Fzf all lines."
  803. (interactive)
  804. (let ((process-environment (cl-copy-list process-environment)))
  805. (setenv "FZF_DEFAULT_COMMAND" "rg -nH --no-heading --hidden --follow --glob '!.git/*' --color=always ^")
  806. (fzf)))
  807. (define-key ctl-x-map "S" 'my-fzf-all-lines)
  808. ;; recently
  809. (when (safe-require-or-eval 'recently)
  810. (define-key ctl-x-map (kbd "C-r") 'recently-show)
  811. (set-variable 'recently-max 1000)
  812. (recently-mode 1))
  813. (when (safe-require-or-eval 'editorconfig)
  814. (set-variable 'editorconfig-get-properties-function
  815. 'editorconfig-core-get-properties-hash)
  816. (editorconfig-mode 1)
  817. (set-variable 'editorconfig-mode-lighter "")
  818. (when (fboundp 'ws-butler-mode)
  819. (set-variable 'editorconfig-trim-whitespaces-mode
  820. 'ws-butler-mode))
  821. (with-eval-after-load 'org-src
  822. ;; [*.org\[\*Org Src*\[ c \]*\]]
  823. (add-hook 'org-src-mode-hook
  824. 'editorconfig-mode-apply t)))
  825. (when (fboundp 'editorconfig-custom-majormode)
  826. (add-hook 'editorconfig-after-apply-functions
  827. 'editorconfig-custom-majormode))
  828. ;; Add readonly=true to set read-only-mode
  829. (add-hook 'editorconfig-after-apply-functions
  830. (lambda (props)
  831. (let ((r (gethash 'readonly props)))
  832. (when (and (string= r "true")
  833. (not buffer-read-only))
  834. (read-only-mode 1)))))
  835. (add-hook 'editorconfig-hack-properties-functions
  836. '(lambda (props)
  837. (when (derived-mode-p 'makefile-mode)
  838. (puthash 'indent_style "tab" props))))
  839. (when (fboundp 'editorconfig-auto-apply-enable)
  840. (add-hook 'editorconfig-conf-mode-hook
  841. 'editorconfig-auto-apply-enable))
  842. ;; (when (fboundp 'editorconfig-charset-extras)
  843. ;; (add-hook 'editorconfig-custom-hooks
  844. ;; 'editorconfig-charset-extras))
  845. (setq revert-without-query '(".+"))
  846. ;; save cursor position
  847. (when (safe-require-or-eval 'saveplace)
  848. (setq-default save-place t)
  849. (setq save-place-file (concat user-emacs-directory
  850. "places")))
  851. ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
  852. (setq make-backup-files t)
  853. (setq vc-make-backup-files t)
  854. ;; (make-directory (expand-file-name "~/.emacsbackup"))
  855. (setq backup-directory-alist
  856. (cons (cons "." (expand-file-name (concat user-emacs-directory
  857. "backup")))
  858. backup-directory-alist))
  859. (setq version-control 't)
  860. (setq delete-old-versions t)
  861. (setq kept-new-versions 20)
  862. (setq auto-save-list-file-prefix (expand-file-name (concat user-emacs-directory
  863. "auto-save/")))
  864. ;; (setq delete-auto-save-files t)
  865. (setq auto-save-visited-interval 8)
  866. (auto-save-visited-mode 1)
  867. ;; (add-to-list 'auto-save-file-name-transforms
  868. ;; `(".*" ,(concat user-emacs-directory "auto-save-dir") t))
  869. ;; (setq auto-save-interval 3)
  870. ;; (auto-save-mode 1)
  871. (add-to-list 'completion-ignored-extensions ".bak")
  872. (set-variable 'completion-cycle-threshold nil) ;; NEVER use
  873. (setq delete-by-moving-to-trash t)
  874. ;; trash-directory "~/.emacs.d/trash")
  875. (add-hook 'after-save-hook
  876. 'executable-make-buffer-file-executable-if-script-p)
  877. (set-variable 'bookmark-default-file
  878. (expand-file-name (concat user-emacs-directory
  879. "bmk")))
  880. (set-variable 'bookmark-save-flag
  881. 1)
  882. (with-eval-after-load 'recentf
  883. (defvar recentf-exclude)
  884. (defvar bookmark-default-file)
  885. (add-to-list 'recentf-exclude
  886. (regexp-quote bookmark-default-file)))
  887. (when (safe-require-or-eval 'smart-revert)
  888. (smart-revert-on))
  889. ;; autosave
  890. ;; auto-save-visited-mode can be used instead?
  891. ;; (when (safe-require-or-eval 'autosave)
  892. ;; (autosave-set 8))
  893. ;; bookmarks
  894. ;; (define-key ctl-x-map "m" 'list-bookmarks)
  895. ;; vc
  896. (set-variable 'vc-handled-backends '(RCS))
  897. (set-variable 'vc-rcs-register-switches "-l")
  898. (set-variable 'vc-rcs-checkin-switches "-l")
  899. (set-variable 'vc-command-messages t)
  900. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  901. ;; share clipboard with x
  902. ;; this page describes this in details, but only these sexps seem to be needed
  903. ;; http://garin.jp/doc/Linux/xwindow_clipboard
  904. (and nil
  905. (not window-system)
  906. (not (eq window-system 'mac))
  907. (getenv "DISPLAY")
  908. (not (equal (getenv "DISPLAY") ""))
  909. (executable-find "xclip")
  910. ;; (< emacs-major-version 24)
  911. '(safe-require-or-eval 'xclip)
  912. nil
  913. (turn-on-xclip))
  914. (and (eq system-type 'darwin)
  915. (safe-require-or-eval 'pasteboard)
  916. (turn-on-pasteboard))
  917. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  918. ;; some modes and hooks
  919. ;; Include some extra modes
  920. (require 'generic-x)
  921. (when (fboundp 'web-mode)
  922. (add-to-list 'auto-mode-alist
  923. '("\\.html\\.j2\\'" . web-mode))
  924. )
  925. (when (autoload-eval-lazily 'wgrep)
  926. (set-variable 'wgrep-auto-save-buffer t)
  927. (with-eval-after-load 'grep
  928. (defvar grep-mode-map)
  929. (define-key grep-mode-map
  930. "e"
  931. 'wgrep-change-to-wgrep-mode)))
  932. (when (fboundp 'grep-context-mode)
  933. (add-hook 'compilation-mode-hook #'grep-context-mode))
  934. (with-eval-after-load 'remember
  935. (defvar remember-mode-map)
  936. (define-key remember-mode-map (kbd "C-x C-s") 'ignore))
  937. (set-variable 'remember-notes-initial-major-mode
  938. 'change-log-mode)
  939. (with-eval-after-load 'magit-files
  940. ;; `global-magit-file-mode' is enabled by default and this mode overwrites
  941. ;; existing keybindings.
  942. ;; Apparently it is a HARMFUL behavior and it is really awful that I have
  943. ;; to disable thie mode here, but do anyway.
  944. ;; See also https://github.com/magit/magit/issues/3517
  945. (global-magit-file-mode -1))
  946. (with-eval-after-load 'magit-section
  947. (set-face-background 'magit-section-highlight
  948. nil))
  949. ;; Sane colors
  950. (with-eval-after-load 'magit-diff
  951. (set-face-background 'magit-diff-context nil)
  952. (set-face-background 'magit-diff-context-highlight nil)
  953. (set-face-foreground 'magit-diff-hunk-heading nil)
  954. (set-face-background 'magit-diff-hunk-heading nil)
  955. (set-face-foreground 'magit-diff-hunk-heading-highlight nil)
  956. (set-face-background 'magit-diff-hunk-heading-highlight nil)
  957. ;; https://blog.shibayu36.org/entry/2016/03/27/220552
  958. (set-face-foreground 'magit-diff-added "green")
  959. (set-face-background 'magit-diff-added nil)
  960. (set-face-foreground 'magit-diff-added-highlight "green")
  961. (set-face-background 'magit-diff-added-highlight nil)
  962. (set-face-foreground 'magit-diff-removed "red")
  963. (set-face-background 'magit-diff-removed nil)
  964. (set-face-foreground 'magit-diff-removed-highlight "red")
  965. (set-face-background 'magit-diff-removed-highlight nil)
  966. (set-face-background 'magit-diff-lines-boundary "blue")
  967. )
  968. (when (boundp 'git-rebase-filename-regexp)
  969. (add-to-list 'auto-mode-alist
  970. `(,git-rebase-filename-regexp . text-mode)))
  971. (when (safe-require-or-eval 'aggressive-indent)
  972. (defvar aggressive-indent-excluded-modes)
  973. (setq aggressive-indent-excluded-modes
  974. `(diff-mode
  975. toml-mode
  976. conf-mode
  977. dockerfile-mode
  978. groovy-mode
  979. scala-mode
  980. ,@aggressive-indent-excluded-modes))
  981. (global-aggressive-indent-mode 1))
  982. (when (autoload-eval-lazily 'ggtags)
  983. (add-hook 'c-mode-common-hook
  984. (lambda ()
  985. (when (derived-mode-p 'c-mode 'c++-mode 'java-mode)
  986. (ggtags-mode 1))))
  987. (add-hook 'python-mode-hook
  988. (lambda ()
  989. (ggtags-mode 1))))
  990. (when (autoload-eval-lazily 'imenu-list)
  991. ;; (set-variable 'imenu-list-auto-resize t)
  992. (set-variable 'imenu-list-focus-after-activation t)
  993. (define-key ctl-x-map "l" 'imenu-list-smart-toggle))
  994. (add-hook 'emacs-lisp-mode-hook
  995. (lambda ()
  996. (setq imenu-generic-expression
  997. `(("Sections" ";;;\+\n;; \\(.*\\)\n" 1)
  998. ,@imenu-generic-expression))))
  999. ;; TODO: Try paraedit http://daregada.blogspot.com/2012/03/paredit.html
  1000. (with-eval-after-load 'compile
  1001. (defvar compilation-filter-start)
  1002. (defvar compilation-error-regexp-alist)
  1003. (require 'ansi-color)
  1004. (add-hook 'compilation-filter-hook
  1005. (lambda ()
  1006. (let ((inhibit-read-only t))
  1007. (ansi-color-apply-on-region compilation-filter-start
  1008. (point)))))
  1009. (add-to-list 'compilation-error-regexp-alist
  1010. ;; ansible-lint
  1011. '("^\\([^ \n]+\\):\\([0-9]+\\)$" 1 2))
  1012. (add-to-list 'compilation-error-regexp-alist
  1013. ;; pydocstyle
  1014. '("^\\([^ \n]+\\):\\([0-9]+\\) " 1 2))
  1015. )
  1016. ;; Workaround to avoid ensime error
  1017. (defvar ensime-mode-key-prefix nil)
  1018. (when (safe-require-or-eval 'company)
  1019. ;; http://qiita.com/sune2/items/b73037f9e85962f5afb7
  1020. ;; https://qiita.com/yuze/items/a145b1e3edb6d0c24cbf
  1021. (global-company-mode)
  1022. (set-variable 'company-idle-delay nil)
  1023. (set-variable 'company-minimum-prefix-length 2)
  1024. (set-variable 'company-selection-wrap-around t)
  1025. (defvar company-mode-map)
  1026. (define-key company-mode-map (kbd "C-i") 'company-indent-or-complete-common)
  1027. ;; (with-eval-after-load 'python
  1028. ;; (defvar python-indent-trigger-commands)
  1029. ;; ;; TODO: This disables completion in puthon?
  1030. ;; (add-to-list 'python-indent-trigger-commands
  1031. ;; 'company-indent-or-complete-common))
  1032. (define-key ctl-x-map (kbd "C-i") 'company-complete) ; Originally `indent-rigidly'
  1033. (defvar company-active-map)
  1034. (define-key company-active-map (kbd "C-n") 'company-select-next)
  1035. (define-key company-active-map (kbd "C-p") 'company-select-previous)
  1036. (define-key company-active-map (kbd "C-s") 'company-filter-candidates)
  1037. (define-key company-active-map (kbd "C-i") 'company-complete-selection)
  1038. (define-key company-active-map (kbd "C-f") 'company-complete-selection)
  1039. (defvar company-mode)
  1040. (defvar company-candidates)
  1041. (defvar company-candidates-length)
  1042. ;; (popup-tip "Hello, World!")
  1043. (defun my-company-lighter-current-length ()
  1044. "Get current candidate length."
  1045. (interactive)
  1046. (let ((l nil)
  1047. (inhibit-message t))
  1048. (when (and company-mode
  1049. (not (minibufferp))
  1050. ;; Do nothing when already in company completion
  1051. (not company-candidates))
  1052. ;; FIXME: Somehow it cannto catch errors from ggtags
  1053. (ignore-errors
  1054. ;; (company-auto-begin)
  1055. (company-manual-begin)
  1056. (setq l company-candidates-length)
  1057. (company-cancel)))
  1058. (if l
  1059. (format "[%d]" l)
  1060. "")))
  1061. (defvar company-lighter)
  1062. (set-variable 'company-lighter-base "Cmp")
  1063. ;; (add-to-list 'company-lighter
  1064. ;; '(:eval (my-company-lighter-current-length))
  1065. ;; t)
  1066. ;; This breaks japanese text input
  1067. ;; (set-variable 'my-company-length-popup-tip-timer
  1068. ;; (run-with-idle-timer 0.2 t
  1069. ;; 'my-company-length-popup-tip))
  1070. ;; (current-active-maps)
  1071. ;; (lookup-key)
  1072. '(mapcar (lambda (map)
  1073. (lookup-key map (kbd "C-i")))
  1074. (current-active-maps))
  1075. ;; https://qiita.com/syohex/items/8d21d7422f14e9b53b17
  1076. (set-face-attribute 'company-tooltip nil
  1077. :foreground "black" :background "lightgrey")
  1078. (set-face-attribute 'company-tooltip-common nil
  1079. :foreground "black" :background "lightgrey")
  1080. (set-face-attribute 'company-tooltip-common-selection nil
  1081. :foreground "white" :background "steelblue")
  1082. (set-face-attribute 'company-tooltip-selection nil
  1083. :foreground "black" :background "steelblue")
  1084. (set-face-attribute 'company-preview-common nil
  1085. :background nil :foreground "lightgrey" :underline t)
  1086. (set-face-attribute 'company-scrollbar-fg nil
  1087. :background "orange")
  1088. (set-face-attribute 'company-scrollbar-bg nil
  1089. :background "gray40")
  1090. )
  1091. ;; https://github.com/lunaryorn/flycheck
  1092. (when (safe-require-or-eval 'flycheck)
  1093. (call-after-init (global-flycheck-mode)))
  1094. (with-eval-after-load 'flycheck
  1095. (when (fboundp 'flycheck-black-check-setup)
  1096. (flycheck-black-check-setup)))
  1097. (when (autoload-eval-lazily 'ilookup)
  1098. (define-key ctl-x-map "d" 'ilookup-open-word))
  1099. (set-variable 'ac-ignore-case nil)
  1100. (when (autoload-eval-lazily 'term-run '(term-run-shell-command term-run))
  1101. (define-key ctl-x-map "t" 'term-run-shell-command))
  1102. (add-to-list 'safe-local-variable-values
  1103. '(encoding utf-8))
  1104. (setq enable-local-variables :safe)
  1105. ;; Detect file type from shebang and set major-mode.
  1106. (add-to-list 'interpreter-mode-alist
  1107. '("python3" . python-mode))
  1108. (add-to-list 'interpreter-mode-alist
  1109. '("python2" . python-mode))
  1110. (with-eval-after-load 'python
  1111. (defvar python-mode-map (make-sparse-keymap))
  1112. (define-key python-mode-map (kbd "C-m") 'newline-and-indent))
  1113. (set-variable 'py-indent-list-style
  1114. 'one-level-to-beginning-of-statement)
  1115. (set-variable 'pydoc-command
  1116. "python3 -m pydoc")
  1117. (when (autoload-eval-lazily 'pipenv)
  1118. ;; (declare-function pipenv-projectile-after-switch-default "pipenv")
  1119. ;; (add-hook 'python-mode-hook
  1120. ;; (lambda ()
  1121. ;; (pipenv-mode 1)
  1122. ;; (pipenv-projectile-after-switch-default)))
  1123. )
  1124. (set-variable 'flycheck-python-mypy-ini ".mypy.ini")
  1125. (set-variable 'flycheck-python-pylint-executable "python3")
  1126. (set-variable 'flycheck-python-pycompile-executable "python3")
  1127. (set-variable 'python-indent-guess-indent-offset nil)
  1128. (with-eval-after-load 'blacken
  1129. (when (require 'with-venv nil t)
  1130. (with-venv-advice-add 'blacken-buffer)))
  1131. ;; https://github.com/lunaryorn/old-emacs-configuration/blob/master/lisp/flycheck-virtualenv.el
  1132. (defun my-set-venv-flycheck-executable-find ()
  1133. "Set flycheck executabie find."
  1134. (when (require 'with-venv nil t)
  1135. (set-variable 'flycheck-executable-find
  1136. '(lambda (e)
  1137. (with-venv
  1138. (executable-find e)))
  1139. t)))
  1140. ;; TODO: This sucks when venv dir is not found
  1141. ;; (add-hook 'python-mode-hook
  1142. ;; 'my-set-venv-flycheck-executable-find)
  1143. ;; Run multiple chekcers
  1144. ;; https://github.com/flycheck/flycheck/issues/186
  1145. ;; http://fukuyama.co/foreign-regexp
  1146. '(and (safe-require-or-eval 'foreign-regexp)
  1147. (progn
  1148. (setq foreign-regexp/regexp-type 'perl)
  1149. '(setq reb-re-syntax 'foreign-regexp)
  1150. ))
  1151. (autoload-eval-lazily 'sql '(sql-mode)
  1152. (require 'sql-indent nil t))
  1153. (add-to-list 'auto-mode-alist
  1154. '("\\.hql\\'" . sql-mode))
  1155. (when (autoload-eval-lazily 'git-command)
  1156. (define-key ctl-x-map "g" 'git-command))
  1157. (when (autoload-eval-lazily 'gited)
  1158. (define-key ctl-x-map (kbd "C-g") 'gited-list))
  1159. (when (safe-require-or-eval 'git-commit)
  1160. (global-git-commit-mode 1))
  1161. (with-eval-after-load 'git-commit
  1162. (add-hook 'git-commit-setup-hook
  1163. 'turn-off-auto-fill t))
  1164. (autoload-eval-lazily 'sl)
  1165. (with-eval-after-load 'rst
  1166. (defvar rst-mode-map)
  1167. (define-key rst-mode-map (kbd "C-m") 'newline-and-indent))
  1168. (with-eval-after-load 'jdee
  1169. (add-hook 'jdee-mode-hook
  1170. (lambda ()
  1171. (make-local-variable 'global-mode-string)
  1172. (add-to-list 'global-mode-string
  1173. mode-line-position))))
  1174. ;; Cannot enable error thrown. Why???
  1175. ;; https://github.com/m0smith/malabar-mode#Installation
  1176. ;; (when (autoload-eval-lazily 'malabar-mode)
  1177. ;; (add-to-list 'load-path
  1178. ;; (expand-file-name (concat user-emacs-directory "/cedet")))
  1179. ;; (safe-require-or-eval 'cedet-devel-load)
  1180. ;; (call-after-init (activate-malabar-mode)))
  1181. (with-eval-after-load 'make-mode
  1182. (defvar makefile-mode-map (make-sparse-keymap))
  1183. (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
  1184. ;; this functions is set in write-file-functions, i cannot find any
  1185. ;; good way to remove this.
  1186. (fset 'makefile-warn-suspicious-lines 'ignore))
  1187. (with-eval-after-load 'verilog-mode
  1188. (defvar verilog-mode-map (make-sparse-keymap))
  1189. (define-key verilog-mode-map ";" 'self-insert-command))
  1190. (setq diff-switches "-u")
  1191. (with-eval-after-load 'diff-mode
  1192. ;; (when (and (eq major-mode
  1193. ;; 'diff-mode)
  1194. ;; (not buffer-file-name))
  1195. ;; ;; do not pass when major-mode is derived mode of diff-mode
  1196. ;; (view-mode 1))
  1197. (set-face-attribute 'diff-header nil
  1198. :foreground nil
  1199. :background nil
  1200. :weight 'bold)
  1201. (set-face-attribute 'diff-file-header nil
  1202. :foreground nil
  1203. :background nil
  1204. :weight 'bold)
  1205. (set-face-foreground 'diff-index "blue")
  1206. (set-face-attribute 'diff-hunk-header nil
  1207. :foreground "cyan"
  1208. :weight 'normal)
  1209. (set-face-attribute 'diff-context nil
  1210. ;; :foreground "white"
  1211. :foreground nil
  1212. :weight 'normal)
  1213. (set-face-foreground 'diff-removed "red")
  1214. (set-face-foreground 'diff-added "green")
  1215. (set-face-background 'diff-removed nil)
  1216. (set-face-background 'diff-added nil)
  1217. (set-face-attribute 'diff-changed nil
  1218. :foreground "magenta"
  1219. :weight 'normal)
  1220. (set-face-attribute 'diff-refine-changed nil
  1221. :foreground nil
  1222. :background nil
  1223. :weight 'bold
  1224. :inverse-video t)
  1225. ;; Annoying !
  1226. ;;(diff-auto-refine-mode)
  1227. )
  1228. ;; (ffap-bindings)
  1229. (set-variable 'browse-url-browser-function
  1230. 'eww-browse-url)
  1231. (set-variable 'sh-here-document-word "__EOC__")
  1232. (when (autoload-eval-lazily 'adoc-mode
  1233. nil
  1234. (defvar adoc-mode-map (make-sparse-keymap))
  1235. (define-key adoc-mode-map (kbd "C-m") 'newline))
  1236. (setq auto-mode-alist
  1237. `(("\\.adoc\\'" . adoc-mode)
  1238. ("\\.asciidoc\\'" . adoc-mode)
  1239. ,@auto-mode-alist)))
  1240. (with-eval-after-load 'markup-faces
  1241. ;; Is this too match ?
  1242. (set-face-foreground 'markup-meta-face
  1243. "color-245")
  1244. (set-face-foreground 'markup-meta-hide-face
  1245. "color-245")
  1246. )
  1247. ;; TODO: check if this is required
  1248. (when (autoload-eval-lazily 'groovy-mode nil
  1249. (defvar groovy-mode-map (make-sparse-keymap))
  1250. (define-key groovy-mode-map "(" 'self-insert-command)
  1251. (define-key groovy-mode-map ")" 'self-insert-command)
  1252. (define-key groovy-mode-map (kbd "C-m") 'newline-and-indent)
  1253. )
  1254. (add-to-list 'auto-mode-alist
  1255. '("build\\.gradle\\'" . groovy-mode)))
  1256. (add-to-list 'auto-mode-alist
  1257. '("\\.gawk\\'" . awk-mode))
  1258. (with-eval-after-load 'yaml-mode
  1259. (defvar yaml-mode-map (make-sparse-keymap))
  1260. (define-key yaml-mode-map (kbd "C-m") 'newline))
  1261. (with-eval-after-load 'html-mode
  1262. (defvar html-mode-map (make-sparse-keymap))
  1263. (define-key html-mode-map (kbd "C-m") 'reindent-then-newline-and-indent))
  1264. (with-eval-after-load 'text-mode
  1265. (define-key text-mode-map (kbd "C-m") 'newline))
  1266. (autoload-eval-lazily 'info nil
  1267. (defvar Info-additional-directory-list)
  1268. (dolist (dir (directory-files (concat user-emacs-directory
  1269. "info")
  1270. t
  1271. "^[^.].*"))
  1272. (when (file-directory-p dir)
  1273. (add-to-list 'Info-additional-directory-list
  1274. dir)))
  1275. (let ((dir (expand-file-name "~/.brew/share/info")))
  1276. (when (file-directory-p dir)
  1277. (add-to-list 'Info-additional-directory-list
  1278. dir))))
  1279. (with-eval-after-load 'apropos
  1280. (defvar apropos-mode-map (make-sparse-keymap))
  1281. (define-key apropos-mode-map "n" 'next-line)
  1282. (define-key apropos-mode-map "p" 'previous-line))
  1283. ;; `isearch' library does not call `provide' so cannot use with-eval-after-load
  1284. ;; (define-key isearch-mode-map
  1285. ;; (kbd "C-j") 'isearch-other-control-char)
  1286. ;; (define-key isearch-mode-map
  1287. ;; (kbd "C-k") 'isearch-other-control-char)
  1288. ;; (define-key isearch-mode-map
  1289. ;; (kbd "C-h") 'isearch-other-control-char)
  1290. (define-key isearch-mode-map (kbd "C-h") 'isearch-del-char)
  1291. (define-key isearch-mode-map (kbd "M-r")
  1292. 'isearch-query-replace-regexp)
  1293. ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
  1294. (setq lazy-highlight-cleanup nil)
  1295. ;; face for isearch highlighing
  1296. (set-face-attribute 'lazy-highlight
  1297. nil
  1298. :foreground `unspecified
  1299. :background `unspecified
  1300. :underline t
  1301. ;; :weight `bold
  1302. )
  1303. (add-hook 'outline-mode-hook
  1304. (lambda ()
  1305. (when (string-match "\\.md\\'" buffer-file-name)
  1306. (set (make-local-variable 'outline-regexp) "#+ "))))
  1307. (add-hook 'outline-mode-hook
  1308. 'outline-show-all)
  1309. (add-to-list 'auto-mode-alist (cons "\\.ol\\'" 'outline-mode))
  1310. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
  1311. (when (autoload-eval-lazily 'markdown-mode
  1312. '(markdown-mode gfm-mode)
  1313. (defvar gfm-mode-map (make-sparse-keymap))
  1314. (define-key gfm-mode-map (kbd "C-m") 'electric-indent-just-newline))
  1315. (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'gfm-mode))
  1316. (set-variable 'markdown-command (or (executable-find "markdown")
  1317. (executable-find "markdown.pl")
  1318. ""))
  1319. (add-hook 'markdown-mode-hook
  1320. (lambda ()
  1321. (outline-minor-mode 1)
  1322. (flyspell-mode)
  1323. (set (make-local-variable 'comment-start) ";")))
  1324. )
  1325. ;; c-mode
  1326. ;; http://www.emacswiki.org/emacs/IndentingC
  1327. ;; http://en.wikipedia.org/wiki/Indent_style
  1328. ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
  1329. ;; http://seesaawiki.jp/whiteflare503/d/Emacs%20%a5%a4%a5%f3%a5%c7%a5%f3%a5%c8
  1330. (with-eval-after-load 'cc-vars
  1331. (defvar c-default-style nil)
  1332. (add-to-list 'c-default-style
  1333. '(c-mode . "k&r"))
  1334. (add-to-list 'c-default-style
  1335. '(c++-mode . "k&r")))
  1336. (autoload-eval-lazily 'js2-mode nil
  1337. ;; currently do not use js2-mode
  1338. ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
  1339. ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
  1340. ;; (defvar js2-mode-map (make-sparse-keymap))
  1341. ;; (define-key js2-mode-map (kbd "C-m") (lambda ()
  1342. ;; (interactive)
  1343. ;; (js2-enter-key)
  1344. ;; (indent-for-tab-command)))
  1345. ;; (add-hook (kill-local-variable 'before-save-hook)
  1346. ;; 'js2-before-save)
  1347. ;; (add-hook 'before-save-hook
  1348. ;; 'my-indent-buffer
  1349. ;; nil
  1350. ;; t)
  1351. )
  1352. (add-to-list 'interpreter-mode-alist
  1353. '("node" . js-mode))
  1354. (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
  1355. (with-eval-after-load 'uniquify
  1356. (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
  1357. (setq uniquify-ignore-buffers-re "*[^*]+*")
  1358. (setq uniquify-min-dir-content 1))
  1359. (with-eval-after-load 'view
  1360. (defvar view-mode-map (make-sparse-keymap))
  1361. (define-key view-mode-map "j" 'scroll-up-line)
  1362. (define-key view-mode-map "k" 'scroll-down-line)
  1363. (define-key view-mode-map "v" 'toggle-read-only)
  1364. (define-key view-mode-map "q" 'bury-buffer)
  1365. ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
  1366. ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
  1367. ;; (define-key view-mode-map
  1368. ;; "n" 'nonincremental-repeat-search-forward)
  1369. ;; (define-key view-mode-map
  1370. ;; "N" 'nonincremental-repeat-search-backward)
  1371. ;; N conflicts with git-walktree
  1372. ;; (define-key view-mode-map "/" 'isearch-forward-regexp)
  1373. ;; (define-key view-mode-map "?" 'isearch-backward-regexp)
  1374. ;; (define-key view-mode-map "n" 'isearch-repeat-forward)
  1375. ;; (define-key view-mode-map "N" 'isearch-repeat-backward)
  1376. (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point))
  1377. (global-set-key "\M-r" 'view-mode)
  1378. ;; (setq view-read-only t)
  1379. (with-eval-after-load 'term
  1380. (defvar term-raw-map (make-sparse-keymap))
  1381. (define-key term-raw-map (kbd "C-x")
  1382. (lookup-key (current-global-map)
  1383. (kbd "C-x"))))
  1384. (add-hook 'term-mode-hook
  1385. (lambda ()
  1386. ;; Stop current line highlighting
  1387. (set (make-local-variable (defvar hl-line-range-function))
  1388. (lambda () '(0 . 0)))
  1389. (set (make-local-variable 'scroll-margin)
  1390. 0)
  1391. (set-variable 'term-buffer-maximum-size 20480)
  1392. ))
  1393. (add-hook 'Man-mode-hook
  1394. (lambda ()
  1395. (view-mode 1)
  1396. (setq truncate-lines nil)))
  1397. (set-variable 'Man-notify-method (if window-system
  1398. 'newframe
  1399. 'aggressive))
  1400. (set-variable 'woman-cache-filename (expand-file-name (concat user-emacs-directory
  1401. "woman_cache.el")))
  1402. ;; not work because man.el will be loaded when man called
  1403. (defalias 'man 'woman)
  1404. (add-to-list 'auto-mode-alist
  1405. '("tox\\.ini\\'" . conf-unix-mode))
  1406. (when (autoload-eval-lazily 'toml-mode)
  1407. (add-to-list 'auto-mode-alist
  1408. '("/tox\\.ini\\'" . toml-mode))
  1409. (add-to-list 'auto-mode-alist
  1410. '("/Pipfile\\'" . toml-mode))
  1411. (add-to-list 'auto-mode-alist
  1412. '("/poetry\\.lock\\'" . toml-mode))
  1413. )
  1414. (when (autoload-eval-lazily 'json-mode)
  1415. (add-to-list 'auto-mode-alist
  1416. '("/Pipfile\\.lock\\'" . json-mode)))
  1417. (add-hook 'go-mode-hook
  1418. (lambda()
  1419. (defvar go-mode-map)
  1420. (add-hook 'before-save-hook' 'gofmt-before-save nil t)
  1421. (define-key go-mode-map (kbd "M-.") 'godef-jump)))
  1422. (when (autoload-eval-lazily 'k8s-mode)
  1423. (add-to-list 'auto-mode-alist
  1424. '("\\.k8s\\'" . k8s-mode)))
  1425. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1426. ;; buffers
  1427. (defvar bs-configurations)
  1428. (declare-function bs-set-configuration "bs")
  1429. (declare-function bs-refresh "bs")
  1430. (declare-function bs-message-without-log "bs")
  1431. (declare-function bs--current-config-message "bs")
  1432. (when (autoload-eval-lazily 'bs '(bs-show)
  1433. (add-to-list 'bs-configurations
  1434. '("specials" "^\\*" nil ".*" nil nil))
  1435. (add-to-list 'bs-configurations
  1436. '("files-and-specials" "^\\*" buffer-file-name ".*" nil nil))
  1437. (defvar bs-mode-map)
  1438. (defvar bs-current-configuration)
  1439. (define-key bs-mode-map (kbd "t")
  1440. ;; TODO: fix toggle feature
  1441. (lambda ()
  1442. (interactive)
  1443. (if (string= "specials"
  1444. bs-current-configuration)
  1445. (bs-set-configuration "files")
  1446. (bs-set-configuration "specials"))
  1447. (bs-refresh)
  1448. (bs-message-without-log "%s"
  1449. (bs--current-config-message))))
  1450. ;; (setq bs-configurations (list
  1451. ;; '("processes" nil get-buffer-process ".*" nil nil)
  1452. ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
  1453. ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
  1454. )
  1455. (defalias 'list-buffers 'bs-show)
  1456. (set-variable 'bs-default-configuration "files-and-specials")
  1457. (set-variable 'bs-default-sort-name "by nothing")
  1458. (add-hook 'bs-mode-hook
  1459. (lambda ()
  1460. (set (make-local-variable 'scroll-margin) 0))))
  1461. ;;(iswitchb-mode 1)
  1462. (icomplete-mode)
  1463. (defun iswitchb-buffer-display-other-window ()
  1464. "Do iswitchb in other window."
  1465. (interactive)
  1466. (let ((iswitchb-default-method 'display))
  1467. (call-interactively 'iswitchb-buffer)))
  1468. ;; buffer killing
  1469. ;; (defun my-delete-window-killing-buffer () nil)
  1470. (defun my-query-kill-current-buffer ()
  1471. "Interactively kill current buffer."
  1472. (interactive)
  1473. (if (y-or-n-p (concat "kill current buffer? :"))
  1474. (kill-buffer (current-buffer))))
  1475. ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
  1476. (substitute-key-definition 'kill-buffer
  1477. 'my-query-kill-current-buffer
  1478. global-map)
  1479. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1480. ;; dired
  1481. (defun my-file-head (filename &optional n)
  1482. "Return list of first N lines of file FILENAME."
  1483. ;; TODO: Fix for janapese text
  1484. ;; TODO: Fix for short text
  1485. (let ((num (or n 10))
  1486. (size 100)
  1487. (beg 0)
  1488. (end 0)
  1489. (result '())
  1490. (read -1))
  1491. (with-temp-buffer
  1492. (erase-buffer)
  1493. (while (or (<= (count-lines (point-min)
  1494. (point-max))
  1495. num)
  1496. (eq read 0))
  1497. (setq end (+ beg size))
  1498. (setq read (nth 1 (insert-file-contents-literally filename
  1499. nil
  1500. beg
  1501. end)))
  1502. (goto-char (point-max))
  1503. (setq beg (+ beg size)))
  1504. (goto-char (point-min))
  1505. (while (< (length result) num)
  1506. (let ((start (point)))
  1507. (forward-line 1)
  1508. (setq result
  1509. `(,@result ,(buffer-substring-no-properties start
  1510. (point))))))
  1511. result
  1512. ;; (buffer-substring-no-properties (point-min)
  1513. ;; (progn
  1514. ;; (forward-line num)
  1515. ;; (point)))
  1516. )))
  1517. ;; (apply 'concat (my-file-head "./shrc" 10)
  1518. (defun my-dired-echo-file-head (arg)
  1519. "Echo head of current file.
  1520. ARG is num to show, or defaults to 7."
  1521. (interactive "P")
  1522. (let ((f (dired-get-filename)))
  1523. (message "%s"
  1524. (apply 'concat
  1525. (my-file-head f
  1526. 7)))))
  1527. (defun my-dired-diff ()
  1528. "Show diff of marked file and file of current line."
  1529. (interactive)
  1530. (let ((files (dired-get-marked-files nil nil nil t)))
  1531. (if (eq (car files)
  1532. t)
  1533. (diff (cadr files) (dired-get-filename))
  1534. (message "One file must be marked!"))))
  1535. (defun dired-get-file-info ()
  1536. "Print information of current line file."
  1537. (interactive)
  1538. (let ((f (shell-quote-argument (dired-get-filename t))))
  1539. (if (file-directory-p f)
  1540. (progn
  1541. (message "Calculating disk usage...")
  1542. (shell-command (concat "du -hsD "
  1543. f)))
  1544. (shell-command (concat "file "
  1545. f)))))
  1546. (defun my-dired-scroll-up ()
  1547. "Scroll up."
  1548. (interactive)
  1549. (my-dired-previous-line (- (window-height) 1)))
  1550. (defun my-dired-scroll-down ()
  1551. "Scroll down."
  1552. (interactive)
  1553. (my-dired-next-line (- (window-height) 1)))
  1554. ;; (defun my-dired-forward-line (arg)
  1555. ;; ""
  1556. ;; (interactive "p"))
  1557. (defun my-dired-previous-line (arg)
  1558. "Move ARG lines up."
  1559. (interactive "p")
  1560. (if (> arg 0)
  1561. (progn
  1562. (if (eq (line-number-at-pos)
  1563. 1)
  1564. (goto-char (point-max))
  1565. (forward-line -1))
  1566. (my-dired-previous-line (if (or (dired-get-filename nil t)
  1567. (dired-get-subdir))
  1568. (- arg 1)
  1569. arg)))
  1570. (dired-move-to-filename)))
  1571. (defun my-dired-next-line (arg)
  1572. "Move ARG lines down."
  1573. (interactive "p")
  1574. (if (> arg 0)
  1575. (progn
  1576. (if (eq (point)
  1577. (point-max))
  1578. (goto-char (point-min))
  1579. (forward-line 1))
  1580. (my-dired-next-line (if (or (dired-get-filename nil t)
  1581. (dired-get-subdir))
  1582. (- arg 1)
  1583. arg)))
  1584. (dired-move-to-filename)))
  1585. (defun my-tramp-remote-find-file (f)
  1586. "Open F."
  1587. (interactive (list (read-file-name "My Find File Tramp: "
  1588. "/scp:"
  1589. nil ;; "/scp:"
  1590. (confirm-nonexistent-file-or-buffer))))
  1591. (find-file f))
  1592. ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
  1593. (if (eq window-system 'mac)
  1594. (setq dired-listing-switches "-lhF")
  1595. (setq dired-listing-switches "-lhF --time-style=long-iso")
  1596. )
  1597. (setq dired-listing-switches "-lhF")
  1598. ;; when using dired-find-alternate-file
  1599. ;; reuse current dired buffer for the file to open
  1600. ;; (put 'dired-find-alternate-file 'disabled nil)
  1601. (set-variable 'dired-ls-F-marks-symlinks t)
  1602. (set-variable 'ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
  1603. (set-variable 'ls-lisp-dirs-first t)
  1604. (set-variable 'ls-lisp-use-localized-time-format t)
  1605. (set-variable 'ls-lisp-format-time-list
  1606. '("%Y-%m-%d %H:%M"
  1607. "%Y-%m-%d "))
  1608. (set-variable 'dired-dwim-target t)
  1609. (set-variable 'dired-isearch-filenames t)
  1610. (set-variable 'dired-hide-details-hide-symlink-targets nil)
  1611. (set-variable 'dired-hide-details-hide-information-lines nil)
  1612. (set-variable 'dired-deletion-confirmer 'y-or-n-p)
  1613. (set-variable 'dired-recursive-deletes 'always)
  1614. ;; (add-hook 'dired-after-readin-hook
  1615. ;; 'my-replace-nasi-none)
  1616. (with-eval-after-load 'dired
  1617. (safe-require-or-eval 'ls-lisp)
  1618. (defvar dired-mode-map (make-sparse-keymap))
  1619. ;; dired-do-chgrp sometimes cause system hung
  1620. (define-key dired-mode-map "G" 'ignore)
  1621. (define-key dired-mode-map "e" 'wdired-change-to-wdired-mode)
  1622. (define-key dired-mode-map "i" 'dired-get-file-info)
  1623. ;; (define-key dired-mode-map "f" 'find-file)
  1624. (define-key dired-mode-map "f" 'my-fzf-or-find-file)
  1625. (define-key dired-mode-map "z" 'fzf)
  1626. (define-key dired-mode-map "!" 'shell-command)
  1627. (define-key dired-mode-map "&" 'async-shell-command)
  1628. (define-key dired-mode-map "X" 'dired-do-async-shell-command)
  1629. (define-key dired-mode-map "=" 'my-dired-diff)
  1630. (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
  1631. (define-key dired-mode-map "b" 'gtkbm)
  1632. (define-key dired-mode-map "h" 'my-dired-echo-file-head)
  1633. (define-key dired-mode-map (kbd "TAB") 'other-window)
  1634. ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
  1635. (define-key dired-mode-map "/" 'dired-isearch-filenames)
  1636. (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
  1637. (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
  1638. (substitute-key-definition 'dired-next-line
  1639. 'my-dired-next-line
  1640. dired-mode-map)
  1641. (substitute-key-definition 'dired-previous-line
  1642. 'my-dired-previous-line
  1643. dired-mode-map)
  1644. ;; (define-key dired-mode-map (kbd "C-p") 'my-dired-previous-line)
  1645. ;; (define-key dired-mode-map (kbd "p") 'my-dired-previous-line)
  1646. ;; (define-key dired-mode-map (kbd "C-n") 'my-dired-next-line)
  1647. ;; (define-key dired-mode-map (kbd "n") 'my-dired-next-line)
  1648. (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
  1649. (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
  1650. (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
  1651. (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
  1652. (add-hook 'dired-mode-hook
  1653. (lambda ()
  1654. (when (fboundp 'dired-hide-details-mode)
  1655. (dired-hide-details-mode t)
  1656. (local-set-key "l" 'dired-hide-details-mode))
  1657. (let ((file "._Icon\015"))
  1658. (when nil
  1659. '(file-readable-p file)
  1660. (delete-file file)))))
  1661. (when (autoload-eval-lazily 'pack '(dired-do-pack-or-unpack pack-pack)
  1662. (defvar pack-program-alist)
  1663. (add-to-list 'pack-program-alist
  1664. '("\\.txz\\'" :pack "tar -cJf" :unpack "tar -xf")))
  1665. (set-variable 'pack-silence
  1666. t)
  1667. (with-eval-after-load 'dired
  1668. (define-key dired-mode-map "P" 'pack-dired-dwim)))
  1669. (when (autoload-eval-lazily 'dired-list-all-mode)
  1670. (setq dired-listing-switches "-lhF")
  1671. (with-eval-after-load 'dired
  1672. (define-key dired-mode-map "a" 'dired-list-all-mode))))
  1673. (when (autoload-eval-lazily 'dired-filter)
  1674. (add-hook 'dired-mode-hook
  1675. 'dired-filter-mode))
  1676. (set-variable 'dired-filter-stack nil)
  1677. ;; Currently disabled in favor of dired-from-git-ls-files
  1678. ;; (define-key ctl-x-map "f" 'find-dired)
  1679. (defvar my-dired-git-ls-files-history
  1680. "History for `my-dired-git-ls-files'." nil)
  1681. (defun my-dired-git-ls-files (arg)
  1682. "Dired from git ls-files."
  1683. (interactive (list
  1684. (read-shell-command "git ls-files: "
  1685. "git ls-files -z ")))
  1686. (pop-to-buffer-same-window
  1687. (dired-noselect `(,default-directory
  1688. ,@(split-string (shell-command-to-string arg)
  1689. "\0" t))
  1690. ""))
  1691. )
  1692. (define-key ctl-x-map (kbd "G") 'my-dired-git-ls-files)
  1693. (with-eval-after-load 'dired
  1694. (defvar dired-mode-map (make-sparse-keymap))
  1695. (define-key dired-mode-map "G" 'my-dired-git-ls-files))
  1696. ;; (define-minor-mode my-dired-glob-filter)
  1697. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1698. ;; misc funcs
  1699. (define-key ctl-x-map "T" 'git-worktree)
  1700. (define-key ctl-x-map "W" 'git-walktree)
  1701. (when (fboundp 'browse-url-default-macosx-browser)
  1702. (defalias 'browse-osx 'browse-url-default-macosx-browser))
  1703. (defalias 'qcalc 'quick-calc)
  1704. (defun memo (&optional dir)
  1705. "Open memo.txt in DIR."
  1706. (interactive)
  1707. (pop-to-buffer (find-file-noselect (concat (if dir
  1708. (file-name-as-directory dir)
  1709. "")
  1710. "memo.txt"))))
  1711. ;; TODO: remember-projectile
  1712. (set (defvar my-privnotes-path nil
  1713. "My privnotes repository path.")
  1714. (expand-file-name "~/my/privnotes"))
  1715. (defun my-privnotes-readme (dir)
  1716. "Open my privnotes DIR."
  1717. (interactive (list
  1718. (read-file-name "Privnotes: "
  1719. (expand-file-name (format-time-string "%Y%m%d_")
  1720. my-privnotes-path))))
  1721. (let ((path (expand-file-name "README.md" dir)))
  1722. (with-current-buffer (find-file path)
  1723. (unless (file-exists-p path)
  1724. (insert (file-name-base dir)
  1725. "\n"
  1726. "=======\n"
  1727. "\n\n")))))
  1728. (define-key ctl-x-map "p" 'my-privnotes-readme)
  1729. (set (defvar my-rgrep-alist nil
  1730. "Alist of rgrep command.
  1731. Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
  1732. condition to choose COMMAND when evaluated.")
  1733. `(
  1734. ;; ripgrep
  1735. ("rg"
  1736. (executable-find "rg")
  1737. "rg -nH --no-heading --color=always --hidden --glob '!.git/' --smart-case -M 1280 ")
  1738. ;; git grep
  1739. ("gitgrep"
  1740. (eq 0
  1741. (shell-command "git rev-parse --git-dir"))
  1742. "git --no-pager -c color.grep=always grep -nH -e ")
  1743. ;; sift
  1744. ("sift"
  1745. (executable-find "sift")
  1746. ("sift --binary-skip --filename --line-number --git --smart-case "))
  1747. ;; the silver searcher
  1748. ("ag"
  1749. (executable-find "ag")
  1750. "ag --nogroup --nopager --filename ")
  1751. ;; ack
  1752. ("ack"
  1753. (executable-find "ack")
  1754. "ack --nogroup --nopager --with-filename ")
  1755. ;; gnu global
  1756. ("global"
  1757. (and (require 'ggtags nil t)
  1758. (executable-find "global")
  1759. (ggtags-current-project-root))
  1760. "global --result grep ")
  1761. ;; grep
  1762. ("grep"
  1763. t
  1764. ,(concat "find . "
  1765. "-path '*/.git' -prune -o "
  1766. "-path '*/.svn' -prune -o "
  1767. "-type f -print0 | "
  1768. "xargs -0 grep -nH -e "))
  1769. )
  1770. )
  1771. (defvar my-rgrep-default nil
  1772. "Default command name for my-rgrep.")
  1773. (defun my-rgrep-grep-command (&optional name alist)
  1774. "Return recursive grep command for current directory or nil.
  1775. If NAME is given, use that without testing.
  1776. Commands are searched from ALIST."
  1777. (if alist
  1778. (if name
  1779. ;; if name is given search that from alist and return the command
  1780. (nth 2 (assoc name
  1781. alist))
  1782. ;; if name is not given try test in 1th elem
  1783. (let ((car (car alist))
  1784. (cdr (cdr alist)))
  1785. (if (eval (nth 1 car))
  1786. ;; if the condition is true return the command
  1787. (nth 2 car)
  1788. ;; try next one
  1789. (and cdr
  1790. (my-rgrep-grep-command name cdr)))))
  1791. ;; if alist is not given set default value
  1792. (my-rgrep-grep-command name my-rgrep-alist)))
  1793. (defun my-rgrep (command-args)
  1794. "My recursive grep. Run COMMAND-ARGS.
  1795. If prefix argument is given, use current symbol as default search target
  1796. and search from projectile root (if projectile is available)."
  1797. (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
  1798. nil)))
  1799. (if cmd
  1800. (list (read-shell-command "grep command: "
  1801. (concat cmd
  1802. (if current-prefix-arg
  1803. (thing-at-point 'symbol t)
  1804. ""))
  1805. 'grep-find-history))
  1806. (error "My-Rgrep: Command for rgrep not found")
  1807. )))
  1808. (if (and current-prefix-arg
  1809. (safe-require-or-eval 'projectile)
  1810. (projectile-project-p))
  1811. (projectile-with-default-dir (projectile-project-root)
  1812. (compilation-start command-args
  1813. 'grep-mode))
  1814. (compilation-start command-args
  1815. 'grep-mode)))
  1816. (defun my-rgrep-thing-at-point-projectile-root ()
  1817. "My recursive grep to find thing at point from project root."
  1818. (interactive)
  1819. (let* ((cmd (my-rgrep-grep-command my-rgrep-default
  1820. nil))
  1821. (command-args
  1822. (if cmd
  1823. (concat cmd
  1824. (or (thing-at-point 'symbol t)
  1825. (error "No symbol at point")))
  1826. (error "My-Rgrep: Command for rgrep not found"))))
  1827. (if (safe-require-or-eval 'projectile)
  1828. (projectile-with-default-dir (or (projectile-project-root)
  1829. default-directory)
  1830. (compilation-start command-args
  1831. 'grep-mode))
  1832. (compilation-start command-args
  1833. 'grep-mode))))
  1834. (defmacro define-my-rgrep (name)
  1835. "Define rgrep for NAME."
  1836. `(defun ,(intern (concat "my-rgrep-"
  1837. name)) ()
  1838. ,(format "My recursive grep by %s."
  1839. name)
  1840. (interactive)
  1841. (let ((my-rgrep-default ,name))
  1842. (if (called-interactively-p 'any)
  1843. (call-interactively 'my-rgrep)
  1844. (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
  1845. )
  1846. (define-my-rgrep "ack")
  1847. (define-my-rgrep "ag")
  1848. (define-my-rgrep "rg")
  1849. (define-my-rgrep "sift")
  1850. (define-my-rgrep "gitgrep")
  1851. (define-my-rgrep "grep")
  1852. (define-my-rgrep "global")
  1853. (define-key ctl-x-map "s" 'my-rgrep)
  1854. (define-key ctl-x-map "." 'my-rgrep-thing-at-point-projectile-root)
  1855. (defun my-occur (regexp &optional region)
  1856. "My occur command to search REGEXP."
  1857. (interactive (list (read-string "List lines matching regexp: "
  1858. (thing-at-point 'symbol t))))
  1859. (occur regexp nil region))
  1860. (define-key ctl-x-map (kbd "C-o") 'my-occur)
  1861. (set-variable 'dumb-jump-prefer-searcher 'rg)
  1862. (defalias 'make 'compile)
  1863. (define-key ctl-x-map "c" 'compile)
  1864. (defun my-pushbullet-note (text &optional title)
  1865. "Push TEXT."
  1866. (interactive "sText to Push: ")
  1867. (pb/push-item '("") text "note" (or title "")))
  1868. ;;;;;;;;;;;;;;;;;;;;;
  1869. ;; git-bug
  1870. (defconst git-bug-ls-regexp
  1871. (eval-when-compile
  1872. (rx bol
  1873. (submatch (one-or-more alphanumeric)) ; id
  1874. ;; (one-or-more any)
  1875. (one-or-more space)
  1876. (submatch (or "open" "close")) ; status
  1877. (one-or-more space)
  1878. (submatch (maximal-match (zero-or-more print))) ; title
  1879. "\t"
  1880. (submatch (one-or-more alphanumeric)) ; user
  1881. (one-or-more space)
  1882. "C:"
  1883. (submatch (one-or-more digit)) ; Comment num
  1884. (one-or-more space)
  1885. "L:"
  1886. (submatch (one-or-more digit)) ; Label num
  1887. eol
  1888. ))
  1889. "Regexp to parse line of output of git-bug ls.
  1890. Used by `git-bug-ls'.")
  1891. (defun git-bug-bugs ()
  1892. "Get list of git-bug bugs."
  1893. (with-temp-buffer
  1894. (git-bug--call-process "bug" "ls")
  1895. (goto-char (point-min))
  1896. (let ((bugs nil))
  1897. (while (not (eq (point) (point-max)))
  1898. (save-match-data
  1899. (when (re-search-forward git-bug-ls-regexp (point-at-eol) t)
  1900. (setq bugs `(,@bugs
  1901. ,(list
  1902. :id (match-string 1)
  1903. :status (match-string 2)
  1904. :title (string-trim (match-string 3))
  1905. :user (match-string 4)
  1906. :comment-num (match-string 5)
  1907. :label-num (match-string 6)
  1908. )))))
  1909. (forward-line 1)
  1910. (goto-char (point-at-bol)))
  1911. bugs)))
  1912. (defun git-bug-ls-noselect (&optional directory)
  1913. "Open git bug list buffer.
  1914. If optional arg DIRECTORY is given change current directory to there before
  1915. initializing."
  1916. (setq directory (expand-file-name (or directory
  1917. default-directory)))
  1918. (cl-assert (file-directory-p directory))
  1919. (let* ((root (git-bug--get-repository-root directory))
  1920. (name (file-name-nondirectory root))
  1921. (bname (format "*GitBug<%s>*" name)))
  1922. (with-current-buffer (get-buffer-create bname)
  1923. (cd root)
  1924. (git-bug-ls--set-tabulated-list-mode-variables)
  1925. (git-bug-ls-mode)
  1926. (current-buffer))))
  1927. (defun git-bug--get-repository-root (dir)
  1928. "Resolve repository root of DIR.
  1929. If DIR is not inside of any git repository, signal an error."
  1930. (cl-assert (file-directory-p dir))
  1931. (with-temp-buffer
  1932. (cd dir)
  1933. (git-bug--call-process "rev-parse" "--show-toplevel")
  1934. (goto-char (point-min))
  1935. (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
  1936. (defun git-bug--call-process (&rest args)
  1937. "Start git process synchronously with ARGS.
  1938. Raise error when git process ends with non-zero status.
  1939. Any output will be written to current buffer."
  1940. (let ((status (apply 'call-process
  1941. "git"
  1942. nil
  1943. t
  1944. nil
  1945. args)))
  1946. (cl-assert (eq status 0)
  1947. nil
  1948. (buffer-substring-no-properties (point-min) (point-max)))))
  1949. ;;;;;;;;;;;;;;;;;;;
  1950. ;; peek-file-mode
  1951. (defun peek-file (file)
  1952. "Peek FILE."
  1953. (interactive)
  1954. (message "%s" file))
  1955. ;;;;;;;;;;;;;;;;;;;;
  1956. ;; remember-projectile
  1957. ;; TODO: Add global-minor-mode
  1958. (defvar remember-data-file)
  1959. (defun my-set-remember-data-file-buffer-local ()
  1960. "Set `remember-data-file'."
  1961. (when (require 'projectile nil t)
  1962. (setq-local remember-data-file
  1963. (expand-file-name ".remember.notes"
  1964. (projectile-project-root)))))
  1965. (add-hook 'after-change-major-mode-hook
  1966. 'my-set-remember-data-file-buffer-local)
  1967. ;;;;;;;;;;;;;;;;;;;;;;;
  1968. ;; flycheck-pydocstyle
  1969. (require 'flycheck nil t)
  1970. ;; TODO: Use `source' and config file
  1971. (flycheck-define-checker python-pydocstyle
  1972. "Docstring style checker."
  1973. :command ("python" "-m" "pydocstyle"
  1974. source-inplace)
  1975. :error-patterns
  1976. (
  1977. (error line-start (file-name) ":" line " " (one-or-more not-newline) "\n" (one-or-more blank) (message) line-end)
  1978. )
  1979. :enabled (lambda ()
  1980. (or (not (flycheck-python-needs-module-p 'python-pydocstyle))
  1981. (flycheck-python-find-module 'python-black-check "pydocstyle")))
  1982. :verify (lambda (_) (flycheck-python-verify-module 'python-black-check "pydocstyle"))
  1983. :modes python-mode)
  1984. (defun flycheck-pydocstyle-setup ()
  1985. "Setup Flycheck pydocstyle."
  1986. (interactive)
  1987. (add-to-list 'flycheck-checkers
  1988. 'python-pydocstyle))
  1989. (flycheck-pydocstyle-setup)
  1990. ;; Local Variables:
  1991. ;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
  1992. ;; flycheck-checker: emacs-lisp
  1993. ;; End:
  1994. ;;; emancs.el ends here