|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016 |
- ;;; emacs.el --- 10sr emacs initialization
-
- ;;; Code:
-
- ;; SETUP_LOAD: (load "bytecomp") ;; Required for WSL environment
- ;; SETUP_LOAD: (let ((file "DOTFILES_DIR/emacs.el"))
- ;; SETUP_LOAD: (and (file-readable-p file)
- ;; SETUP_LOAD: (byte-recompile-file file nil 0 t)))
-
- ;; TODO: Use custom-set-variables in place of set-variable
-
- (setq debug-on-error t)
-
- ;; make directories
- (unless (file-directory-p (expand-file-name user-emacs-directory))
- (make-directory (expand-file-name user-emacs-directory)))
-
- (require 'cl-lib)
- (require 'simple)
-
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; Some macros for internals
-
- (defvar after-first-visit-hook nil
- "Run only once at the first visit of file.")
-
- (defvar after-first-visit-hook--done nil
- "Non-nil when `after-first-visit-hook' has already been called.")
-
- (defun after-first-visit-hook-run ()
- "Run `after-first-visit-hook' and clear its config."
- (when (not after-first-visit-hook--done)
- (run-hooks 'after-first-visit-hook))
- (setq after-first-visit-hook--done t)
- (remove-hook 'find-file-hook
- 'after-first-visit-hook-run))
- (add-hook 'find-file-hook
- 'after-first-visit-hook-run)
-
- (defmacro eval-after-init (&rest body)
- "If `after-init-hook' has been run, run BODY immediately.
- Otherwize hook it."
- (declare (indent 0) (debug t))
- `(if after-init-time
- ;; Currently after-init-hook is run just after setting after-init-hook
- (progn
- ,@body)
- (add-hook 'after-init-hook
- (lambda ()
- ,@body))))
-
- ;; (defmacro safe-require-or-eval (feature)
- ;; "Require FEATURE if available.
-
- ;; At compile time the feature will be loaded immediately."
- ;; `(eval-and-compile
- ;; (message "safe-require-or-eval: Trying to require %s" ,feature)
- ;; (require ,feature nil t)))
-
- ;; (defmacro autoload-eval-lazily (feature &optional functions &rest body)
- ;; "Define autoloading FEATURE that defines FUNCTIONS.
- ;; FEATURE is a symbol. FUNCTIONS is a list of symbols. If FUNCTIONS is nil,
- ;; the function same as FEATURE is defined as autoloaded function. BODY is passed
- ;; to `eval-after-load'.
- ;; After this macro is expanded, this returns the path to library if FEATURE
- ;; found, otherwise returns nil."
- ;; (declare (indent 2) (debug t))
- ;; (let* ((libname (symbol-name (eval feature)))
- ;; (libpath (locate-library libname)))
- ;; `(progn
- ;; (when (locate-library ,libname)
- ;; ,@(mapcar (lambda (f)
- ;; `(unless (fboundp ',f)
- ;; (progn
- ;; (message "Autoloaded function `%S' defined (%s)"
- ;; (quote ,f)
- ;; ,libpath)
- ;; (autoload (quote ,f)
- ;; ,libname
- ;; ,(concat "Autoloaded function defined in \""
- ;; libpath
- ;; "\".")
- ;; t))))
- ;; (or (eval functions)
- ;; `(,(eval feature)))))
- ;; (eval-after-load ,feature
- ;; (quote (progn
- ;; ,@body)))
- ;; (locate-library ,libname))))
-
- ;; (when (autoload-eval-lazily 'tetris nil
- ;; (message "Tetris loaded!"))
- ;; (message "Tetris found!"))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; package
-
- (set (defvar 10sr-package-list)
- '(
- vimrc-mode
- markdown-mode
- yaml-mode
- gnuplot-mode
- php-mode
- erlang
- js2-mode
- js-doc
- git-commit
- gitignore-mode
- adoc-mode
- go-mode
- ;; It seems malabar has been merged into jdee and this package
- ;; already removed
- ;; malabar-mode
- gosh-mode
- scala-mode
- web-mode
- toml-mode
- json-mode
-
-
- color-moccur
- ggtags
- flycheck
- auto-highlight-symbol
- hl-todo
- ;; Currently not available
- ;; pp-c-l
- xclip
- foreign-regexp
- multi-term
- term-run
- editorconfig
- git-ps1-mode
- restart-emacs
- fill-column-indicator
- pkgbuild-mode
- minibuffer-line
- which-key
- ;; I think this works in place of my autosave lib
- super-save
- pipenv
- imenu-list
- page-break-lines
- aggressive-indent
- dired-filter
- wgrep
- magit
- git-gutter
- end-mark
- sl
- ;; TODO: Configure pony-tpl-mode
- pony-mode
- gited
- highlight-indentation
- diminish
- fzf
- fic-mode
- term-cursor
- pydoc
- swoop
- color-identifiers-mode
- dired-k
- blacken
- back-button
- with-venv
- nyan-mode
-
- editorconfig
- editorconfig-custom-majormode
-
- git-command
-
- prompt-text
-
- ;; 10sr repository
- ;; 10sr-extras
- terminal-title
- dired-list-all-mode
- pack
- set-modeline-color
- read-only-only-mode
- smart-revert
- autosave
- ;;window-organizer
- ilookup
- pasteboard
- awk-preview
- recently
-
- ))
-
- (require 'package)
- (set-variable 'package-archives
- `(,@package-archives
- ("melpa" . "https://melpa.org/packages/")
- ;; Somehow fails to download via https
- ("10sr-el" . "http://10sr.github.io/emacs-lisp/elpa/")))
- (package-initialize)
-
- (defun my-auto-install-package ()
- "Install packages semi-automatically."
- (interactive)
- (package-refresh-contents)
- (mapc (lambda (pkg)
- (or (package-installed-p pkg)
- (package-install pkg)))
- 10sr-package-list))
-
- ;; (lazy-load-eval 'sudoku)
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; my-idle-hook
-
- (defvar my-idle-hook nil
- "Hook run when idle for several secs.")
- (defvar my-idle-hook-sec 5
- "Second to run `my-idle-hook'.")
- (run-with-idle-timer my-idle-hook-sec
- t
- (lambda ()
- (run-hooks 'my-idle-hook)))
-
- ;; (add-hook 'my-idle-hook
- ;; (lambda ()
- ;; (message "idle hook message")))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; start and quit
-
- (setq inhibit-startup-message t)
- (setq initial-buffer-choice 'messages-buffer)
- (setq confirm-kill-emacs 'y-or-n-p)
- (setq gc-cons-threshold (* 1024 1024 16))
- (setq garbage-collection-messages nil)
-
- (when window-system
- (add-to-list 'default-frame-alist '(cursor-type . box))
- (add-to-list 'default-frame-alist '(background-color . "white"))
- (add-to-list 'default-frame-alist '(foreground-color . "gray10"))
- ;; (add-to-list 'default-frame-alist '(alpha . (80 100 100 100)))
- ;; does not work?
- )
- ;; (add-to-list 'default-frame-alist '(cursor-type . box))
- (menu-bar-mode 1)
- (define-key ctl-x-map "M" 'menu-bar-open)
- (defalias 'menu 'menu-bar-open)
- (and (fboundp 'tool-bar-mode)
- (tool-bar-mode 0))
- (and (fboundp 'set-scroll-bar-mode)
- (set-scroll-bar-mode nil))
-
- (eval-after-init
- (message "%s %s" invocation-name emacs-version)
- (message "Invocation directory: %s" default-directory)
- (message "%s was taken to initialize emacs." (emacs-init-time))
- ;; (view-echo-area-messages)
- ;; (view-emacs-news)
- )
-
- (with-current-buffer "*Messages*"
- (emacs-lock-mode 'kill))
-
- (cd ".") ; when using windows use / instead of \ in `default-directory'
-
- ;; locale
- (set-language-environment "Japanese")
- (set-default-coding-systems 'utf-8-unix)
- (prefer-coding-system 'utf-8-unix)
- (setq system-time-locale "C")
-
- ;; my prefix map
- (defvar my-prefix-map nil
- "My prefix map.")
- (define-prefix-command 'my-prefix-map)
- (global-set-key (kbd "C-^") 'my-prefix-map)
- ;; (define-key my-prefix-map (kbd "C-q") 'quoted-insert)
- ;; (define-key my-prefix-map (kbd "C-z") 'suspend-frame)
-
- ;; (comint-show-maximum-output)
-
- ;; kill scratch
- (eval-after-init
- (let ((buf (get-buffer "*scratch*")))
- (when buf
- (kill-buffer buf))))
-
- ;; modifier keys
- ;; (setq mac-option-modifier 'control)
-
- ;; display
- (setq visible-bell t)
- (setq ring-bell-function 'ignore)
- (mouse-avoidance-mode 'banish)
- (setq echo-keystrokes 0.1)
-
- (defun reload-init-file ()
- "Reload Emacs init file."
- (interactive)
- (when (and user-init-file
- (file-readable-p user-init-file))
- (load-file user-init-file)))
-
- (require 'session nil t)
-
- ;; server
-
- (set-variable 'server-name (concat "server"
- (number-to-string (emacs-pid))))
-
- ;; In Cygwin Environment `server-runnning-p' stops when server-use-tcp is nil
- ;; In Darwin environment, init fails with message like 'Service name too long'
- ;; when server-use-tcp is nil
- (when (or (eq system-type
- 'cygwin)
- (eq system-type
- 'darwin))
- (set-variable 'server-use-tcp t))
-
- ;; MSYS2 fix
-
- (when (eq system-type
- 'windows-nt)
- (setq shell-file-name
- (executable-find "bash"))
- '(setq function-key-map
- `(,@function-key-map ([pause] . [?\C-c])
- ))
- (define-key key-translation-map
- (kbd "<pause>")
- (kbd "C-c"))
- '(keyboard-translate [pause]
- (kbd "C-c")p)
- ;; TODO: move to other place later
- (when (not window-system)
- (setq interprogram-paste-function nil)
- (setq interprogram-cut-function nil)))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; global keys
-
- (global-set-key (kbd "<up>") 'scroll-down-line)
- (global-set-key (kbd "<down>") 'scroll-up-line)
- (global-set-key (kbd "<left>") 'scroll-down)
- (global-set-key (kbd "<right>") 'scroll-up)
-
- ;; (define-key my-prefix-map (kbd "C-h") help-map)
- ;; (global-set-key (kbd "C-\\") help-map)
-
- (define-key ctl-x-map (kbd "DEL") help-map)
- (define-key ctl-x-map (kbd "C-h") help-map)
- ;; This is often fired mistakenly
- (define-key ctl-x-map "h" 'ignore) ;; Previously mark-whole-buffer
- (define-key help-map "a" 'apropos)
-
- ;; disable annoying keys
- (global-set-key [prior] 'ignore)
- (global-set-key (kbd "<next>") 'ignore)
- (global-set-key [menu] 'ignore)
- (global-set-key [down-mouse-1] 'ignore)
- (global-set-key [down-mouse-2] 'ignore)
- (global-set-key [down-mouse-3] 'ignore)
- (global-set-key [mouse-1] 'ignore)
- (global-set-key [mouse-2] 'ignore)
- (global-set-key [mouse-3] 'ignore)
- (global-set-key (kbd "<eisu-toggle>") 'ignore)
- (global-set-key (kbd "C-<eisu-toggle>") 'ignore)
-
- ;; Interactively evaluate Emacs Lisp expressions
- (define-key ctl-x-map "i" 'ielm)
-
- (when (fboundp 'which-key-mode)
- (which-key-mode))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; editor
-
- ;; Basically it should not set globally (instead use something like file local
- ;; variables or editorconfig), but for most cases I just need this...
- (defun my-set-require-final-newline ()
- "Set `require-final-newline'."
- (set (make-local-variable 'require-final-newline)
- mode-require-final-newline))
-
- (add-hook 'prog-mode-hook
- 'my-set-require-final-newline)
- (add-hook 'text-mode-hook
- 'my-set-require-final-newline)
- (add-hook 'conf-mode-hook
- 'my-set-require-final-newline)
-
- ;; Used from term-cursor
- ;; hbar is too hard to find...
- (defun my-cursor-type-change (&rest args)
- "ARGS are discarded."
- ;; TODO: Support wdired and wgrep
- (if buffer-read-only
- (setq cursor-type 'hbar)
- (setq cursor-type 'box)))
- ;; (add-hook 'switch-buffer-functions
- ;; 'my-cursor-type-change)
- ;; (add-hook 'read-only-mode-hook
- ;; 'my-cursor-type-change)
- ;; (when (fboundp 'global-term-cursor-mode)
- ;; (global-term-cursor-mode 1))
- ;; ;; (term-cursor--eval)
-
-
- (setq kill-whole-line t)
- (setq scroll-conservatively 35
- scroll-margin 2)
- (setq-default major-mode 'text-mode)
- (setq next-line-add-newlines nil)
- (setq kill-read-only-ok t)
- (setq truncate-partial-width-windows nil) ; when splitted horizontally
- ;; (setq-default line-spacing 0.2)
- (setq-default indicate-empty-lines t) ; when using x indicate empty line
- ;; (setq-default tab-width 4)
- (setq-default indent-tabs-mode nil)
- (setq-default indent-line-function 'indent-to-left-margin)
- ;; (setq-default indent-line-function nil)
- (setq-default truncate-lines nil)
- ;; (pc-selection-mode 1) ; make some already defined keybind back to default
- (delete-selection-mode 1)
- (cua-mode 0)
- (setq line-move-visual nil)
- (setq create-lockfiles nil)
- (setq set-mark-command-repeat-pop t)
-
- (add-hook 'before-save-hook
- 'time-stamp)
- ;; Add Time-stamp: <> to insert timestamp there
- (set-variable 'time-stamp-format
- "%:y-%02m-%02d %02H:%02M:%02S %Z 10sr")
-
- ;; key bindings
- ;; moving around
- ;;(keyboard-translate ?\M-j ?\C-j)
- ;; (global-set-key (kbd "M-p") 'backward-paragraph)
- (define-key esc-map "p" 'backward-paragraph)
- ;; (global-set-key (kbd "M-n") 'forward-paragraph)
- (define-key esc-map "n" 'forward-paragraph)
- (global-set-key (kbd "C-<up>") 'scroll-down-line)
- (global-set-key (kbd "C-<down>") 'scroll-up-line)
- (global-set-key (kbd "C-<left>") 'scroll-down)
- (global-set-key (kbd "C-<right>") 'scroll-up)
- (global-set-key (kbd "<select>") 'ignore) ; 'previous-line-mark)
- (define-key ctl-x-map (kbd "ESC x") 'execute-extended-command)
- (define-key ctl-x-map (kbd "ESC :") 'eval-expression)
-
- ;; C-h and DEL
- (global-set-key (kbd "C-h") (kbd "DEL"))
- ;; (normal-erase-is-backspace-mode 1)
-
- ;;(global-set-key (kbd "C-m") 'reindent-then-newline-and-indent)
- (global-set-key (kbd "C-m") 'newline-and-indent)
- ;; (global-set-key (kbd "C-o") (kbd "C-e C-m"))
-
- ;; (global-set-key "\C-z" 'undo) ; undo is M-u
- (define-key esc-map "u" 'undo)
- (define-key esc-map "i" (kbd "ESC TAB"))
- ;; (global-set-key (kbd "C-r") 'query-replace-regexp)
-
- ;; (global-set-key (kbd "C-s") 'isearch-forward-regexp)
- ;; (global-set-key (kbd "C-r") 'isearch-backward-regexp)
- (set-variable 'search-default-mode t)
- ;; TODO: Do not depend on ivy function
- ;; (set-variable 'search-default-mode
- ;; (lambda (str lax)
- ;; (ivy--regex-fuzzy (replace-regexp-in-string (rx (one-or-more whitespace))
- ;; ""
- ;; str))))
-
- (when (fboundp 'undo-fu-only-undo)
- (global-set-key (kbd "C-_") 'undo-fu-only-undo))
- (when (fboundp 'undo-fu-only-redo)
- (global-set-key (kbd "C-M-_") 'undo-fu-only-redo))
-
- (require 'page-ext nil t)
-
- (when (fboundp 'global-page-break-lines-mode)
- (add-hook 'after-first-visit-hook
- 'global-page-break-lines-mode))
- (with-eval-after-load 'page-break-lines
- (set-face-foreground 'page-break-lines
- "cyan")
- )
- (defun my-insert-page-break ()
- "Insert ^L."
- (interactive)
- (insert "\^L\n"))
-
-
- (when (fboundp 'global-git-gutter-mode)
- (add-hook 'after-first-visit-hook
- 'global-git-gutter-mode))
- (with-eval-after-load 'git-gutter
- (declare-function global-git-gutter-mode "git-gutter")
- (custom-set-variables
- '(git-gutter:lighter " Gttr"))
- (custom-set-variables
- '(git-gutter:update-interval 2))
- (custom-set-variables
- '(git-gutter:unchanged-sign " "))
- (when (>= (display-color-cells)
- 256)
- (let ((c "color-233"))
- (set-face-background 'git-gutter:modified c)
- (set-face-background 'git-gutter:added c)
- (set-face-background 'git-gutter:deleted c)
- (set-face-background 'git-gutter:unchanged c))))
-
- ;; (when (fboundp 'fancy-narrow-mode)
- ;; (add-hook 'after-first-visit-hook
- ;; 'fancy-narrow-mode))
-
- ;; https://solist.work/blog/posts/mark-ring/
- (defun my-exchange-point-and-mark ()
- "`exchange-point-and-mark' without mark activation."
- (interactive)
- (exchange-point-and-mark)
- (deactivate-mark))
- (define-key ctl-x-map (kbd "C-x") 'my-exchange-point-and-mark)
- (when (fboundp 'counsel-mark-ring)
- (define-key ctl-x-map "m" 'counsel-mark-ring))
- (with-eval-after-load 'ivy
- (defvar ivy-sort-functions-alist)
- (add-to-list 'ivy-sort-functions-alist
- '(counsel-mark-ring)))
- (run-with-idle-timer 10 t
- (lambda ()
- (push-mark)
- ;; (when (fboundp 'visible-mark-move-overlays)
- ;; (visible-mark-move-overlays))
- ))
-
- (when (fboundp 'back-button-mode)
- (back-button-mode 1))
- (when (fboundp 'back-button-local-forward)
- (global-set-key (kbd "<right>") 'back-button-local-forward))
- (when (fboundp 'back-button-local-backward)
- (global-set-key (kbd "<left>") 'back-button-local-backward))
-
- (when (fboundp 'global-visible-mark-mode)
- (set-variable 'visible-mark-max 2)
- ;; (set-variable 'visible-mark-faces '(visible-mark-face1 visible-mark-face2))
-
- ;; http://emacs.rubikitch.com/visible-mark/
- ;; transient-mark-modeでC-SPC C-SPC、あるいはC-SPC C-gすると消えるバグ修正
- (defun visible-mark-move-overlays--avoid-disappear (&rest them)
- "Fix.
-
- THEM are function and its args."
- (let ((mark-active t)) (apply them)))
- (advice-add 'visible-mark-move-overlays
- :around
- 'visible-mark-move-overlays--avoid-disappear)
-
- ;; (global-visible-mark-mode 1)
- )
-
- ;; visible-mark-mode
- ;; visible-mark-overlays
- ;; mark-ring
- ;; (equal mark-ring (cl-copy-list mark-ring))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; title and mode-line
-
- (when (fboundp 'terminal-title-mode)
- ;; if TERM is not screen use default value
- (if (getenv "TMUX")
- ;; if use tmux locally just basename of current dir
- (set-variable 'terminal-title-format
- '((file-name-nondirectory (directory-file-name
- default-directory))))
- (if (and (let ((tty-type (frame-parameter nil
- 'tty-type)))
- (and tty-type
- (equal (car (split-string tty-type
- "-"))
- "screen")))
- (not (getenv "SSH_CONNECTION")))
- (set-variable 'terminal-title-format
- '((file-name-nondirectory (directory-file-name
- default-directory))))
- ;; seems that TMUX is used locally and ssh to remote host
- (set-variable 'terminal-title-format
- `("em:"
- ,user-login-name
- "@"
- ,(car (split-string (system-name)
- "\\."))
- ":"
- default-directory))
- )
- )
- (terminal-title-mode))
-
- (setq eol-mnemonic-dos "\\r\\n")
- (setq eol-mnemonic-mac "\\r")
- (setq eol-mnemonic-unix "")
-
- (which-function-mode 1)
-
- (line-number-mode 0)
- (column-number-mode 0)
- (size-indication-mode 0)
- (setq mode-line-position
- '(:eval (format ":%%l:%%c /%d%s"
- (count-lines (point-max)
- (point-min))
- (if (buffer-narrowed-p)
- "[N]"
- "")
- )))
-
- (when (fboundp 'diminish)
- (eval-after-init
- (diminish 'recently-mode)
- (diminish 'editorconfig-mode)
- (diminish 'which-key-mode)
- )
- (with-eval-after-load 'whitespace
- (diminish 'global-whitespace-mode))
- (with-eval-after-load 'page-break-lines
- (diminish 'page-break-lines-mode))
- (with-eval-after-load 'auto-highlight-symbol
- (diminish 'auto-highlight-symbol-mode))
- (with-eval-after-load 'color-identifiers-mode
- (diminish 'color-identifiers-mode))
- (with-eval-after-load 'highlight-indentation
- (diminish 'highlight-indentation-mode))
- (with-eval-after-load 'back-button
- (diminish 'back-button-mode))
- (with-eval-after-load 'git-gutter
- (diminish 'git-gutter-mode))
- )
-
- (setq mode-line-front-space "")
- ;; (setq mode-line-end-spaces "")
- ;; Set current frame name to empty string
- (setq-default mode-line-format
- (let* ((l mode-line-format)
- (l (cl-substitute " " " "
- l
- :test 'equal))
- (l (cl-substitute " " " "
- l
- :test 'equal))
- )
- l))
-
- (set-frame-parameter nil 'name "")
-
- ;; See color-name-rgb-alist for available color names
- ;; http://www.raebear.net/computers/emacs-colors/
- ;; https://www.emacswiki.org/emacs/ListColors
- ;; (list-colors-display is not a complete list)
- (defconst my-mode-line-background-default
- (face-background 'mode-line)
- "Default color of mode-line at init.")
- (defun my-mode-line-color-update (&rest args)
- "ARGS are discarded"
- (let ((ro "skyblue")
- (rw my-mode-line-background-default))
- (if (or (not buffer-read-only)
- (and (eq major-mode 'wdired-mode)))
- (set-face-background 'mode-line
- rw)
- (set-face-background 'mode-line
- ro))))
- (add-hook 'switch-buffer-functions
- 'my-mode-line-color-update)
- (add-hook 'read-only-mode-hook
- 'my-mode-line-color-update)
- (add-hook 'wdired-mode-hook
- 'my-mode-line-color-update)
- (advice-add 'wdired-change-to-dired-mode
- :after
- 'my-mode-line-color-update)
- (advice-add 'wgrep-change-to-wgrep-mode
- :after
- 'my-mode-line-color-update)
- (advice-add 'wgrep-to-original-mode
- :after
- 'my-mode-line-color-update)
-
- (set-face-background 'header-line
- my-mode-line-background-default)
-
- ;; http://www.geocities.jp/simizu_daisuke/bunkei-meadow.html#frame-title
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; minibuffer
-
- (setq insert-default-directory t)
- (setq completion-ignore-case t
- read-file-name-completion-ignore-case t
- read-buffer-completion-ignore-case t)
- (setq resize-mini-windows t)
- (temp-buffer-resize-mode 1)
- (savehist-mode 1)
- (defvar display-time-format "%Y/%m/%d %a %H:%M")
-
- (set-variable 'help-at-pt-display-when-idle t)
-
- (fset 'yes-or-no-p 'y-or-n-p)
-
- ;; complete symbol when `eval'
- (define-key read-expression-map (kbd "TAB") 'completion-at-point)
-
- (define-key minibuffer-local-map (kbd "C-u")
- (lambda () (interactive) (delete-region (point-at-bol) (point))))
- ;; I dont know these bindings are good
- (define-key minibuffer-local-map (kbd "C-p") (kbd "ESC p"))
- (define-key minibuffer-local-map (kbd "C-n") (kbd "ESC n"))
-
- (with-eval-after-load 'minibuffer-line
- (set-face-underline 'minibuffer-line nil)
- )
- (when (fboundp 'minibuffer-line-mode)
- (set-variable 'minibuffer-line-refresh-interval
- 25)
-
- ;; Set idle timer
- (defvar my-minibuffer-line--idle-timer nil)
- (defvar minibuffer-line-mode)
- (add-hook 'minibuffer-line-mode-hook
- (lambda ()
- (when my-minibuffer-line--idle-timer
- (cancel-timer my-minibuffer-line--idle-timer)
- (setq my-minibuffer-line--idle-timer nil))
- (when minibuffer-line-mode
- (setq my-minibuffer-line--idle-timer
- (run-with-idle-timer 0.5
- t
- 'minibuffer-line--update)))))
-
-
- (set-variable 'minibuffer-line-format
- `(,(concat user-login-name
- "@"
- (car (split-string (system-name)
- "\\."))
- ":")
- (:eval (abbreviate-file-name (or buffer-file-name
- default-directory)))
- (:eval (and (fboundp 'git-ps1-mode-get-current)
- (git-ps1-mode-get-current " [GIT:%s]")))
- " "
- (:eval (format-time-string display-time-format))))
- (minibuffer-line-mode 1)
- )
-
- (when (fboundp 'prompt-text-mode)
-
- (set-variable 'prompt-text-format
- `(,(concat ""
- user-login-name
- "@"
- (car (split-string (system-name)
- "\\."))
- ":")
- (:eval (abbreviate-file-name (or buffer-file-name
- default-directory)))
- (:eval (and (fboundp 'git-ps1-mode-get-current)
- (git-ps1-mode-get-current " [GIT:%s]")))
- " "
- (:eval (format-time-string display-time-format))
- "\n"
- (:eval (symbol-name this-command))
- ": "))
- (prompt-text-mode 1))
-
- (with-eval-after-load 'helm
- (defvar helm-map)
- (define-key helm-map (kbd "C-h") (kbd "DEL")))
-
- (setq-default header-line-format
- '(:eval (let ((f (or (buffer-file-name)
- default-directory)))
- (when f
- (abbreviate-file-name f)))))
-
- (when (eval-and-compile (require 'nyan-mode nil t))
- (setq-default header-line-format
- '(
- ;; (:eval (file-name-nondirectory(directory-file-name (or buffer-file-name
- ;; default-directory))))
- ;; "["
- (:eval (progn
- (list (nyan-create))))
- ;; "]"
- ;; (:eval (let ((f (or (buffer-file-name)
- ;; default-directory)))
- ;; (when f
- ;; (abbreviate-file-name f))))
- ))
- (add-hook 'window-configuration-change-hook
- (lambda ()
- (set-variable 'nyan-bar-length
- (- (window-size nil t) 4)
- t))))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; letters, font-lock mode and fonts
-
- (when (fboundp 'color-identifiers-mode)
- (add-hook 'prog-mode-hook
- 'color-identifiers-mode))
-
- (setq text-quoting-style 'grave)
-
- ;; (set-face-background 'vertical-border (face-foreground 'mode-line))
-
- ;; (set-window-margins (selected-window) 1 1)
-
- (unless window-system
- (setq frame-background-mode 'dark))
-
- (and (or (eq system-type 'Darwin)
- (eq system-type 'darwin))
- (fboundp 'mac-set-input-method-parameter)
- (mac-set-input-method-parameter 'japanese 'cursor-color "red")
- (mac-set-input-method-parameter 'roman 'cursor-color "black"))
-
- (when (and (boundp 'input-method-activate-hook) ; i dont know this is correct
- (boundp 'input-method-inactivate-hook))
- (add-hook 'input-method-activate-hook
- (lambda () (set-cursor-color "red")))
- (add-hook 'input-method-inactivate-hook
- (lambda () (set-cursor-color "black"))))
-
- (when (fboundp 'show-paren-mode)
- (add-hook 'after-first-visit-hook
- 'show-paren-mode))
- (set-variable 'show-paren-delay 0.5)
- (set-variable 'show-paren-style 'parenthesis) ; mixed is hard to read
- ;; (set-face-background 'show-paren-match
- ;; "black")
- ;; ;; (face-foreground 'default))
- ;; (set-face-foreground 'show-paren-match
- ;; "white")
- ;; (set-face-inverse-video-p 'show-paren-match
- ;; t)
-
- (transient-mark-mode 1)
-
- (global-font-lock-mode 1)
- (setq font-lock-global-modes
- '(not
- help-mode
- eshell-mode
- ;;term-mode
- Man-mode
- ))
-
- ;; (standard-display-ascii ?\n "$\n")
-
- ;; (defvar my-eol-face
- ;; '(("\n" . (0 font-lock-comment-face t nil)))
- ;; )
- ;; (defvar my-tab-face
- ;; '(("\t" . '(0 highlight t nil))))
- (defvar my-jspace-face
- '(("\u3000" . '(0 highlight t nil))))
-
- (add-hook 'font-lock-mode-hook
- (lambda ()
- ;; (font-lock-add-keywords nil my-eol-face)
- (font-lock-add-keywords nil my-jspace-face)
- ))
-
- (when (fboundp 'global-whitespace-mode)
- (add-hook 'after-first-visit-hook
- 'global-whitespace-mode))
- (add-hook 'dired-mode-hook
- ;; Other way to disable in dired buffers?
- (lambda () (set-variable 'whitespace-style nil t)))
-
- (with-eval-after-load 'whitespace
- (defvar whitespace-display-mappings)
- (defvar whitespace-mode)
- (add-to-list 'whitespace-display-mappings
- ;; We need t since last one takes precedence
- `(tab-mark ?\t ,(vconcat "|>\t")) t)
- ;; (add-to-list 'whitespace-display-mappings
- ;; `(newline-mark ?\n ,(vconcat "$\n")))
- (set-variable 'whitespace-style '(face
- trailing ; trailing blanks
- ;; tabs
- ;; spaces
- ;; lines
- lines-tail ; lines over 80
- newline ; newlines
- ;; empty ; empty lines at beg or end of buffer
- ;; big-indent
- ;; space-mark
- tab-mark
- newline-mark ; use display table for newline
- ))
- ;; (setq whitespace-newline 'font-lock-comment-face)
- ;; (setq whitespace-style (delq 'newline-mark whitespace-style))
- (defun my-whitesspace-mode-reload ()
- "Reload whitespace-mode config."
- (interactive)
- (when whitespace-mode
- (whitespace-mode 0)
- (whitespace-mode 1)))
-
- (set-variable 'whitespace-line-column nil)
- (if (>= (display-color-cells)
- 256)
- (set-face-foreground 'whitespace-newline "color-109")
- ;; (progn
- ;; (set-face-bold-p 'whitespace-newline
- ;; t))
- ))
-
- (and nil
- '(require 'fill-column-indicator nil t)
- (setq fill-column-indicator))
-
- (defun my-gen-hl-line-color-dark ()
- "Generate color for current line in black background."
- (let* ((candidates (mapcar 'number-to-string (number-sequence 1 6)))
- (limit (length candidates))
- (r 0) (g 0) (b 0))
- (while (and (<= (abs (- r g)) 1)
- (<= (abs (- g b)) 1)
- (<= (abs (- b r)) 1))
- (setq r (random limit))
- (setq g (random limit))
- (setq b (random limit)))
- (format "#%s%s%s"
- (nth r candidates)
- (nth g candidates)
- (nth b candidates)
- )))
- ;; (my-gen-hl-line-color-dark)
-
- ;; highlight current line
- ;; http://wiki.riywo.com/index.php?Meadow
- (face-spec-set 'hl-line
- `((((min-colors 256)
- (background dark))
- ;; Rotate midnightblue
- (:background ,(my-gen-hl-line-color-dark)))
- (((min-colors 256)
- (background light))
- ;; TODO: What is should be?
- (:background "color-234"))
- (t
- (:underline "black"))))
- (set-variable 'hl-line-global-modes
- '(not
- term-mode))
- (global-hl-line-mode 1) ;; (hl-line-mode 1)
-
- (set-face-foreground 'font-lock-regexp-grouping-backslash "#666")
- (set-face-foreground 'font-lock-regexp-grouping-construct "#f60")
-
- ;;(require 'set-modeline-color nil t)
-
- ;; (let ((fg (face-foreground 'default))
- ;; (bg (face-background 'default)))
- ;; (set-face-background 'mode-line-inactive
- ;; (if (face-inverse-video-p 'mode-line) fg bg))
- ;; (set-face-foreground 'mode-line-inactive
- ;; (if (face-inverse-video-p 'mode-line) bg fg)))
- ;; (set-face-underline 'mode-line-inactive
- ;; t)
- ;; (set-face-underline 'vertical-border
- ;; nil)
-
- ;; (when (require 'end-mark nil t)
- ;; (global-end-mark-mode))
-
- ;; M-x highlight-* to highlight things
- (global-hi-lock-mode 1)
-
- (unless (fboundp 'highlight-region-text)
- (defun highlight-region-text (beg end)
- "Highlight text between BEG and END."
- (interactive "r")
- (highlight-regexp (regexp-quote (buffer-substring-no-properties beg
- end)))
- (setq deactivate-mark t)))
-
- (when (fboundp 'auto-highlight-symbol-mode)
- (add-hook 'prog-mode-hook
- 'auto-highlight-symbol-mode))
- ;; Not work in combination with flyspell-mode
- ;; (when (fboundp 'global-auto-highlight-symbol-mode)
- ;; (add-hook 'after-first-visit-hook
- ;; 'global-auto-highlight-symbol-mode))
- (set-variable 'ahs-idle-interval 0.6)
-
-
- (when (fboundp 'highlight-indentation-mode)
- (dolist (hook
- '(
- prog-mode-hook
- text-mode-hook
- ))
- (add-hook hook
- 'highlight-indentation-mode)))
- (with-eval-after-load 'highlight-indentation
- (set-face-background 'highlight-indentation-face "color-236"))
- ;; (set-face-background 'highlight-indentation-current-column-face "#c3b3b3")
-
- (when (fboundp 'fic-mode)
- (add-hook 'prog-mode-hook
- 'fic-mode))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; file handling
-
- (auto-insert-mode 1)
-
- ;; fzf
-
- ;; Too slow in term buffer!
- ;; (set-variable 'fzf/executable "sk")
- ;; (set-variable 'fzf/args "--color bw --print-query")
- ;; Modified from hardcoded default to include:
- ;; - directories
- ;; - hidden files
- ;; - root directory (.)
- ;; - parent directory (..)
- ;; ripgrep cannot list directories...
- ;; (setenv "FZF_DEFAULT_COMMAND" "rg --files --hidden --follow --glob '!.git/*' --no-ignore")
- (defvar my-fzf-default-command nil
- "My fzf FZF_DEFAULT_COMMAND.")
- (set-variable 'my-fzf-default-command
- (let ((find (or (executable-find "bfs") ;; Breadth-first find https://github.com/tavianator/bfs
- ;; Use gfind if available?
- "find"))
- (fd (or (executable-find "fdfind")
- (executable-find "fd"))))
- (if fd
- (concat "set -eu; set -o pipefail; "
- "echo .; "
- "echo ..; "
- "command " fd " "
- "--follow --hidden --no-ignore "
- "--color always "
- "2>/dev/null")
- (concat "set -eu; set -o pipefail; "
- "echo .; "
- "echo ..; "
- "command " find " -L . "
- "-mindepth 1 "
- "\\( -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune "
- "-o -print "
- "2> /dev/null "
- "| "
- "cut -b3-"))))
- (set-variable 'fzf/window-height 45)
- (set-variable 'fzf/args "--print-query --ansi --color='bg+:-1' --inline-info --cycle")
- ;; (set-variable 'fzf/args "--print-query --ansi --inline-info --cycle")
- ;; (set-variable 'fzf/args "--print-query --ansi --color=bw --inline-info --cycle")
-
- (declare-function fzf "fzf" t)
- (defun my-fzf-or-find-file ()
- "Call fzf if usable or call `find-file'."
- (declare (interactive-only t))
- (interactive)
- (if (and (executable-find "fzf")
- (fboundp 'fzf)
- (not (file-remote-p default-directory)))
- (let ((process-environment (cl-copy-list process-environment)))
- (setenv "FZF_DEFAULT_COMMAND" my-fzf-default-command)
- (fzf))
- (call-interactively 'find-file)))
- (define-key ctl-x-map "f" 'my-fzf-or-find-file)
-
- (defun my-fzf-all-lines ()
- "Fzf all lines."
- (interactive)
- (let ((process-environment (cl-copy-list process-environment)))
- (setenv "FZF_DEFAULT_COMMAND" "rg -nH --no-heading --hidden --follow --glob '!.git/*' --color=always ^")
- (fzf)))
- (define-key ctl-x-map "S" 'my-fzf-all-lines)
-
- ;; recently
-
- ;; TODO: Enable after first visit file?
- (with-eval-after-load 'recently
- (defvar recently-excludes)
- (add-to-list 'recently-excludes
- (rx-to-string (list 'and
- 'string-start
- (expand-file-name package-user-dir))
- t)))
- (when (fboundp 'recently-mode)
- (define-key ctl-x-map (kbd "C-r") 'recently-show)
- (set-variable 'recently-max 1000)
- (recently-mode 1))
-
- (defvar my-cousel-recently-history nil "History of `my-counsel-recently'.")
-
- (declare-function recently-list "recently" t)
- (when (and (require 'recently nil t)
- (fboundp 'ivy-read))
- (defun my-counsel-recently ()
- "Consel `recently'."
- (interactive)
- (ivy-read "Recently: " (mapcar 'abbreviate-file-name (recently-list))
- :require-match t
- :history 'my-cousel-recently-history
- :preselect default-directory
- :action (lambda (x) (find-file x))
- :caller 'my-counsel-recently))
-
- (define-key ctl-x-map (kbd "C-r") 'my-counsel-recently)
- )
-
- (when (fboundp 'editorconfig-mode)
- (add-hook 'after-first-visit-hook
- 'editorconfig-mode))
- (set-variable 'editorconfig-get-properties-function
- 'editorconfig-core-get-properties-hash)
- (set-variable 'editorconfig-mode-lighter "")
- (when (fboundp 'ws-butler-mode)
- (set-variable 'editorconfig-trim-whitespaces-mode
- 'ws-butler-mode))
- (with-eval-after-load 'org-src
- ;; [*.org\[\*Org Src*\[ c \]*\]]
- (add-hook 'org-src-mode-hook
- 'editorconfig-mode-apply t))
-
- (when (fboundp 'editorconfig-custom-majormode)
- (add-hook 'editorconfig-after-apply-functions
- 'editorconfig-custom-majormode))
-
- ;; Add readonly=true to set read-only-mode
- (add-hook 'editorconfig-after-apply-functions
- (lambda (props)
- (let ((r (gethash 'readonly props)))
- (when (and (string= r "true")
- (not buffer-read-only))
- (read-only-mode 1)))))
-
- (add-hook 'editorconfig-hack-properties-functions
- '(lambda (props)
- (when (derived-mode-p 'makefile-mode)
- (puthash 'indent_style "tab" props))
- (when (derived-mode-p 'diff-mode)
- (puthash 'trim_trailing_whitespace "false" props)
- (puthash 'insert_final_newline "false" props)
- )
- ))
-
- (when (fboundp 'editorconfig-auto-apply-enable)
- (add-hook 'editorconfig-conf-mode-hook
- 'editorconfig-auto-apply-enable))
-
-
-
- ;; (when (fboundp 'editorconfig-charset-extras)
- ;; (add-hook 'editorconfig-custom-hooks
- ;; 'editorconfig-charset-extras))
-
- (setq revert-without-query '(".+"))
-
- ;; save cursor position
- (when (fboundp 'save-place-mode)
- (autoload 'save-place-find-file-hook "saveplace")
- (add-hook 'after-first-visit-hook
- 'save-place-mode)
- (add-hook 'after-first-visit-hook
- 'save-place-find-file-hook
- t))
- (set-variable 'save-place-file (concat user-emacs-directory
- "places"))
-
- ;; http://www.bookshelf.jp/soft/meadow_24.html#SEC260
- (setq make-backup-files t)
- (setq vc-make-backup-files t)
- ;; (make-directory (expand-file-name "~/.emacsbackup"))
- (setq backup-directory-alist
- (cons (cons "." (expand-file-name (concat user-emacs-directory
- "backup")))
- backup-directory-alist))
- (setq version-control 't)
- (setq delete-old-versions t)
- (setq kept-new-versions 20)
-
- (setq auto-save-list-file-prefix (expand-file-name (concat user-emacs-directory
- "auto-save/")))
- ;; (setq delete-auto-save-files t)
- (setq auto-save-visited-interval 8)
- (auto-save-visited-mode 1)
-
- ;; (add-to-list 'auto-save-file-name-transforms
- ;; `(".*" ,(concat user-emacs-directory "auto-save-dir") t))
- ;; (setq auto-save-interval 3)
- ;; (auto-save-mode 1)
-
- (add-to-list 'completion-ignored-extensions ".bak")
- (set-variable 'completion-cycle-threshold nil) ;; NEVER use
- (setq delete-by-moving-to-trash t)
- ;; trash-directory "~/.emacs.d/trash")
-
- (add-hook 'after-save-hook
- 'executable-make-buffer-file-executable-if-script-p)
-
-
- (when (fboundp 'smart-revert-on)
- (smart-revert-on))
-
- ;; autosave
- ;; auto-save-visited-mode can be used instead?
- ;; (when (require 'autosave nil t)
- ;; (autosave-set 8))
-
-
- ;; bookmarks
-
- (set-variable 'bookmark-default-file
- (expand-file-name (concat user-emacs-directory
- "bmk")))
- (set-variable 'bookmark-sort-flag nil)
-
- (defun my-bookmark-set ()
- "My `bookmark-set'."
- (interactive)
- (cl-assert (or buffer-file-name
- default-directory))
- (let ((name (file-name-nondirectory (or buffer-file-name
- (directory-file-name default-directory))))
- (linenum (count-lines (point-min)
- (point)))
- (linetext (buffer-substring-no-properties (point-at-bol)
- (point-at-eol))))
- (bookmark-set (format "%s:%d:%s"
- name linenum linetext)
- nil)))
-
- ;; Done by advice instead
- ;; (set-variable 'bookmark-save-flag
- ;; 1)
- (with-eval-after-load 'recentf
- (defvar recentf-exclude)
- (defvar bookmark-default-file)
- (add-to-list 'recentf-exclude
- (regexp-quote bookmark-default-file)))
-
- (defvar bookmark-default-file)
- (defun my-bookmark-set--advice (orig-func &rest args)
- "Function for `bookmark-set-internal'.
-
- ORIG-FUNC is the target function, and ARGS is the argument when it is called."
- (bookmark-load bookmark-default-file)
- (apply orig-func args)
- (bookmark-save))
-
- (with-eval-after-load 'bookmark
- (advice-add 'bookmark-set-internal
- :around
- 'my-bookmark-set--advice))
- (define-key ctl-x-map "b" 'list-bookmarks)
- (when (fboundp 'counsel-bookmark)
- (define-key ctl-x-map "b" 'counsel-bookmark))
- (define-key ctl-x-map "B" 'my-bookmark-set)
-
- ;; vc
-
- (set-variable 'vc-handled-backends '(RCS))
- (set-variable 'vc-rcs-register-switches "-l")
- (set-variable 'vc-rcs-checkin-switches "-l")
- (set-variable 'vc-command-messages t)
-
- (when (fboundp 'neotree)
- (define-key ctl-x-map (kbd "C-n") 'neotree))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; share clipboard with x
-
- ;; this page describes this in details, but only these sexps seem to be needed
- ;; http://garin.jp/doc/Linux/xwindow_clipboard
-
- (and nil
- (not window-system)
- (not (eq window-system 'mac))
- (getenv "DISPLAY")
- (not (equal (getenv "DISPLAY") ""))
- (executable-find "xclip")
- ;; (< emacs-major-version 24)
- '(require 'xclip nil t)
- nil
- (turn-on-xclip))
-
- (and (eq system-type 'darwin)
- (require 'pasteboard nil t)
- (turn-on-pasteboard))
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; some modes and hooks
-
- ;; Include some extra modes
- (require 'generic-x)
-
- ;; Derived from https://github.com/ensime/ensime-emacs/issues/591#issuecomment-291916753
- (defun my-scalafmt ()
- (interactive)
- (cl-assert buffer-file-name)
- (cl-assert (not (buffer-modified-p)))
- (let* ((configdir (locate-dominating-file default-directory ".scalafmt.conf"))
- (configoption (if configdir
- (concat " --config "
- (shell-quote-argument (expand-file-name configdir))
- ".scalafmt.conf"
- )
- ""))
- (str (concat "scalafmt -f "
- (shell-quote-argument buffer-file-name)
- configoption
- " -i --exclude ensime")))
- (message str)
- (shell-command-to-string str))
- (message "scalafmt done")
- (revert-buffer nil t))
-
- (when (fboundp 'web-mode)
- (add-to-list 'auto-mode-alist
- '("\\.html\\.j2\\'" . web-mode))
- (add-to-list 'auto-mode-alist
- ;; Django Template Language
- '("\\.dtl\\'" . web-mode))
- )
-
- (when (locate-library "wgrep")
- (set-variable 'wgrep-auto-save-buffer t)
- (with-eval-after-load 'grep
- (defvar grep-mode-map)
- (define-key grep-mode-map
- "e"
- 'wgrep-change-to-wgrep-mode)))
-
- (when (fboundp 'grep-context-mode)
- (add-hook 'compilation-mode-hook #'grep-context-mode))
-
- (with-eval-after-load 'remember
- (defvar remember-mode-map)
- (define-key remember-mode-map (kbd "C-x C-s") 'ignore))
- (set-variable 'remember-notes-initial-major-mode
- 'change-log-mode)
-
- (with-eval-after-load 'magit-files
- ;; `global-magit-file-mode' is enabled by default and this mode overwrites
- ;; existing keybindings.
- ;; Apparently it is a HARMFUL behavior and it is really awful that I have
- ;; to disable thie mode here, but do anyway.
- ;; See also https://github.com/magit/magit/issues/3517
- (global-magit-file-mode -1))
-
- (with-eval-after-load 'magit-section
- (set-face-background 'magit-section-highlight
- nil))
-
- ;; Sane colors
- (with-eval-after-load 'magit-diff
- (set-face-background 'magit-diff-context nil)
- (set-face-background 'magit-diff-context-highlight nil)
-
- (set-face-foreground 'magit-diff-hunk-heading nil)
- (set-face-background 'magit-diff-hunk-heading nil)
- (set-face-foreground 'magit-diff-hunk-heading-highlight nil)
- (set-face-background 'magit-diff-hunk-heading-highlight nil)
-
- ;; https://blog.shibayu36.org/entry/2016/03/27/220552
- (set-face-foreground 'magit-diff-added "green")
- (set-face-background 'magit-diff-added nil)
- (set-face-foreground 'magit-diff-added-highlight "green")
- (set-face-background 'magit-diff-added-highlight nil)
- (set-face-foreground 'magit-diff-removed "red")
- (set-face-background 'magit-diff-removed nil)
- (set-face-foreground 'magit-diff-removed-highlight "red")
- (set-face-background 'magit-diff-removed-highlight nil)
- (set-face-background 'magit-diff-lines-boundary "blue")
- )
-
- (defun my-magit-messenger (file line)
- "Magit messenger."
- (interactive (list buffer-file-name
- (line-number-at-pos)))
- (cl-assert file)
- (cl-assert line)
- (let* ((blame-args '("-w"))
- (id (with-temp-buffer
- (let ((exit (apply 'call-process
- "git" ;; PROGRAM
- nil ;; INFILE
- t ;; DESTINATION
- nil ;; DISPLAY
- "--no-pager" ;; ARGS
- "blame"
- "-L"
- (format "%d,+1" line)
- "--porcelain"
- file
- blame-args
- )))
- (goto-char (point-min))
- (cl-assert (eq exit 0)
- "Failed: %s" (buffer-substring (point)
- (point-at-eol)))
- (save-match-data
- (re-search-forward (rx buffer-start
- (one-or-more hex-digit)))
- (match-string 0))))))
- (magit-show-commit id)))
-
-
- (when (boundp 'git-rebase-filename-regexp)
- (add-to-list 'auto-mode-alist
- `(,git-rebase-filename-regexp . text-mode)))
-
- (when (fboundp 'global-aggressive-indent-mode)
- (add-hook 'after-first-visit-hook
- 'global-aggressive-indent-mode))
- (with-eval-after-load 'aggressive-indent
- (defvar aggressive-indent-excluded-modes)
- (set-variable 'aggressive-indent-excluded-modes
- `(web-mode
- diff-mode
- toml-mode
- conf-mode
- dockerfile-mode
- groovy-mode
- scala-mode
- ,@aggressive-indent-excluded-modes)))
-
- (when (fboundp 'ggtags-mode)
- (add-hook 'c-mode-common-hook
- 'ggtags-mode)
- (add-hook 'python-mode-hook
- 'ggtags-mode)
- (add-hook 'js-mode-hook
- 'ggtags-mode)
- (add-hook 'scheme-mode-hook
- 'ggtags-mode)
- )
-
- (when (fboundp 'imenu-list-minor-mode)
- (defvar imenu-list-buffer-name)
- (defun my-imenu-list-toggle ()
- "My 'imenu-list` toggle."
- (interactive)
- (require 'imenu-list)
- (if (eq (window-buffer)
- (get-buffer imenu-list-buffer-name))
- (imenu-list-minor-mode -1)
- (imenu-list-minor-mode 1)))
- ;; (set-variable 'imenu-list-auto-resize t)
- (set-variable 'imenu-list-focus-after-activation t)
- (define-key ctl-x-map (kbd "C-l") 'my-imenu-list-toggle))
-
- (add-hook 'emacs-lisp-mode-hook
- (lambda ()
- (setq imenu-generic-expression
- `(("Sections" ";;;\+\n;; \\(.*\\)\n" 1)
- ,@imenu-generic-expression))))
- ;; TODO: Try paraedit http://daregada.blogspot.com/2012/03/paredit.html
-
- (with-eval-after-load 'compile
- (defvar compilation-filter-start)
- (defvar compilation-error-regexp-alist)
- (require 'ansi-color)
- (add-hook 'compilation-filter-hook
- (lambda ()
- (let ((inhibit-read-only t))
- (ansi-color-apply-on-region compilation-filter-start
- (point)))))
- (add-to-list 'compilation-error-regexp-alist
- ;; ansible-lint
- '("^\\([^ \n]+\\):\\([0-9]+\\)$" 1 2))
- (add-to-list 'compilation-error-regexp-alist
- ;; pydocstyle
- '("^\\([^ \n]+\\):\\([0-9]+\\) " 1 2))
- )
-
- (when (fboundp 'global-company-mode)
- (add-hook 'after-first-visit-hook
- 'global-company-mode))
- (with-eval-after-load 'company
- ;; http://qiita.com/sune2/items/b73037f9e85962f5afb7
- ;; https://qiita.com/yuze/items/a145b1e3edb6d0c24cbf
- (set-variable 'company-idle-delay nil)
- (set-variable 'company-minimum-prefix-length 2)
- (set-variable 'company-selection-wrap-around t)
-
- (defvar company-mode-map)
- (define-key company-mode-map (kbd "C-i") 'company-indent-or-complete-common)
- ;; (with-eval-after-load 'python
- ;; (defvar python-indent-trigger-commands)
- ;; ;; TODO: This disables completion in puthon?
- ;; (add-to-list 'python-indent-trigger-commands
- ;; 'company-indent-or-complete-common))
- (define-key ctl-x-map (kbd "C-i") 'company-complete) ; Originally `indent-rigidly'
-
- (defvar company-active-map)
- (define-key company-active-map (kbd "C-n") 'company-select-next)
- (define-key company-active-map (kbd "C-p") 'company-select-previous)
- (define-key company-active-map (kbd "C-s") 'company-filter-candidates)
- (define-key company-active-map (kbd "C-i") 'company-complete-selection)
- (define-key company-active-map (kbd "C-f") 'company-complete-selection)
-
- (defvar company-mode)
- (defvar company-candidates)
- (defvar company-candidates-length)
- ;; (popup-tip "Hello, World!")
- (defun my-company-lighter-current-length ()
- "Get current candidate length."
- (interactive)
- (let ((l nil)
- (inhibit-message t))
- (when (and company-mode
- (not (minibufferp))
- ;; Do nothing when already in company completion
- (not company-candidates))
- ;; FIXME: Somehow it cannto catch errors from ggtags
- (ignore-errors
- ;; (company-auto-begin)
- (company-manual-begin)
- (setq l company-candidates-length)
- (company-cancel)))
- (if l
- (format "[%d]" l)
- "")))
-
- (defvar company-lighter)
- (set-variable 'company-lighter-base "Cmp")
- ;; (add-to-list 'company-lighter
- ;; '(:eval (my-company-lighter-current-length))
- ;; t)
-
- ;; This breaks japanese text input
- ;; (set-variable 'my-company-length-popup-tip-timer
- ;; (run-with-idle-timer 0.2 t
- ;; 'my-company-length-popup-tip))
-
- ;; (current-active-maps)
- ;; (lookup-key)
- '(mapcar (lambda (map)
- (lookup-key map (kbd "C-i")))
- (current-active-maps))
-
- ;; https://qiita.com/syohex/items/8d21d7422f14e9b53b17
- (set-face-attribute 'company-tooltip nil
- :foreground "black" :background "lightgrey")
- (set-face-attribute 'company-tooltip-common nil
- :foreground "black" :background "lightgrey")
- (set-face-attribute 'company-tooltip-common-selection nil
- :foreground "white" :background "steelblue")
- (set-face-attribute 'company-tooltip-selection nil
- :foreground "black" :background "steelblue")
- (set-face-attribute 'company-preview-common nil
- :background nil :foreground "lightgrey" :underline t)
- (set-face-attribute 'company-scrollbar-fg nil
- :background "orange")
- (set-face-attribute 'company-scrollbar-bg nil
- :background "gray40")
-
- )
-
- ;; https://github.com/lunaryorn/flycheck
- ;; TODO: Any way to disable auto check?
- ;; Update flycheck-hooks-alist?
- (when (fboundp 'global-flycheck-mode)
- (add-hook 'after-first-visit-hook
- 'global-flycheck-mode))
- ;; (set-variable 'flycheck-display-errors-delay 2.0)
- ;; (fset 'flycheck-display-error-at-point-soon 'ignore)
-
- ;; (with-eval-after-load 'flycheck
- ;; (when (fboundp 'flycheck-black-check-setup)
- ;; (flycheck-black-check-setup)))
-
- (when (fboundp 'ilookup-open-word)
- (define-key ctl-x-map "d" 'ilookup-open-word))
-
- (set-variable 'ac-ignore-case nil)
-
- (when (fboundp 'term-run-shell-command)
- (define-key ctl-x-map "t" 'term-run-shell-command))
-
- (add-to-list 'safe-local-variable-values
- '(encoding utf-8))
- (setq enable-local-variables :safe)
-
- ;; Detect file type from shebang and set major-mode.
- (add-to-list 'interpreter-mode-alist
- '("python3" . python-mode))
- (add-to-list 'interpreter-mode-alist
- '("python2" . python-mode))
- (with-eval-after-load 'python
- (defvar python-mode-map (make-sparse-keymap))
- (define-key python-mode-map (kbd "C-m") 'newline-and-indent))
- ;; I want to use this, but this breaks normal self-insert-command
- ;; (set-variable 'py-indent-list-style
- ;; 'one-level-to-beginning-of-statement)
- (set-variable 'pydoc-command
- "python3 -m pydoc")
- (with-eval-after-load 'pydoc
- (when (require 'with-venv nil t)
- (with-venv-advice-add 'pydoc)))
-
- (set-variable 'flycheck-python-mypy-ini ".mypy.ini")
- (set-variable 'flycheck-flake8rc "setup.cfg")
-
- (set-variable 'flycheck-python-pylint-executable "python3")
- (set-variable 'flycheck-python-pycompile-executable "python3")
-
- (set-variable 'python-indent-guess-indent-offset nil)
-
- (with-eval-after-load 'blacken
- (when (require 'with-venv nil t)
- (with-venv-advice-add 'blacken-buffer)))
-
- (with-eval-after-load 'ansible-doc
- (when (require 'with-venv nil t)
- (with-venv-advice-add 'ansible-doc)))
-
- ;; `isortify-buffer' breaks buffer when it contains japanese text
- (defun my-isortify ()
- (interactive)
- (cl-assert buffer-file-name)
- (cl-assert (not (buffer-modified-p)))
- (call-process "python" ;; PROGRAM
- nil ;; INFILE
- nil ;; DESTINATION
- nil ;; DISPLAY
- "-m" "isort" buffer-file-name)
- (message "isortify done")
- (revert-buffer nil t))
- (when (fboundp 'with-venv-advice-add)
- ;; TODO: Lazy load with-venv
- (with-venv-advice-add 'my-isortify))
-
- ;; https://github.com/lunaryorn/old-emacs-configuration/blob/master/lisp/flycheck-virtualenv.el
- (defun my-set-venv-flycheck-executable-find ()
- "Set flycheck executabie find."
- (interactive)
- (when (fboundp 'with-venv)
- (set-variable 'flycheck-executable-find
- '(lambda (e)
- (with-venv
- (executable-find e)))
- t)))
-
- (defun my-update-flycheck-flake8-error-level-alist ()
- "Update `flycheck-flake8-error-level-alist'."
- (defvar flycheck-flake8-error-level-alist)
- ;; (add-to-list 'flycheck-flake8-error-level-alist
- ;; '("^D.*$" . warning))
- (set-variable 'flycheck-flake8-error-level-alist
- nil)
- )
-
- (add-hook 'python-mode-hook
- 'my-set-venv-flycheck-executable-find)
- (add-hook 'python-mode-hook
- 'my-update-flycheck-flake8-error-level-alist)
- (when (fboundp 'with-venv-info-mode)
- (add-hook 'python-mode-hook
- 'with-venv-info-mode))
-
- ;; Run multiple chekcers
- ;; https://github.com/flycheck/flycheck/issues/186
-
-
- ;; http://fukuyama.co/foreign-regexp
- '(and (require 'foreign-regexp nil t)
- (progn
- (setq foreign-regexp/regexp-type 'perl)
- '(setq reb-re-syntax 'foreign-regexp)
- ))
-
- (with-eval-after-load 'sql
- (require 'sql-indent nil t))
- (add-to-list 'auto-mode-alist
- '("\\.hql\\'" . sql-mode))
-
- (when (fboundp 'git-command)
- (define-key ctl-x-map "g" 'git-command))
-
- (when (fboundp 'gited-list)
- (defalias 'gited 'gited-list))
-
- (when (fboundp 'global-git-commit-mode)
- (add-hook 'after-first-visit-hook
- 'global-git-commit-mode)
- (add-hook 'after-first-visit-hook
- 'git-commit-setup-check-buffer))
- (with-eval-after-load 'git-commit
- (add-hook 'git-commit-setup-hook
- 'turn-off-auto-fill t))
-
- (with-eval-after-load 'rst
- (defvar rst-mode-map)
- (define-key rst-mode-map (kbd "C-m") 'newline-and-indent))
-
- (with-eval-after-load 'jdee
- (add-hook 'jdee-mode-hook
- (lambda ()
- (make-local-variable 'global-mode-string)
- (add-to-list 'global-mode-string
- mode-line-position))))
-
- ;; Cannot enable error thrown. Why???
- ;; https://github.com/m0smith/malabar-mode#Installation
- ;; (when (require 'malabar-mode nil t)
- ;; (add-to-list 'load-path
- ;; (expand-file-name (concat user-emacs-directory "/cedet")))
- ;; (require 'cedet-devel-load nil t)
- ;; (eval-after-init (activate-malabar-mode)))
-
- (with-eval-after-load 'make-mode
- (defvar makefile-mode-map (make-sparse-keymap))
- (define-key makefile-mode-map (kbd "C-m") 'newline-and-indent)
- ;; this functions is set in write-file-functions, i cannot find any
- ;; good way to remove this.
- (fset 'makefile-warn-suspicious-lines 'ignore))
-
- (with-eval-after-load 'verilog-mode
- (defvar verilog-mode-map (make-sparse-keymap))
- (define-key verilog-mode-map ";" 'self-insert-command))
-
-
- (setq diff-switches "-u")
- (autoload 'diff-goto-source "diff-mode" nil t)
- (with-eval-after-load 'diff-mode
- ;; (when (and (eq major-mode
- ;; 'diff-mode)
- ;; (not buffer-file-name))
- ;; ;; do not pass when major-mode is derived mode of diff-mode
- ;; (view-mode 1))
- (set-face-attribute 'diff-header nil
- :foreground nil
- :background nil
- :weight 'bold)
- (set-face-attribute 'diff-file-header nil
- :foreground nil
- :background nil
- :weight 'bold)
- (set-face-foreground 'diff-index "blue")
- (set-face-attribute 'diff-hunk-header nil
- :foreground "cyan"
- :weight 'normal)
- (set-face-attribute 'diff-context nil
- ;; :foreground "white"
- :foreground nil
- :weight 'normal)
- (set-face-foreground 'diff-removed "red")
- (set-face-foreground 'diff-added "green")
- (set-face-background 'diff-removed nil)
- (set-face-background 'diff-added nil)
- (set-face-attribute 'diff-changed nil
- :foreground "magenta"
- :weight 'normal)
- (set-face-attribute 'diff-refine-changed nil
- :foreground nil
- :background nil
- :weight 'bold
- :inverse-video t)
- ;; Annoying !
- ;;(diff-auto-refine-mode)
- )
-
- ;; (ffap-bindings)
-
- (set-variable 'browse-url-browser-function
- 'eww-browse-url)
-
- (set-variable 'sh-here-document-word "__EOC__")
-
- (with-eval-after-load 'adoc-mode
- (defvar adoc-mode-map)
- (define-key adoc-mode-map (kbd "C-m") 'newline))
- (when (fboundp 'adoc-mode)
- (setq auto-mode-alist
- `(("\\.adoc\\'" . adoc-mode)
- ("\\.asciidoc\\'" . adoc-mode)
- ,@auto-mode-alist)))
-
- (with-eval-after-load 'markup-faces
- ;; Is this too match ?
- (set-face-foreground 'markup-meta-face
- "color-245")
- (set-face-foreground 'markup-meta-hide-face
- "color-245")
- )
-
- ;; TODO: check if this is required
- (with-eval-after-load 'groovy-mode
- (defvar groovy-mode-map)
- (define-key groovy-mode-map "(" 'self-insert-command)
- (define-key groovy-mode-map ")" 'self-insert-command)
- (define-key groovy-mode-map (kbd "C-m") 'newline-and-indent)
- )
- (when (fboundp 'groovy-mode)
- (add-to-list 'auto-mode-alist
- '("build\\.gradle\\'" . groovy-mode)))
-
-
- (add-to-list 'auto-mode-alist
- '("\\.gawk\\'" . awk-mode))
-
- (with-eval-after-load 'yaml-mode
- (defvar yaml-mode-map (make-sparse-keymap))
- (define-key yaml-mode-map (kbd "C-m") 'newline))
-
- (with-eval-after-load 'html-mode
- (defvar html-mode-map (make-sparse-keymap))
- (define-key html-mode-map (kbd "C-m") 'reindent-then-newline-and-indent))
-
- (with-eval-after-load 'text-mode
- (define-key text-mode-map (kbd "C-m") 'newline))
-
- (with-eval-after-load 'info
- (defvar Info-additional-directory-list)
- (dolist (dir (directory-files (concat user-emacs-directory
- "info")
- t
- "^[^.].*"))
- (when (file-directory-p dir)
- (add-to-list 'Info-additional-directory-list
- dir)))
- (let ((dir (expand-file-name "~/.brew/share/info")))
- (when (file-directory-p dir)
- (add-to-list 'Info-additional-directory-list
- dir))))
-
- (with-eval-after-load 'apropos
- (defvar apropos-mode-map (make-sparse-keymap))
- (define-key apropos-mode-map "n" 'next-line)
- (define-key apropos-mode-map "p" 'previous-line))
-
- ;; `isearch' library does not call `provide' so cannot use with-eval-after-load
- ;; (define-key isearch-mode-map
- ;; (kbd "C-j") 'isearch-other-control-char)
- ;; (define-key isearch-mode-map
- ;; (kbd "C-k") 'isearch-other-control-char)
- ;; (define-key isearch-mode-map
- ;; (kbd "C-h") 'isearch-other-control-char)
- (define-key isearch-mode-map (kbd "C-h") 'isearch-del-char)
- (define-key isearch-mode-map (kbd "M-r")
- 'isearch-query-replace-regexp)
- ;; do not cleanup isearch highlight: use `lazy-highlight-cleanup' to remove
- (setq lazy-highlight-cleanup nil)
- ;; face for isearch highlighing
- (set-face-attribute 'lazy-highlight
- nil
- :foreground `unspecified
- :background `unspecified
- :underline t
- ;; :weight `bold
- )
-
- (add-hook 'outline-mode-hook
- (lambda ()
- (when (string-match "\\.md\\'" buffer-file-name)
- (setq-local outline-regexp "#+ "))))
- (add-hook 'outline-mode-hook
- 'outline-show-all)
-
- (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'outline-mode))
- (with-eval-after-load 'markdown-mode
- (defvar gfm-mode-map)
- (define-key gfm-mode-map (kbd "C-m") 'electric-indent-just-newline)
- (define-key gfm-mode-map "`" nil) ;; markdown-electric-backquote
- )
- (when (fboundp 'gfm-mode)
- (add-to-list 'auto-mode-alist (cons "\\.md\\'" 'gfm-mode))
- (add-hook 'markdown-mode-hook
- 'outline-minor-mode)
- (add-hook 'markdown-mode-hook
- (lambda ()
- (setq-local comment-start ";")))
- )
-
- ;; http://keisanbutsuriya.hateblo.jp/entry/2015/02/10/152543
- ;; M-$ to ispell word
- ;; M-x flyspell-buffer to highlight all suspicious words
- (when (executable-find "aspell")
- (set-variable 'ispell-program-name "aspell")
- (set-variable 'ispell-extra-args '("--lang=en_US")))
- (with-eval-after-load 'ispell
- (add-to-list 'ispell-skip-region-alist '("[^\000-\377]+")))
-
- (when (fboundp 'flyspell-mode)
- (add-hook 'text-mode-hook
- 'flyspell-mode))
- (when (fboundp 'flyspell-prog-mode)
- (add-hook 'prog-mode-hook
- 'flyspell-prog-mode))
-
- ;; c-mode
- ;; http://www.emacswiki.org/emacs/IndentingC
- ;; http://en.wikipedia.org/wiki/Indent_style
- ;; http://d.hatena.ne.jp/emergent/20070203/1170512717
- ;; http://seesaawiki.jp/whiteflare503/d/Emacs%20%a5%a4%a5%f3%a5%c7%a5%f3%a5%c8
- (with-eval-after-load 'cc-vars
- (defvar c-default-style nil)
- (add-to-list 'c-default-style
- '(c-mode . "k&r"))
- (add-to-list 'c-default-style
- '(c++-mode . "k&r")))
-
- (with-eval-after-load 'js2-mode
- ;; currently do not use js2-mode
- ;; (add-to-list 'auto-mode-alist '("\\.js\\'" . js2-mode))
- ;; (add-to-list 'auto-mode-alist '("\\.jsm\\'" . js2-mode))
- ;; (defvar js2-mode-map (make-sparse-keymap))
- ;; (define-key js2-mode-map (kbd "C-m") (lambda ()
- ;; (interactive)
- ;; (js2-enter-key)
- ;; (indent-for-tab-command)))
- ;; (add-hook (kill-local-variable 'before-save-hook)
- ;; 'js2-before-save)
- ;; (add-hook 'before-save-hook
- ;; 'my-indent-buffer
- ;; nil
- ;; t)
- )
-
- (add-to-list 'interpreter-mode-alist
- '("node" . js-mode))
-
- (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
-
- (with-eval-after-load 'uniquify
- (setq uniquify-buffer-name-style 'post-forward-angle-brackets)
- (setq uniquify-ignore-buffers-re "*[^*]+*")
- (setq uniquify-min-dir-content 1))
-
- (with-eval-after-load 'view
- (defvar view-mode-map (make-sparse-keymap))
- (define-key view-mode-map "j" 'scroll-up-line)
- (define-key view-mode-map "k" 'scroll-down-line)
- (define-key view-mode-map "v" 'toggle-read-only)
- (define-key view-mode-map "q" 'bury-buffer)
- ;; (define-key view-mode-map "/" 'nonincremental-re-search-forward)
- ;; (define-key view-mode-map "?" 'nonincremental-re-search-backward)
- ;; (define-key view-mode-map
- ;; "n" 'nonincremental-repeat-search-forward)
- ;; (define-key view-mode-map
- ;; "N" 'nonincremental-repeat-search-backward)
-
- ;; N conflicts with git-walktree
- ;; (define-key view-mode-map "/" 'isearch-forward-regexp)
- ;; (define-key view-mode-map "?" 'isearch-backward-regexp)
- ;; (define-key view-mode-map "n" 'isearch-repeat-forward)
- ;; (define-key view-mode-map "N" 'isearch-repeat-backward)
-
- (define-key view-mode-map (kbd "C-m") 'my-rgrep-symbol-at-point))
- (global-set-key "\M-r" 'view-mode)
- ;; (setq view-read-only t)
-
- (with-eval-after-load 'term
- (defvar term-raw-map (make-sparse-keymap))
- (define-key term-raw-map (kbd "C-x")
- (lookup-key (current-global-map)
- (kbd "C-x"))))
- (add-hook 'term-mode-hook
- (lambda ()
- ;; Stop current line highlighting
- (set-variable 'hl-line-range-function (lambda () '(0 . 0)) t)
- (set-variable 'scroll-margin 0 t)
- ))
- (set-variable 'term-buffer-maximum-size 20480)
- (set-variable 'term-suppress-hard-newline t)
-
- (add-hook 'Man-mode-hook
- (lambda ()
- (view-mode 1)
- (setq truncate-lines nil)))
- (set-variable 'Man-notify-method (if window-system
- 'newframe
- 'aggressive))
-
- (set-variable 'woman-cache-filename (expand-file-name (concat user-emacs-directory
- "woman_cache.el")))
- ;; not work because man.el will be loaded when man called
- (defalias 'man 'woman)
-
- (add-to-list 'auto-mode-alist
- '("tox\\.ini\\'" . conf-unix-mode))
-
- (when (fboundp 'toml-mode)
- (add-to-list 'auto-mode-alist
- '("/tox\\.ini\\'" . toml-mode))
- (add-to-list 'auto-mode-alist
- '("/Pipfile\\'" . toml-mode))
- (add-to-list 'auto-mode-alist
- '("/poetry\\.lock\\'" . toml-mode))
- )
-
- (when (fboundp 'json-mode)
- (add-to-list 'auto-mode-alist
- '("/Pipfile\\.lock\\'" . json-mode)))
-
- (add-hook 'go-mode-hook
- (lambda()
- (defvar go-mode-map)
- (add-hook 'before-save-hook' 'gofmt-before-save nil t)
- (define-key go-mode-map (kbd "M-.") 'godef-jump)))
-
- (when (fboundp 'k8s-mode)
- (add-to-list 'auto-mode-alist
- '("\\.k8s\\'" . k8s-mode)))
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; buffers
-
- (defvar bs-configurations)
- (declare-function bs-set-configuration "bs")
- (declare-function bs-refresh "bs")
- (declare-function bs-message-without-log "bs")
- (declare-function bs--current-config-message "bs")
- (with-eval-after-load 'bs
- (add-to-list 'bs-configurations
- '("specials" "^\\*" nil ".*" nil nil))
- (add-to-list 'bs-configurations
- '("files-and-specials" "^\\*" buffer-file-name ".*" nil nil))
- (defvar bs-mode-map)
- (defvar bs-current-configuration)
- (define-key bs-mode-map (kbd "t")
- ;; TODO: fix toggle feature
- (lambda ()
- (interactive)
- (if (string= "specials"
- bs-current-configuration)
- (bs-set-configuration "files")
- (bs-set-configuration "specials"))
- (bs-refresh)
- (bs-message-without-log "%s"
- (bs--current-config-message))))
- ;; (setq bs-configurations (list
- ;; '("processes" nil get-buffer-process ".*" nil nil)
- ;; '("files-and-scratch" "^\\*scratch\\*$" nil nil
- ;; bs-visits-non-file bs-sort-buffer-interns-are-last)))
- )
- (when (fboundp 'bs-show)
- (defalias 'list-buffers 'bs-show)
- (set-variable 'bs-default-configuration "files-and-specials")
- (set-variable 'bs-default-sort-name "by nothing")
- (add-hook 'bs-mode-hook
- (lambda ()
- (set (make-local-variable 'scroll-margin) 0)
- (setq-local header-line-format nil)
- (setq-local mode-line-format nil)
- )))
-
- ;;(iswitchb-mode 1)
- (icomplete-mode)
-
- (defun iswitchb-buffer-display-other-window ()
- "Do iswitchb in other window."
- (interactive)
- (let ((iswitchb-default-method 'display))
- (call-interactively 'iswitchb-buffer)))
-
-
- ;; buffer killing
-
- ;; (defun my-delete-window-killing-buffer () nil)
-
- (defun my-query-kill-current-buffer ()
- "Interactively kill current buffer."
- (interactive)
- (if (y-or-n-p (concat "kill current buffer? :"))
- (kill-buffer (current-buffer))))
- (defun my-force-query-kill-current-buffer ()
- "Interactively kill current buffer."
- (interactive)
- (when (y-or-n-p (concat "kill current buffer? :"))
- (let ((kill-buffer-hook nil)
- (kill-buffer-query-functions nil))
- (kill-buffer (current-buffer)))))
- ;;(global-set-key "\C-xk" 'my-query-kill-current-buffer)
-
- ;; Originally C-x C-k -> kmacro-keymap
- ;; (global-set-key "\C-x\C-k" 'kmacro-keymap)
- (global-set-key (kbd "C-x C-k") 'my-query-kill-current-buffer)
- (substitute-key-definition 'kill-buffer
- 'my-query-kill-current-buffer
- global-map)
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; dired
-
- (defun my-file-head (filename &optional n)
- "Return list of first N lines of file FILENAME."
- ;; TODO: Fix for janapese text
- ;; TODO: Fix for short text
- (let ((num (or n 10))
- (size 100)
- (beg 0)
- (end 0)
- (result '())
- (read -1))
- (with-temp-buffer
- (erase-buffer)
- (while (or (<= (count-lines (point-min)
- (point-max))
- num)
- (eq read 0))
- (setq end (+ beg size))
- (setq read (nth 1 (insert-file-contents-literally filename
- nil
- beg
- end)))
- (goto-char (point-max))
- (setq beg (+ beg size)))
- (goto-char (point-min))
- (while (< (length result) num)
- (let ((start (point)))
- (forward-line 1)
- (setq result
- `(,@result ,(buffer-substring-no-properties start
- (point))))))
- result
- ;; (buffer-substring-no-properties (point-min)
- ;; (progn
- ;; (forward-line num)
- ;; (point)))
- )))
- ;; (apply 'concat (my-file-head "./shrc" 10)
-
-
- (declare-function dired-get-filename "dired" t)
- (defun my-dired-echo-file-head (arg)
- "Echo head of current file.
-
- ARG is num to show, or defaults to 7."
- (interactive "P")
- (let ((f (dired-get-filename)))
- (message "%s"
- (apply 'concat
- (my-file-head f
- 7)))))
-
- (defun my-dired-diff ()
- "Show diff of marked file and file of current line."
- (interactive)
- (let ((files (dired-get-marked-files nil nil nil t)))
- (if (eq (car files)
- t)
- (diff (cadr files) (dired-get-filename))
- (message "One file must be marked!"))))
-
- (defun dired-get-file-info ()
- "Print information of current line file."
- (interactive)
- (let* ((file (dired-get-filename t))
- (quoted (shell-quote-argument file)))
- (if (file-directory-p file)
- (progn
- (message "Calculating disk usage...")
- (let ((du (or (executable-find "gdu")
- (executable-find "du")
- (error "du not found"))))
- (shell-command (concat du
- " -hsD "
- quoted))))
- (shell-command (concat "file "
- quoted)))))
-
- (defun my-dired-scroll-up ()
- "Scroll up."
- (interactive)
- (my-dired-previous-line (- (window-height) 1)))
-
- (defun my-dired-scroll-down ()
- "Scroll down."
- (interactive)
- (my-dired-next-line (- (window-height) 1)))
-
- ;; (defun my-dired-forward-line (arg)
- ;; ""
- ;; (interactive "p"))
-
- (defun my-dired-previous-line (arg)
- "Move ARG lines up."
- (interactive "p")
- (if (> arg 0)
- (progn
- (if (eq (line-number-at-pos)
- 1)
- (goto-char (point-max))
- (forward-line -1))
- (my-dired-previous-line (if (or (dired-get-filename nil t)
- (dired-get-subdir))
- (- arg 1)
- arg)))
- (dired-move-to-filename)))
-
- (defun my-dired-next-line (arg)
- "Move ARG lines down."
- (interactive "p")
- (if (> arg 0)
- (progn
- (if (eq (point)
- (point-max))
- (goto-char (point-min))
- (forward-line 1))
- (my-dired-next-line (if (or (dired-get-filename nil t)
- (dired-get-subdir))
- (- arg 1)
- arg)))
- (dired-move-to-filename)))
-
- (defun my-tramp-remote-find-file (f)
- "Open F."
- (interactive (list (read-file-name "My Find File Tramp: "
- "/scp:"
- nil ;; "/scp:"
- (confirm-nonexistent-file-or-buffer))))
- (find-file f))
-
- ;;http://bach.istc.kobe-u.ac.jp/lect/tamlab/ubuntu/emacs.html
-
- (if (eq window-system 'mac)
- (setq dired-listing-switches "-lhF")
- (setq dired-listing-switches "-lhF --time-style=long-iso")
- )
- (setq dired-listing-switches "-lhF")
-
- ;; when using dired-find-alternate-file
- ;; reuse current dired buffer for the file to open
- ;; (put 'dired-find-alternate-file 'disabled nil)
- (set-variable 'dired-ls-F-marks-symlinks t)
-
- (set-variable 'ls-lisp-use-insert-directory-program nil) ; always use ls-lisp
- (set-variable 'ls-lisp-dirs-first t)
- (set-variable 'ls-lisp-use-localized-time-format t)
- (set-variable 'ls-lisp-format-time-list
- '("%Y-%m-%d %H:%M"
- "%Y-%m-%d "))
-
- (set-variable 'dired-dwim-target t)
- (set-variable 'dired-isearch-filenames t)
- (set-variable 'dired-hide-details-hide-symlink-targets nil)
- (set-variable 'dired-hide-details-hide-information-lines nil)
-
- (set-variable 'dired-deletion-confirmer 'y-or-n-p)
- (set-variable 'dired-recursive-deletes 'always)
-
- ;; (add-hook 'dired-after-readin-hook
- ;; 'my-replace-nasi-none)
-
- (with-eval-after-load 'dired
- (require 'ls-lisp nil t)
- (defvar dired-mode-map (make-sparse-keymap))
- ;; dired-do-chgrp sometimes cause system hung
- (define-key dired-mode-map "G" 'ignore)
- (define-key dired-mode-map "e" 'wdired-change-to-wdired-mode)
- (define-key dired-mode-map "i" 'dired-get-file-info)
- ;; (define-key dired-mode-map "f" 'find-file)
- (define-key dired-mode-map "f" 'my-fzf-or-find-file)
- (define-key dired-mode-map "z" 'fzf)
- (define-key dired-mode-map "!" 'shell-command)
- (define-key dired-mode-map "&" 'async-shell-command)
- (define-key dired-mode-map "X" 'dired-do-async-shell-command)
- (define-key dired-mode-map "=" 'my-dired-diff)
- (define-key dired-mode-map "B" 'gtkbm-add-current-dir)
- (define-key dired-mode-map "b" 'gtkbm)
- (define-key dired-mode-map "h" 'my-dired-echo-file-head)
- (define-key dired-mode-map (kbd "TAB") 'other-window)
- ;; (define-key dired-mode-map "P" 'my-dired-do-pack-or-unpack)
- (define-key dired-mode-map "/" 'dired-isearch-filenames)
- (define-key dired-mode-map (kbd "DEL") 'dired-up-directory)
- (define-key dired-mode-map (kbd "C-h") 'dired-up-directory)
- (substitute-key-definition 'dired-next-line
- 'my-dired-next-line
- dired-mode-map)
- (substitute-key-definition 'dired-previous-line
- 'my-dired-previous-line
- dired-mode-map)
- ;; (define-key dired-mode-map (kbd "C-p") 'my-dired-previous-line)
- ;; (define-key dired-mode-map (kbd "p") 'my-dired-previous-line)
- ;; (define-key dired-mode-map (kbd "C-n") 'my-dired-next-line)
- ;; (define-key dired-mode-map (kbd "n") 'my-dired-next-line)
- (define-key dired-mode-map (kbd "<left>") 'my-dired-scroll-up)
- (define-key dired-mode-map (kbd "<right>") 'my-dired-scroll-down)
- (define-key dired-mode-map (kbd "ESC p") 'my-dired-scroll-up)
- (define-key dired-mode-map (kbd "ESC n") 'my-dired-scroll-down)
-
- (add-hook 'dired-mode-hook
- (lambda ()
- (when (fboundp 'dired-hide-details-mode)
- (dired-hide-details-mode t)
- (local-set-key "l" 'dired-hide-details-mode))
- (let ((file "._Icon\015"))
- (when nil
- '(file-readable-p file)
- (delete-file file)))))
-
- (when (fboundp 'pack-dired-dwim)
- (with-eval-after-load 'dired
- (define-key dired-mode-map "P" 'pack-dired-dwim)))
-
- (when (fboundp 'dired-list-all-mode)
- (setq dired-listing-switches "-lhF")
- (with-eval-after-load 'dired
- (define-key dired-mode-map "a" 'dired-list-all-mode))))
-
- (when (fboundp 'dired-filter-mode)
- (add-hook 'dired-mode-hook
- 'dired-filter-mode))
- (set-variable 'dired-filter-stack nil)
-
- ;; Currently disabled in favor of dired-from-git-ls-files
- ;; (define-key ctl-x-map "f" 'find-dired)
-
-
- (defvar my-dired-git-ls-files-history
- "History for `my-dired-git-ls-files'." nil)
- (defun my-dired-git-ls-files (arg)
- "Dired from git ls-files."
- (interactive (list
- (read-shell-command "git ls-files: "
- "git ls-files -z ")))
- (pop-to-buffer-same-window
- (dired-noselect `(,default-directory
- ,@(split-string (shell-command-to-string arg)
- "\0" t))
- ""))
- )
-
- (define-key ctl-x-map (kbd "G") 'my-dired-git-ls-files)
- (with-eval-after-load 'dired
- (defvar dired-mode-map (make-sparse-keymap))
- (define-key dired-mode-map "G" 'my-dired-git-ls-files))
-
- (with-eval-after-load 'pack
- (set-variable 'pack-silence
- t)
- (defvar pack-program-alist)
- (add-to-list 'pack-program-alist
- '("\\.txz\\'" :pack "tar -cJf" :unpack "tar -xf"))
-
- (when (executable-find "aunpack")
- (add-to-list 'pack-program-alist
- ' ("\\.zip\\'"
- :pack ("zip" "-r" archive sources)
- :pack-append ("zip" "-r" archive sources)
- :unpack ("aunpack" archive))))
- )
-
-
- ;; (define-minor-mode my-dired-glob-filter)
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; misc funcs
-
- (define-key ctl-x-map "T" 'git-worktree)
- (define-key ctl-x-map "W" 'git-walktree)
-
- (when (fboundp 'browse-url-default-macosx-browser)
- (defalias 'browse-osx 'browse-url-default-macosx-browser))
-
- (defalias 'qcalc 'quick-calc)
-
- (defun memo (&optional dir)
- "Open memo.txt in DIR."
- (interactive)
- (pop-to-buffer (find-file-noselect (concat (if dir
- (file-name-as-directory dir)
- "")
- "memo.txt"))))
-
- ;; TODO: remember-projectile
-
- (set (defvar my-privnotes-path nil
- "My privnotes repository path.")
- (expand-file-name "~/my/privnotes"))
-
- (defun my-privnotes-readme (dir)
- "Open my privnotes DIR."
- (interactive (list
- (read-file-name "Privnotes: "
- (expand-file-name (format-time-string "%Y%m%d_")
- my-privnotes-path))))
- (let ((path (expand-file-name "README.md" dir)))
- (with-current-buffer (find-file path)
- (unless (file-exists-p path)
- (insert (file-name-base dir)
- "\n"
- "=======\n"
- "\n\n")))))
- (define-key ctl-x-map "p" 'my-privnotes-readme)
-
- (set (defvar my-rgrep-alist nil
- "Alist of rgrep command.
- Each element is in the form like (NAME SEXP COMMAND), where SEXP returns the
- condition to choose COMMAND when evaluated.")
- `(
- ;; ripgrep
- ("rg"
- (executable-find "rg")
- "rg -nH --no-heading --hidden --glob '!.git/' --smart-case -M 1280 ")
-
- ;; git grep
- ("gitgrep"
- (eq 0
- (shell-command "git rev-parse --git-dir"))
- "git --no-pager grep -nH -e ")
-
- ;; sift
- ("sift"
- (executable-find "sift")
- ("sift --binary-skip --filename --line-number --git --smart-case "))
-
- ;; the silver searcher
- ("ag"
- (executable-find "ag")
- "ag --nogroup --nopager --filename ")
-
- ;; ack
- ("ack"
- (executable-find "ack")
- "ack --nogroup --nopager --with-filename ")
-
- ;; gnu global
- ("global"
- (and (require 'ggtags nil t)
- (executable-find "global")
- (ggtags-current-project-root))
- "global --result grep ")
-
- ;; grep
- ("grep"
- t
- ,(concat "find . "
- "-path '*/.git' -prune -o "
- "-path '*/.svn' -prune -o "
- "-type f -print0 | "
- "xargs -0 grep -nH -e "))
- )
- )
-
- (defvar my-rgrep-default nil
- "Default command name for my-rgrep.")
-
- (defun my-rgrep-grep-command (&optional name alist)
- "Return recursive grep command for current directory or nil.
- If NAME is given, use that without testing.
- Commands are searched from ALIST."
- (if alist
- (if name
- ;; if name is given search that from alist and return the command
- (nth 2 (assoc name
- alist))
-
- ;; if name is not given try test in 1th elem
- (let ((car (car alist))
- (cdr (cdr alist)))
-
- (if (eval (nth 1 car))
- ;; if the condition is true return the command
- (nth 2 car)
-
- ;; try next one
- (and cdr
- (my-rgrep-grep-command name cdr)))))
-
- ;; if alist is not given set default value
- (my-rgrep-grep-command name my-rgrep-alist)))
-
- (defun my-rgrep (command-args)
- "My recursive grep. Run COMMAND-ARGS.
- If prefix argument is given, use current symbol as default search target
- and search from projectile root (if projectile is available)."
- (interactive (let ((cmd (my-rgrep-grep-command my-rgrep-default
- nil)))
- (if cmd
- (list (read-shell-command "grep command: "
- (concat cmd
- (if current-prefix-arg
- (thing-at-point 'symbol t)
- ""))
- 'grep-find-history))
- (error "My-Rgrep: Command for rgrep not found")
- )))
- (if (and current-prefix-arg
- (eval-and-compile (require 'projectile nil t))
- (projectile-project-p))
- (projectile-with-default-dir (projectile-project-root)
- (compilation-start command-args
- 'grep-mode))
- (compilation-start command-args
- 'grep-mode)))
-
- (defun my-rgrep-thing-at-point-projectile-root ()
- "My recursive grep to find thing at point from project root."
- (interactive)
- (let* ((cmd (my-rgrep-grep-command my-rgrep-default
- nil))
- (command-args
- (if cmd
- (concat cmd
- (or (thing-at-point 'symbol t)
- (error "No symbol at point")))
- (error "My-Rgrep: Command for rgrep not found"))))
- (if (eval-and-compile (require 'projectile nil t))
- (projectile-with-default-dir (or (projectile-project-root)
- default-directory)
- (compilation-start command-args
- 'grep-mode))
- (compilation-start command-args
- 'grep-mode))))
-
-
- (defmacro define-my-rgrep (name)
- "Define rgrep for NAME."
- `(defun ,(intern (concat "my-rgrep-"
- name)) ()
- ,(format "My recursive grep by %s."
- name)
- (interactive)
- (let ((my-rgrep-default ,name))
- (if (called-interactively-p 'any)
- (call-interactively 'my-rgrep)
- (error "Not intended to be called noninteractively. Use `my-rgrep'"))))
- )
-
- (define-my-rgrep "ack")
- (define-my-rgrep "ag")
- (define-my-rgrep "rg")
- (define-my-rgrep "sift")
- (define-my-rgrep "gitgrep")
- (define-my-rgrep "grep")
- (define-my-rgrep "global")
-
- (define-key ctl-x-map "s" 'my-rgrep)
- (define-key ctl-x-map "." 'my-rgrep-thing-at-point-projectile-root)
-
- (defun my-occur (regexp &optional region)
- "My occur command to search REGEXP."
- (interactive (list (read-string "List lines matching regexp: "
- (thing-at-point 'symbol t))))
- (occur regexp nil region))
- (define-key ctl-x-map (kbd "C-o") 'my-occur)
-
- (set-variable 'dumb-jump-prefer-searcher 'rg)
-
- (defalias 'make 'compile)
- (define-key ctl-x-map "c" 'compile)
-
- (defun my-pushbullet-note (text &optional title)
- "Push TEXT."
- (interactive "sText to Push: ")
- (pb/push-item '("") text "note" (or title "")))
-
-
- ;;;;;;;;;;;;;;;;;;;;;
- ;; git-bug
-
- (defconst git-bug-ls-regexp
- (eval-when-compile
- (rx bol
- (submatch (one-or-more alphanumeric)) ; id
- ;; (one-or-more any)
- (one-or-more space)
- (submatch (or "open" "close")) ; status
- (one-or-more space)
- (submatch (maximal-match (zero-or-more print))) ; title
- "\t"
- (submatch (one-or-more alphanumeric)) ; user
- (one-or-more space)
- "C:"
- (submatch (one-or-more digit)) ; Comment num
- (one-or-more space)
- "L:"
- (submatch (one-or-more digit)) ; Label num
- eol
- ))
- "Regexp to parse line of output of git-bug ls.
- Used by `git-bug-ls'.")
-
- (defun git-bug-bugs ()
- "Get list of git-bug bugs."
- (with-temp-buffer
- (git-bug--call-process "bug" "ls")
- (goto-char (point-min))
- (let ((bugs nil))
- (while (not (eq (point) (point-max)))
- (save-match-data
- (when (re-search-forward git-bug-ls-regexp (point-at-eol) t)
- (setq bugs `(,@bugs
- ,(list
- :id (match-string 1)
- :status (match-string 2)
- :title (string-trim (match-string 3))
- :user (match-string 4)
- :comment-num (match-string 5)
- :label-num (match-string 6)
- )))))
- (forward-line 1)
- (goto-char (point-at-bol)))
- bugs)))
-
- (defun git-bug-ls ()
- "Open and select git bug list buffer."
- (interactive)
- (pop-to-buffer (git-bug-ls-noselect)))
-
- (defun git-bug-ls-noselect (&optional directory)
- "Open git bug list buffer.
-
- If optional arg DIRECTORY is given change current directory to there before
- initializing."
- (setq directory (expand-file-name (or directory
- default-directory)))
- (cl-assert (file-directory-p directory))
- (let* ((root (git-bug--get-repository-root directory))
- (name (file-name-nondirectory root))
- (bname (format "*GitBug<%s>*" name)))
- (with-current-buffer (get-buffer-create bname)
- (cd root)
- (git-bug-ls--set-tabulated-list-mode-variables)
- (git-bug-ls-mode)
- (current-buffer))))
-
- (defun git-bug--get-repository-root (dir)
- "Resolve repository root of DIR.
-
- If DIR is not inside of any git repository, signal an error."
- (cl-assert (file-directory-p dir))
- (with-temp-buffer
- (cd dir)
- (git-bug--call-process "rev-parse" "--show-toplevel")
- (goto-char (point-min))
- (buffer-substring-no-properties (point-at-bol) (point-at-eol))))
-
- (defun git-bug--call-process (&rest args)
- "Start git process synchronously with ARGS.
-
- Raise error when git process ends with non-zero status.
- Any output will be written to current buffer."
- (let ((status (apply 'call-process
- "git"
- nil
- t
- nil
- args)))
- (cl-assert (eq status 0)
- nil
- (buffer-substring-no-properties (point-min) (point-max)))))
-
-
- ;;;;;;;;;;;;;;;;;;;
- ;; peek-file-mode
-
- (defvar peek-file-buffers
- ()
- "Peek buffers.")
-
- (defun peek-file (file)
- "Peek FILE."
- (interactive "fFile to peek: ")
- (with-current-buffer (find-file file)
- (peek-file-mode)))
-
- (define-minor-mode peek-file-mode
- "Peek file mode."
- :lighter "PK"
- (view-mode peek-file-mode)
- (add-to-list 'peek-file-buffers
- (current-buffer))
- (add-hook 'switch-buffer-functions
- 'peek-file-remove-buffers))
-
- (defun peek-file-remove-buffers (&args _)
- "Remove peek file buffers."
- (cl-dolist (buf (cl-copy-list peek-file-buffers))
- (unless (get-buffer-window buf t)
- (setq peek-file-buffers
- (delq buf
- peek-file-buffers))
- (with-current-buffer buf
- (when peek-file-mode
- (kill-buffer))))))
-
-
- ;;;;;;;;;;;;;;;;;;;;
- ;; remember-projectile
-
- ;; TODO: Add global-minor-mode
- (defvar remember-data-file)
- (defun my-set-remember-data-file-buffer-local ()
- "Set `remember-data-file'."
- (when (require 'projectile nil t)
- (setq-local remember-data-file
- (expand-file-name ".remember.notes"
- (projectile-project-root)))))
-
- (add-hook 'after-change-major-mode-hook
- 'my-set-remember-data-file-buffer-local)
-
- (define-key ctl-x-map "R" 'remember)
-
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; ivy
-
- ;; (set-variable 'enable-recursive-minibuffers t)
- ;; (minibuffer-depth-indicate-mode 1)
-
- (defun my--ivy-regex-fuzzy-ignore-order (str)
- "Re-build regex from STR for ignore-order fuzzy match."
- (let ((re-list (ivy--regex-ignore-order str)))
- (if (listp re-list)
- (mapcar (lambda (e)
- (let ((head (car e))
- (tail (cdr e)))
- (if tail
- (cons (ivy--regex-fuzzy head)
- tail)
- (cons head tail))))
- re-list)
- (ivy--regex-fuzzy re-list))))
- ;; (my--ivy-regex-fuzzy-ignore-order "ab bc !cee")
- ;; (ivy--regex-fuzzy "ab")
- ;; (ivy--regex-ignore-order "a b")
-
- (set-variable 'ivy-re-builders-alist
- '((t . my--ivy-regex-fuzzy-ignore-order)))
-
- ;; (set-variable 'ivy-format-functions-alist
- ;; '((t . ivy-format-function-arrow)))
- (set-variable 'ivy-format-functions-alist
- '((t . (lambda (cands) (ivy--format-function-generic
- (lambda (str)
- (concat "-> "
- (ivy--add-face str 'ivy-current-match)
- ))
- (lambda (str)
- (concat "| " str))
- cands
- "\n")))))
- (set-variable 'ivy-wrap t)
- (set-variable 'ivy-sort-max-size 500)
-
- (when (fboundp 'ivy-rich-mode)
- (ivy-rich-mode 1))
-
- (with-eval-after-load 'ivy
- (defvar ivy-minibuffer-map)
- (define-key ivy-minibuffer-map (kbd "C-u")
- (lambda () (interactive) (delete-region (point-at-bol) (point)))))
- (set-variable 'ivy-on-del-error-function 'ignore)
-
- (when (fboundp 'counsel-M-x)
- (define-key esc-map "x" 'counsel-M-x)
- ;; (counsel-mode 1)
- ;; counsel-fzf executes fzf -f QUERY for each input
- ;; (define-key ctl-x-map "f"
- ;; (lambda ()
- ;; (interactive
- ;; (let ((process-environment (cl-copy-list process-environment)))
- ;; (setenv "FZF_DEFAULT_COMMAND" nil)
- ;; (counsel-fzf)))))
- )
- ;; (when (fboundp 'counsel-switch-buffer)
- ;; (define-key ctl-x-map (kbd "C-b") 'counsel-switch-buffer))
-
- (when (and (fboundp 'ivy-read)
- (locate-library "counsel"))
- (defvar counsel-describe-map)
-
- (defun my-counsel-describe-symbol ()
- "Forwaord to `describe-symbol'."
- (interactive)
- (cl-assert (eval-and-compile (require 'help-mode nil t))) ;; describe-symbol-backends
- (cl-assert (eval-and-compile (require 'counsel nil t)))
- (ivy-read "Describe symbol: " obarray
- ;; From describe-symbol definition
- :predicate (lambda (vv)
- (cl-some (lambda (x) (funcall (nth 1 x) vv))
- describe-symbol-backends))
- :require-match t
- :history 'counsel-describe-symbol-history
- :keymap counsel-describe-map
- :preselect (ivy-thing-at-point)
- :action (lambda (x)
- (describe-symbol (intern x)))
- :caller 'my-counsel-describe-symbol))
-
- (define-key help-map "o" 'my-counsel-describe-symbol)
- )
-
- ;; (defun my-ivy-length (x y)
- ;; "Ivy sort to order by string length."
- ;; (<= (length (if (consp x) (car x) x))
- ;; (length (if (consp y) (car y) y))))
- ;; (my-ivy-length "a" (cons "bc" t))
- ;; (my-ivy-length "a" (cons "c" t))
-
- (with-eval-after-load 'ivy
- ;; (ivy-configure 'my-counsel-describe-symbol
- ;; :sort-fn 'my-ivy-length)
- (ivy-configure 'counsel-M-x
- :initial-input ""
- ;; :sort-fn 'my-ivy-length
- )
- (defvar ivy-sort-matches-functions-alist)
- (add-to-list 'ivy-sort-matches-functions-alist
- '(my-counsel-describe-symbol . ivy--shorter-matches-first))
- (add-to-list 'ivy-sort-matches-functions-alist
- '(counsel-M-x . ivy--shorter-matches-first))
- )
-
-
- (when (fboundp 'counsel-imenu)
- (define-key ctl-x-map "l" 'counsel-imenu))
-
- (when (fboundp 'swoop)
- ;; (global-set-key (kbd "C-s") 'swoop)
- ;; (global-set-key (kbd "C-r") 'swoop)
- ;; (define-key esc-map (kbd "C-s") 'swoop-multi)
- (define-key esc-map (kbd "C-s") 'swoop)
- (with-eval-after-load 'swoop-lib
- (defvar swoop-map)
- (define-key swoop-map (kbd "C-s") 'swoop-action-goto-line-next)
- (define-key swoop-map (kbd "C-r") 'swoop-action-goto-line-prev)
- )
- ;; TODO: case sensitive swoop
- ;; Wrap swoop-async-get-match-lines-list?
- ;; (with-eval-after-load 'swoop-lib
- ;; (defun my-swoop-advice-smart-case (orig-func &rest args)
- ;; "Function to wrap swoop function."
- ;; (message "args: %S" args)
- ;; (let* (
- ;; (query (car args))
- ;; ;; (query (plist-get args
- ;; ;; :$query))
- ;; (case-fold-search
- ;; (let ((case-fold-search nil))
- ;; (not (string-match-p (rx upper) query))))
- ;; )
- ;; ;; (message "case-fold-search: %S" case-fold-search)
- ;; ;; (message "query: %S" query)
- ;; (apply orig-func args)))
- ;; (advice-add 'swoop-async-get-match-lines-list
- ;; :around
- ;; 'my-swoop-advice-smart-case)
- ;; (set-variable 'swoop-async-get-match-lines-list
- ;; (byte-compile 'swoop-async-get-match-lines-list))
- ;; )
-
- )
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; dired-k
- ;; なんかよくわからないけど頻繁に index.lock を残してしまう
- (when (fboundp 'dired-k)
- (set-variable 'dired-k-style 'git)
-
- ;; What is the best way of doing this?
- (with-eval-after-load 'dired-k
- (fset 'dired-k--highlight-by-file-attribyte 'ignore))
- ;; (set-variable 'dired-k-size-colors
- ;; `((,most-positive-fixnum)))
- ;; (set-variable 'dired-k-date-colors
- ;; `((,most-positive-fixnum)))
-
- ;; always execute dired-k when dired buffer is opened and reverted
- ;; (add-hook 'dired-after-readin-hook #'dired-k-no-revert)
-
- ;; This causes:
- ;; fatal: Unable to create '.git/index.lock': File exist.s
- ;; (add-hook 'switch-buffer-functions
- ;; (lambda (prev cur)
- ;; (when (derived-mode-p 'dired-mode)
- ;; (dired-k-no-revert))))
- )
-
- (add-hook 'python-mode-hook
- (lambda ()
- ;; Currently on python-mode eldoc-mode sometimes print
- ;; wired message on "from" keyword:
- ;;var from = require("./from")
- (eldoc-mode -1)))
-
- ;; ?
- (define-key input-decode-map "\e[1;5C" [C-right])
- (define-key input-decode-map "\e[1;5D" [C-left])
-
- ;;;;;;;;;;;;;;;;;;;;;;;;
- ;; mozc
-
- (global-set-key (kbd "C-c m e") 'ignore)
- (global-set-key (kbd "C-c m d") 'ignore)
- ;; mozc
- (when (locate-library "mozc")
- ;; https://tottoto.net/mac-emacs-karabiner-elements-japanese-input-method-config/
- (with-eval-after-load 'mozc
- ;; (define-key mozc-mode-map (kbd "C-h") 'backward-delete-char)
- ;; (define-key mozc-mode-map (kbd "C-p") (kbd "<up>"))
- ;; (define-key mozc-mode-map (kbd "C-n") (kbd "SPC"))
- )
- (setq default-input-method "japanese-mozc")
- (custom-set-variables '(mozc-leim-title "あ"))
- (defun turn-on-input-method ()
- (interactive)
- (activate-input-method default-input-method))
- (defun turn-off-input-method ()
- (interactive)
- (deactivate-input-method))
- ;; (setq mozc-candidate-style 'echo-area)
- (global-set-key (kbd "C-c m e") 'turn-on-input-method)
- (global-set-key (kbd "C-c m d") 'turn-off-input-method)
-
- (require 'mozc-popup)
- (set-variable 'mozc-candidate-style 'popup)
-
- ;; これいる?
- (when (require 'mozc-im nil t)
- (setq default-input-method "japanese-mozc-im")
- ;; (global-set-key (kbd "C-j") 'toggle-input-method)
- )
- )
-
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ;; highlight-mark
-
- (defvar-local highlight-mark-last-mark-position nil
- "Last mark object.")
-
- (defun highlight-mark-post-command ()
- "Update highlight mark on mark change."
- (unless (eq (mark t)
- highlight-mark-last-mark-position)
- (setq highlight-mark-last-mark-position (mark t))
- (message "Mark changed! %S"
- highlight-mark-last-mark-position)))
-
- (add-hook 'post-command-hook
- 'highlight-mark-post-command)
-
- ;;;;;;;;;;;;;;
- ;; mmv
- ;; https://www.emacswiki.org/emacs/MakingMarkVisible
-
- ;;;; Make the mark visible, and the visibility toggleable. ('mmv' means 'make
- ;;;; mark visible'.) By Patrick Gundlach, Teemu Leisti, and Stefan.
-
- (defvar mmv-face-foreground
- (face-foreground 'hi-yellow)
- "Foreground color for `mmv-face'.")
-
- (defvar mmv-face-background
- (face-background 'hi-yellow)
- "Background color for `mmv-face'.")
-
- (defface mmv-face
- `((t :background ,mmv-face-background :foreground ,mmv-face-foreground))
- "Face used for showing the mark's position.")
-
- (defvar-local mmv-mark-overlay nil
- "The overlay for showing the mark's position.")
-
- (defvar-local mmv-is-mark-visible t
- "The overlay is visible only when this variable's value is t.")
-
- (defun mmv-draw-mark (&rest _)
- "Make the mark's position stand out by means of a one-character-long overlay.
- If the value of variable `mmv-is-mark-visible' is nil, the mark will be
- invisible."
- (unless mmv-mark-overlay
- (setq mmv-mark-overlay (make-overlay 0 0 nil t))
- (overlay-put mmv-mark-overlay 'face 'mmv-face))
- (let ((mark-position (mark t)))
- (cond
- ((null mark-position) (delete-overlay mmv-mark-overlay))
- ((and (< mark-position (point-max))
- (not (eq ?\n (char-after mark-position))))
- (overlay-put mmv-mark-overlay 'after-string nil)
- (move-overlay mmv-mark-overlay mark-position (1+ mark-position)))
- (t
- ;; This branch is called when the mark is at the end of a line or at the
- ;; end of the buffer. We use a bit of trickery to avoid the higlight
- ;; extending from the mark all the way to the right end of the frame.
- (overlay-put mmv-mark-overlay 'after-string
- (propertize " " 'face (overlay-get mmv-mark-overlay 'face)))
- (move-overlay mmv-mark-overlay mark-position mark-position)))))
-
- (add-hook 'pre-redisplay-functions #'mmv-draw-mark)
-
- (defun mmv-toggle-mark-visibility ()
- "Toggles the mark's visiblity and redraws it (whether invisible or visible)."
- (interactive)
- (setq mmv-is-mark-visible (not mmv-is-mark-visible))
- (if mmv-is-mark-visible
- (set-face-attribute 'mmv-face nil :background mmv-face-background :foreground mmv-face-foreground)
- (set-face-attribute 'mmv-face nil :background 'unspecified :foreground 'unspecified))
- (mmv-draw-mark))
-
-
- ;; Local Variables:
- ;; flycheck-disabled-checkers: (emacs-lisp-checkdoc)
- ;; flycheck-checker: emacs-lisp
- ;; End:
-
- ;;; emancs.el ends here
|