.emacs-my
changeset 1514 1ce5595fe5f1
parent 1507 6f939639c52a
child 1527 ff6e296d2b21
equal deleted inserted replaced
1513:0da077ba84ab 1514:1ce5595fe5f1
    41 
    41 
    42 ;; (setq recentf-menu-filter 'recentf-arrange-by-dir) ; Too slow with dir widgets.
    42 ;; (setq recentf-menu-filter 'recentf-arrange-by-dir) ; Too slow with dir widgets.
    43 ;; Don't sort ``recentf-list`` so ``recentf-open-files`` show files in historical order!
    43 ;; Don't sort ``recentf-list`` so ``recentf-open-files`` show files in historical order!
    44 (setq recentf-menu-filter nil)
    44 (setq recentf-menu-filter nil)
    45 
    45 
    46 (defun my/recentf-clean-project (dir)
    46 (defun my-recentf-clean-project (dir)
    47   "Remove from recentf all files that belong to DIR directory."
    47   "Remove from recentf all files that belong to DIR directory."
    48   (interactive (list (read-directory-name "Exclude all paths")))
    48   (interactive (list (read-directory-name "Exclude all paths")))
    49   (let ( recentf-exclude )
    49   (let ( recentf-exclude )
    50     (setq recentf-exclude (list (concat "^" (regexp-quote (expand-file-name dir)))))
    50     (setq recentf-exclude (list (concat "^" (regexp-quote (expand-file-name dir)))))
    51     (recentf-cleanup) ))
    51     (recentf-cleanup) ))
    67 
    67 
    68 ;; Prevent Emacs from loading 'default.el', which loaded after '.emacs'.
    68 ;; Prevent Emacs from loading 'default.el', which loaded after '.emacs'.
    69 ;; Also '-q' prevent loading your init file.
    69 ;; Also '-q' prevent loading your init file.
    70 (setq inhibit-default-init nil)         ; t/nil
    70 (setq inhibit-default-init nil)         ; t/nil
    71 
    71 
    72 (defun my/debug (mode)
    72 (defun my-debug (mode)
    73   "With prefix enable enter to debuger and show backtrace when
    73   "With prefix enable enter to debuger and show backtrace when
    74 problems occur, with double prefix enable debugging on event and
    74 problems occur, with double prefix enable debugging on event and
    75 signal, else disable breaking to debugger."
    75 signal, else disable breaking to debugger."
    76   (interactive "P")
    76   (interactive "P")
    77   (let ( (lvl1 (not (not mode))) (lvl2 (equal mode '(16))) )
    77   (let ( (lvl1 (not (not mode))) (lvl2 (equal mode '(16))) )
    83     (cond
    83     (cond
    84      (lvl2 (message "Debugging on quit/event/signal..."))
    84      (lvl2 (message "Debugging on quit/event/signal..."))
    85      (lvl1 (message "Debugging on quit..."))
    85      (lvl1 (message "Debugging on quit..."))
    86      (t (message "Debugging disabled...")))))
    86      (t (message "Debugging disabled...")))))
    87 
    87 
    88 (defun my/eval-buffer ()
    88 (defun my-eval-buffer ()
    89   "Evaluate entire buffer with re-assigning values to `defvar' / `defcustom'.
    89   "Evaluate entire buffer with re-assigning values to `defvar' / `defcustom'.
    90 Useful during package development."
    90 Useful during package development."
    91   (interactive)
    91   (interactive)
    92   (save-excursion
    92   (save-excursion
    93     (goto-char (point-min))
    93     (goto-char (point-min))
    94     (while (not (eobp))
    94     (while (not (eobp))
    95       (eval-defun nil)
    95       (eval-defun nil)
    96       (end-of-defun))))
    96       (end-of-defun))))
    97 
    97 
    98 (defun my/load-library (library)
    98 (defun my-load-library (library)
    99   "Evaluate entire library with re-assigning values to `defvar' / `defcustom'.
    99   "Evaluate entire library with re-assigning values to `defvar' / `defcustom'.
   100 Useful during package development."
   100 Useful during package development."
   101   (interactive
   101   (interactive
   102    (list (completing-read "Load library: "
   102    (list (completing-read "Load library: "
   103                           (apply-partially 'locate-file-completion-table
   103                           (apply-partially 'locate-file-completion-table
   104                                            load-path
   104                                            load-path
   105                                            '("" ".el")))))
   105                                            '("" ".el")))))
   106   (with-temp-buffer
   106   (with-temp-buffer
   107     (insert-file-contents (locate-file library load-path '("" ".el")))
   107     (insert-file-contents (locate-file library load-path '("" ".el")))
   108     (my/eval-buffer)))
   108     (my-eval-buffer)))
   109 
   109 
   110 (my/debug nil)
   110 (my-debug nil)
   111 
   111 
   112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   112 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   113 (message "user info")
   113 (message "user info")
   114 
   114 
   115 (eval-when 'compile (require 'info))
   115 (eval-when 'compile (require 'info))
   132          (when (boundp 'user-home-page) (concat ", " user-home-page))))
   132          (when (boundp 'user-home-page) (concat ", " user-home-page))))
   133 
   133 
   134 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   134 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   135 (message "my defun, defmacro, defvar")
   135 (message "my defun, defmacro, defvar")
   136 
   136 
   137 (defmacro my/filter (pred list)
   137 (defmacro my-filter (pred list)
   138   "Construct list with elements from LIST which satisfy PRED."
   138   "Construct list with elements from LIST which satisfy PRED."
   139   (let ( (r (make-symbol "r_")) )
   139   (let ( (r (make-symbol "r_")) )
   140     `(let ( (,r (list nil)) )
   140     `(let ( (,r (list nil)) )
   141        (mapc (lambda (item)
   141        (mapc (lambda (item)
   142                (when (,pred item)
   142                (when (,pred item)
   143                  (nconc ,r (cons item nil))))
   143                  (nconc ,r (cons item nil))))
   144              ,list)
   144              ,list)
   145        (cdr ,r))))
   145        (cdr ,r))))
   146 
   146 
   147 (defun my/fold (f x list)
   147 (defun my-fold (f x list)
   148   "Recursively applies (F i j) to LIST starting with X.
   148   "Recursively applies (F i j) to LIST starting with X.
   149 For example, (fold F X '(1 2 3)) computes (F (F (F X 1) 2) 3)."
   149 For example, (fold F X '(1 2 3)) computes (F (F (F X 1) 2) 3)."
   150   (let ((li list) (x2 x))
   150   (let ((li list) (x2 x))
   151     (while li
   151     (while li
   152       (setq x2 (funcall f x2 (pop li)))
   152       (setq x2 (funcall f x2 (pop li)))
   160 Otherwise, return result of last form in BODY."
   160 Otherwise, return result of last form in BODY."
   161     (declare (debug t) (indent 0))
   161     (declare (debug t) (indent 0))
   162     `(condition-case nil (progn ,@body) (error nil)))
   162     `(condition-case nil (progn ,@body) (error nil)))
   163   )
   163   )
   164 
   164 
   165 (defun my/lookup-key (key)
   165 (defun my-lookup-key (key)
   166   "Search for KEY in all known keymaps."
   166   "Search for KEY in all known keymaps."
   167   (let (result)
   167   (let (result)
   168     (mapatoms (lambda (ob) (when (and (boundp ob)
   168     (mapatoms (lambda (ob) (when (and (boundp ob)
   169                                  (keymapp (symbol-value ob))
   169                                  (keymapp (symbol-value ob))
   170                                  (functionp (lookup-key (symbol-value ob) key)))
   170                                  (functionp (lookup-key (symbol-value ob) key)))
   181 
   181 
   182 (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
   182 (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
   183 (add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
   183 (add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
   184 (add-hook 'ielm-mode-hook 'turn-on-eldoc-mode)
   184 (add-hook 'ielm-mode-hook 'turn-on-eldoc-mode)
   185 
   185 
   186 (defun my/emacs-lisp-mode-hook ()
   186 (defun my-emacs-lisp-mode-hook ()
   187   (setq tab-width 8))
   187   (setq tab-width 8))
   188 (add-hook 'emacs-lisp-mode-hook 'my/emacs-lisp-mode-hook)
   188 (add-hook 'emacs-lisp-mode-hook 'my-emacs-lisp-mode-hook)
   189 
   189 
   190 (defun my/elisp-find-tag ()
   190 (defun my-elisp-find-tag ()
   191   (interactive)
   191   (interactive)
   192   (require 'etags)
   192   (require 'etags)
   193   (ring-insert find-tag-marker-ring (point-marker))
   193   (ring-insert find-tag-marker-ring (point-marker))
   194   (unless (find-variable-at-point)
   194   (unless (find-variable-at-point)
   195     (find-function-at-point)
   195     (find-function-at-point)
   196     ))
   196     ))
   197 ;; Goto elisp definition.
   197 ;; Goto elisp definition.
   198 (define-key emacs-lisp-mode-map (kbd "M-.") 'my/elisp-find-tag)
   198 (define-key emacs-lisp-mode-map (kbd "M-.") 'my-elisp-find-tag)
   199 
   199 
   200 (if (not (fboundp 'global-prettify-symbols-mode))
   200 (if (not (fboundp 'global-prettify-symbols-mode))
   201     ;; http://www.emacswiki.org/emacs/PrettyLambda
   201     ;; http://www.emacswiki.org/emacs/PrettyLambda
   202     (font-lock-add-keywords
   202     (font-lock-add-keywords
   203      'emacs-lisp-mode
   203      'emacs-lisp-mode
   204      `(("(\\<\\(lambda\\)\\>"
   204      `(("(\\<\\(lambda\\)\\>"
   205         (1 (progn (compose-region (match-beginning 1) (match-end 1) ,(make-char 'greek-iso8859-7 107)) font-lock-keyword-face)) )))
   205         (1 (progn (compose-region (match-beginning 1) (match-end 1) ,(make-char 'greek-iso8859-7 107)) font-lock-keyword-face)) )))
   206   (global-prettify-symbols-mode 1))
   206   (global-prettify-symbols-mode 1))
   207 
   207 
   208 (defun my/dump-funcs ()
   208 (defun my-dump-funcs ()
   209   "Dump all function calls in current buffer. Useful to explore
   209   "Dump all function calls in current buffer. Useful to explore
   210 elisp API from somebody else files."
   210 elisp API from somebody else files."
   211   (interactive)
   211   (interactive)
   212   (let* ( (cur-buffer (current-buffer)) (new-buffer (get-buffer-create (concat (buffer-name cur-buffer) "-funcs.el"))) symb )
   212   (let* ( (cur-buffer (current-buffer)) (new-buffer (get-buffer-create (concat (buffer-name cur-buffer) "-funcs.el"))) symb )
   213     (while (search-forward-regexp "([[:alnum:]*]" nil t)
   213     (while (search-forward-regexp "([[:alnum:]*]" nil t)
   220     ))
   220     ))
   221 
   221 
   222 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   222 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   223 (message "mode groups")
   223 (message "mode groups")
   224 
   224 
   225 (defmacro my/defun-rename-symb-tree (name doc func)
   225 (defmacro my-defun-rename-symb-tree (name doc func)
   226   "Travel by TREE and applies FUNC to each symbol."
   226   "Travel by TREE and applies FUNC to each symbol."
   227   `(defun ,name (tree)
   227   `(defun ,name (tree)
   228      ,doc
   228      ,doc
   229      (cond
   229      (cond
   230       ((symbolp tree)
   230       ((symbolp tree)
   234        (mapcar ',name tree)
   234        (mapcar ',name tree)
   235        )
   235        )
   236       (t (error "Only tree of symbols allowed"))
   236       (t (error "Only tree of symbols allowed"))
   237       )))
   237       )))
   238 
   238 
   239 (my/defun-rename-symb-tree
   239 (my-defun-rename-symb-tree
   240  my/feature2mode
   240  my-feature2mode
   241  "Convert TREE of features to TREE of modes for these features. Single symbol allowed."
   241  "Convert TREE of features to TREE of modes for these features. Single symbol allowed."
   242  (lambda (symb) (intern (concat (symbol-name symb) "-mode"))))
   242  (lambda (symb) (intern (concat (symbol-name symb) "-mode"))))
   243 
   243 
   244 (my/defun-rename-symb-tree
   244 (my-defun-rename-symb-tree
   245  my/mode2hook
   245  my-mode2hook
   246  "Convert TREE of modes to TREE of hooks for these modes. Single symbol allowed."
   246  "Convert TREE of modes to TREE of hooks for these modes. Single symbol allowed."
   247  (lambda (symb) (intern (concat (symbol-name symb) "-hook")))
   247  (lambda (symb) (intern (concat (symbol-name symb) "-hook")))
   248  )
   248  )
   249 
   249 
   250 (my/defun-rename-symb-tree
   250 (my-defun-rename-symb-tree
   251  my/mode2modemap
   251  my-mode2modemap
   252  "Convert TREE of modes to TREE of keymaps for these modes. Single symbol allowed."
   252  "Convert TREE of modes to TREE of keymaps for these modes. Single symbol allowed."
   253  (lambda (symb) (intern (concat (symbol-name symb) "-map")))
   253  (lambda (symb) (intern (concat (symbol-name symb) "-map")))
   254  )
   254  )
   255 
   255 
   256 (defvar my/devel-mode-list
   256 (defvar my-devel-mode-list
   257   '(
   257   '(
   258     sh-mode script-mode tcl-mode
   258     sh-mode script-mode tcl-mode
   259     c-mode c++-mode java-mode js-mode
   259     c-mode c++-mode java-mode js-mode
   260     python-mode perl-mode cperl-mode
   260     python-mode perl-mode cperl-mode
   261     lisp-mode
   261     lisp-mode
   269     texinfo-mode
   269     texinfo-mode
   270     gadict-mode
   270     gadict-mode
   271     )
   271     )
   272   "List of development modes.")
   272   "List of development modes.")
   273 
   273 
   274 (defvar my/devel-mode-hook-list
   274 (defvar my-devel-mode-hook-list
   275    (my/mode2hook my/devel-mode-list)
   275    (my-mode2hook my-devel-mode-list)
   276   "List of development mode hooks.")
   276   "List of development mode hooks.")
   277 
   277 
   278 (defvar my/scroll-margin-mode-list
   278 (defvar my-scroll-margin-mode-list
   279   '(
   279   '(
   280     vc-dir-mode
   280     vc-dir-mode
   281     recentf-dialog-mode
   281     recentf-dialog-mode
   282     org-agenda-grid-mode           ; XXX for this item not worked!
   282     org-agenda-grid-mode           ; XXX for this item not worked!
   283     log-view-mode
   283     log-view-mode
   285     compilation-mode
   285     compilation-mode
   286     conf-mode
   286     conf-mode
   287     )
   287     )
   288   "List of modes for enabling scroll margin.")
   288   "List of modes for enabling scroll margin.")
   289 
   289 
   290 (defvar my/scroll-margin-mode-hook-list
   290 (defvar my-scroll-margin-mode-hook-list
   291   (my/mode2hook my/scroll-margin-mode-list)
   291   (my-mode2hook my-scroll-margin-mode-list)
   292   "List of mode hooks for enabling scroll margin.")
   292   "List of mode hooks for enabling scroll margin.")
   293 
   293 
   294 (defvar my/text-mode-list
   294 (defvar my-text-mode-list
   295   '(
   295   '(
   296     text-mode
   296     text-mode
   297     outline-mode
   297     outline-mode
   298     rst-mode
   298     rst-mode
   299     diff-mode
   299     diff-mode
   300     dict-c5-mode
   300     dict-c5-mode
   301     )
   301     )
   302   "List of text modes.")
   302   "List of text modes.")
   303 
   303 
   304 (defvar my/text-mode-hook-list
   304 (defvar my-text-mode-hook-list
   305   (my/mode2hook my/text-mode-list)
   305   (my-mode2hook my-text-mode-list)
   306   "List of text mode hooks.")
   306   "List of text mode hooks.")
   307 
   307 
   308 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   308 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   309 (message "MS Windows, w32, win32")
   309 (message "MS Windows, w32, win32")
   310 
   310 
   344 
   344 
   345 (eval-when 'compile (load-library "window"))
   345 (eval-when 'compile (load-library "window"))
   346 
   346 
   347 (setq display-buffer-reuse-frames t)
   347 (setq display-buffer-reuse-frames t)
   348 
   348 
   349 (defun my/maximize ()
   349 (defun my-maximize ()
   350   ;; Next code work with Emacs 21.4, 22.3, 23.1.
   350   ;; Next code work with Emacs 21.4, 22.3, 23.1.
   351   (let (
   351   (let (
   352         (px (display-pixel-width))
   352         (px (display-pixel-width))
   353         (py (display-pixel-height))
   353         (py (display-pixel-height))
   354         (fx (frame-char-width))
   354         (fx (frame-char-width))
   363     (add-to-list 'initial-frame-alist (cons 'height ty)) ))
   363     (add-to-list 'initial-frame-alist (cons 'height ty)) ))
   364 
   364 
   365 (when window-system
   365 (when window-system
   366   (if (fboundp 'toggle-frame-maximized)
   366   (if (fboundp 'toggle-frame-maximized)
   367       (toggle-frame-maximized)
   367       (toggle-frame-maximized)
   368     (my/maximize) ))
   368     (my-maximize) ))
   369 
   369 
   370 (menu-bar-mode -1)
   370 (menu-bar-mode -1)
   371 (when window-system
   371 (when window-system
   372   (mouse-avoidance-mode 'animate)
   372   (mouse-avoidance-mode 'animate)
   373   (scroll-bar-mode 1)
   373   (scroll-bar-mode 1)
   374   (tool-bar-mode -1)
   374   (tool-bar-mode -1)
   375   (tooltip-mode -1)
   375   (tooltip-mode -1)
   376   (setq-default line-spacing nil)
   376   (setq-default line-spacing nil)
   377   (defun my/popup-menu ()
   377   (defun my-popup-menu ()
   378     "Menu from keyboard by emulating mouse event."
   378     "Menu from keyboard by emulating mouse event."
   379     (interactive)
   379     (interactive)
   380     (mouse-popup-menubar
   380     (mouse-popup-menubar
   381      (list (list (/ (display-pixel-width) 2) 10) (get-buffer-window (buffer-name)))
   381      (list (list (/ (display-pixel-width) 2) 10) (get-buffer-window (buffer-name)))
   382      nil) )
   382      nil) )
   383   (global-set-key [f10] 'my/popup-menu)
   383   (global-set-key [f10] 'my-popup-menu)
   384   (global-set-key [apps] 'my/popup-menu)
   384   (global-set-key [apps] 'my-popup-menu)
   385   (global-set-key [menu] 'my/popup-menu) )
   385   (global-set-key [menu] 'my-popup-menu) )
   386 
   386 
   387 ;; Prefer horizontal windows splitting.
   387 ;; Prefer horizontal windows splitting.
   388 (when (>= emacs-major-version 23)
   388 (when (>= emacs-major-version 23)
   389   (setq split-height-threshold nil)
   389   (setq split-height-threshold nil)
   390   (setq split-width-threshold nil)
   390   (setq split-width-threshold nil)
   480 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   480 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   481 (message "shell, bash, Cygwin, MSYS")
   481 (message "shell, bash, Cygwin, MSYS")
   482 
   482 
   483 (eval-when 'compile (require 'shell))
   483 (eval-when 'compile (require 'shell))
   484 
   484 
   485 (defvar my/use-windows-shell nil
   485 (defvar my-use-windows-shell nil
   486   "If t 'cmdproxy.exe' will be used as shell.
   486   "If t 'cmdproxy.exe' will be used as shell.
   487 Affect on \\[shell] like commands. If nil, 'sh' will be used." )
   487 Affect on \\[shell] like commands. If nil, 'sh' will be used." )
   488 
   488 
   489 (defun follow-cygwin-symlink ()
   489 (defun follow-cygwin-symlink ()
   490   "Follow new-style (and also UCS-16) Cygwin symlinks."
   490   "Follow new-style (and also UCS-16) Cygwin symlinks."
   498          'utf-16-le)
   498          'utf-16-le)
   499         0 -1)                           ; -1 for stripping final \0.
   499         0 -1)                           ; -1 for stripping final \0.
   500        ))))
   500        ))))
   501 
   501 
   502 (defvar cygwin-mount-table--internal)
   502 (defvar cygwin-mount-table--internal)
   503 (defun my/dos2cygwin-path (path)
   503 (defun my-dos2cygwin-path (path)
   504   "Convert DOS path to Cygwin according to current mount table."
   504   "Convert DOS path to Cygwin according to current mount table."
   505   (interactive (list (read-directory-name "Enter DOS path: ")))
   505   (interactive (list (read-directory-name "Enter DOS path: ")))
   506   (setq path (replace-regexp-in-string "\\\\" "/" (expand-file-name path)))
   506   (setq path (replace-regexp-in-string "\\\\" "/" (expand-file-name path)))
   507   (let ( (table cygwin-mount-table--internal) item prefix )
   507   (let ( (table cygwin-mount-table--internal) item prefix )
   508     (while table
   508     (while table
   558   (defun executable-find (command) (locate-file command exec-path exec-suffixes))
   558   (defun executable-find (command) (locate-file command exec-path exec-suffixes))
   559   )
   559   )
   560 
   560 
   561 (ansi-color-for-comint-mode-on)
   561 (ansi-color-for-comint-mode-on)
   562 
   562 
   563 (defun my/ansi-color (&optional beg end)
   563 (defun my-ansi-color (&optional beg end)
   564   "Interpret ANSI color esacape sequence by colorifying cotent.
   564   "Interpret ANSI color esacape sequence by colorifying cotent.
   565 Operate on selected region on whole buffer."
   565 Operate on selected region on whole buffer."
   566   (interactive
   566   (interactive
   567    (if (use-region-p)
   567    (if (use-region-p)
   568        (list (region-beginning) (region-end))
   568        (list (region-beginning) (region-end))
   584 (setq term-scroll-show-maximum-output t)
   584 (setq term-scroll-show-maximum-output t)
   585 
   585 
   586 (my--eval-after-load term
   586 (my--eval-after-load term
   587   (define-key term-mode-map [?\t] #'term-dynamic-complete)
   587   (define-key term-mode-map [?\t] #'term-dynamic-complete)
   588 
   588 
   589   (defun my/term-send-delete-word-forward () (interactive) (term-send-raw-string "\ed"))
   589   (defun my-term-send-delete-word-forward () (interactive) (term-send-raw-string "\ed"))
   590   (defun my/term-send-delete-word-backward () (interactive) (term-send-raw-string "\e\C-h"))
   590   (defun my-term-send-delete-word-backward () (interactive) (term-send-raw-string "\e\C-h"))
   591   (define-key term-raw-map [C-delete] 'my/term-send-delete-word-forward)
   591   (define-key term-raw-map [C-delete] 'my-term-send-delete-word-forward)
   592   (define-key term-raw-map [C-backspace] 'my/term-send-delete-word-backward)
   592   (define-key term-raw-map [C-backspace] 'my-term-send-delete-word-backward)
   593   (defun my/term-send-forward-word () (interactive) (term-send-raw-string "\ef"))
   593   (defun my-term-send-forward-word () (interactive) (term-send-raw-string "\ef"))
   594   (defun my/term-send-backward-word () (interactive) (term-send-raw-string "\eb"))
   594   (defun my-term-send-backward-word () (interactive) (term-send-raw-string "\eb"))
   595   (define-key term-raw-map [C-left] 'my/term-send-backward-word)
   595   (define-key term-raw-map [C-left] 'my-term-send-backward-word)
   596   (define-key term-raw-map [C-right] 'my/term-send-forward-word)
   596   (define-key term-raw-map [C-right] 'my-term-send-forward-word)
   597   (defun my/term-send-m-right () (interactive) (term-send-raw-string "\e[1;3C"))
   597   (defun my-term-send-m-right () (interactive) (term-send-raw-string "\e[1;3C"))
   598   (defun my/term-send-m-left () (interactive) (term-send-raw-string "\e[1;3D"))
   598   (defun my-term-send-m-left () (interactive) (term-send-raw-string "\e[1;3D"))
   599   (define-key term-raw-map [M-right] 'my/term-send-m-right)
   599   (define-key term-raw-map [M-right] 'my-term-send-m-right)
   600   (define-key term-raw-map [M-left] 'my/term-send-m-left) )
   600   (define-key term-raw-map [M-left] 'my-term-send-m-left) )
   601 
   601 
   602 (defun my/term-mode-hook ()
   602 (defun my-term-mode-hook ()
   603   (goto-address-mode 1))
   603   (goto-address-mode 1))
   604 (add-hook 'term-mode-hook #'my/term-mode-hook)
   604 (add-hook 'term-mode-hook #'my-term-mode-hook)
   605 
   605 
   606 (setq term-prompt-regexp "^[^#$%>\n]*[#$%>] *")
   606 (setq term-prompt-regexp "^[^#$%>\n]*[#$%>] *")
   607 
   607 
   608 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   608 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   609 (message "proced")
   609 (message "proced")
   619 (setq default-indicate-buffer-boundaries 'left)
   619 (setq default-indicate-buffer-boundaries 'left)
   620 
   620 
   621 ;; (setq-default show-trailing-whitespace t)
   621 ;; (setq-default show-trailing-whitespace t)
   622 
   622 
   623 (setq whitespace-style '(face trailing tabs))
   623 (setq whitespace-style '(face trailing tabs))
   624 (setq whitespace-global-modes (append my/devel-mode-list my/text-mode-list))
   624 (setq whitespace-global-modes (append my-devel-mode-list my-text-mode-list))
   625 (ignore-errors
   625 (ignore-errors
   626   (require 'whitespace)
   626   (require 'whitespace)
   627   (global-whitespace-mode 1))
   627   (global-whitespace-mode 1))
   628 
   628 
   629 (setq next-line-add-newlines nil)
   629 (setq next-line-add-newlines nil)
   719 (setq
   719 (setq
   720  use-dialog-box t
   720  use-dialog-box t
   721  x-gtk-show-hidden-files t
   721  x-gtk-show-hidden-files t
   722  )
   722  )
   723 
   723 
   724 (defun my/prevent-kill-buffer ()
   724 (defun my-prevent-kill-buffer ()
   725   (if (member (buffer-name) '("*scratch*" "NOTE.org")) nil t))
   725   (if (member (buffer-name) '("*scratch*" "NOTE.org")) nil t))
   726 (add-to-list 'kill-buffer-query-functions 'my/prevent-kill-buffer)
   726 (add-to-list 'kill-buffer-query-functions 'my-prevent-kill-buffer)
   727 
   727 
   728 (define-key global-map "\C-v" nil)
   728 (define-key global-map "\C-v" nil)
   729 (define-key global-map "\C-vt" (lambda nil (interactive) (switch-to-buffer "*scratch*")))
   729 (define-key global-map "\C-vt" (lambda nil (interactive) (switch-to-buffer "*scratch*")))
   730 
   730 
   731 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   731 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   732 (message "scrolling")
   732 (message "scrolling")
   733 
   733 
   734 (defvar my/scroll-margin 4)
   734 (defvar my-scroll-margin 4)
   735 
   735 
   736 (setq-default
   736 (setq-default
   737  ;; Set to zero as this recommend documentation.
   737  ;; Set to zero as this recommend documentation.
   738  scroll-step 0
   738  scroll-step 0
   739  ;; If the value is greater than 100, redisplay will never recenter point, but
   739  ;; If the value is greater than 100, redisplay will never recenter point, but
   742  scroll-preserve-screen-position t
   742  scroll-preserve-screen-position t
   743  )
   743  )
   744 
   744 
   745 ;; Set margin only for desired modes! Do not frustrate calendar any more.
   745 ;; Set margin only for desired modes! Do not frustrate calendar any more.
   746 (make-variable-buffer-local 'scroll-margin)
   746 (make-variable-buffer-local 'scroll-margin)
   747 (mapc (lambda (hook) (add-hook hook (lambda nil (setq scroll-margin my/scroll-margin))))
   747 (mapc (lambda (hook) (add-hook hook (lambda nil (setq scroll-margin my-scroll-margin))))
   748       (delete-dups (append my/text-mode-hook-list my/devel-mode-hook-list my/scroll-margin-mode-hook-list)) )
   748       (delete-dups (append my-text-mode-hook-list my-devel-mode-hook-list my-scroll-margin-mode-hook-list)) )
   749 
   749 
   750 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   750 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   751 (message "chars, unicode")
   751 (message "chars, unicode")
   752 
   752 
   753 (defun my/print-unicode (&optional start end)
   753 (defun my-print-unicode (&optional start end)
   754   "Print UNICODE table."
   754   "Print UNICODE table."
   755   (interactive "nstart: \nnend: ")
   755   (interactive "nstart: \nnend: ")
   756   (switch-to-buffer (get-buffer-create "*UNICODE*"))
   756   (switch-to-buffer (get-buffer-create "*UNICODE*"))
   757   (erase-buffer)
   757   (erase-buffer)
   758   (let ( (i start) )
   758   (let ( (i start) )
   802     (add-to-list 'grep-find-ignored-files "*TAGS")
   802     (add-to-list 'grep-find-ignored-files "*TAGS")
   803     (add-to-list 'grep-find-ignored-files "GPATH")) )
   803     (add-to-list 'grep-find-ignored-files "GPATH")) )
   804 
   804 
   805 (global-set-key [M-f7] 'rgrep)
   805 (global-set-key [M-f7] 'rgrep)
   806 
   806 
   807 (global-set-key [f7] 'my/ag)
   807 (global-set-key [f7] 'my-ag)
   808 (global-set-key [S-f7] 'my/ag-default-directory)
   808 (global-set-key [S-f7] 'my-ag-default-directory)
   809 
   809 
   810 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   810 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   811 (message "highlighting")
   811 (message "highlighting")
   812 
   812 
   813 ;; Increase scrolling speed by defer consuming operation.
   813 ;; Increase scrolling speed by defer consuming operation.
   851 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   851 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   852 (message "highlighting current line")
   852 (message "highlighting current line")
   853 
   853 
   854 (require 'hl-line)
   854 (require 'hl-line)
   855 
   855 
   856 (defun my/hl-line-range-function ()
   856 (defun my-hl-line-range-function ()
   857   (cons (line-end-position) (line-beginning-position 2)))
   857   (cons (line-end-position) (line-beginning-position 2)))
   858 (setq hl-line-range-function #'my/hl-line-range-function)
   858 (setq hl-line-range-function #'my-hl-line-range-function)
   859 
   859 
   860 (set-face-attribute 'hl-line nil :inherit nil :background "light yellow")
   860 (set-face-attribute 'hl-line nil :inherit nil :background "light yellow")
   861 (setq global-hl-line-sticky-flag t)
   861 (setq global-hl-line-sticky-flag t)
   862 (global-hl-line-mode 1)
   862 (global-hl-line-mode 1)
   863 
   863 
   879 ;; cyrillic-jis-russian  for 567 is :,.
   879 ;; cyrillic-jis-russian  for 567 is :,.
   880 ;; cyrillic-jcuken  for SHIFT 567 is :,.
   880 ;; cyrillic-jcuken  for SHIFT 567 is :,.
   881 ;; russian-computer for SHIFT 567 is %^&
   881 ;; russian-computer for SHIFT 567 is %^&
   882 (setq default-input-method 'russian-computer)
   882 (setq default-input-method 'russian-computer)
   883 
   883 
   884 (defun my/toggle-input-method (&optional arg)
   884 (defun my-toggle-input-method (&optional arg)
   885   (interactive "P")
   885   (interactive "P")
   886   (if (numberp arg)
   886   (if (numberp arg)
   887       (cond
   887       (cond
   888        ((eq arg 1)
   888        ((eq arg 1)
   889         (activate-input-method nil))
   889         (activate-input-method nil))
   897         (activate-input-method 'ipa-x-sampa))
   897         (activate-input-method 'ipa-x-sampa))
   898        ((eq arg 6)
   898        ((eq arg 6)
   899         (activate-input-method 'TeX)) )
   899         (activate-input-method 'TeX)) )
   900     (toggle-input-method arg)) )
   900     (toggle-input-method arg)) )
   901 
   901 
   902 (global-set-key (kbd "C-\\") 'my/toggle-input-method)
   902 (global-set-key (kbd "C-\\") 'my-toggle-input-method)
   903 
   903 
   904 ;; I found this more quick method to allow `forward-word' across pronunciation
   904 ;; I found this more quick method to allow `forward-word' across pronunciation
   905 ;; as a whole word.
   905 ;; as a whole word.
   906 (defconst my/ipa-chars (list ?ˈ ?ˌ ?ː ?ǁ ?ʲ ?θ ?ð ?ŋ ?ɡ ?ʒ ?ʃ ?ʧ ?ə ?ɜ ?ɛ ?ʌ ?ɒ ?ɔ ?ɑ ?æ ?ʊ ?ɪ))
   906 (defconst my-ipa-chars (list ?ˈ ?ˌ ?ː ?ǁ ?ʲ ?θ ?ð ?ŋ ?ɡ ?ʒ ?ʃ ?ʧ ?ə ?ɜ ?ɛ ?ʌ ?ɒ ?ɔ ?ɑ ?æ ?ʊ ?ɪ))
   907 (when (boundp 'char-script-table)       ; Absent in Emacs 22.
   907 (when (boundp 'char-script-table)       ; Absent in Emacs 22.
   908   (mapc (lambda (ch)
   908   (mapc (lambda (ch)
   909           (aset char-script-table ch 'latin)
   909           (aset char-script-table ch 'latin)
   910           (modify-syntax-entry ch "w"))
   910           (modify-syntax-entry ch "w"))
   911         my/ipa-chars))
   911         my-ipa-chars))
   912 ;; Another option is to invent new category:
   912 ;; Another option is to invent new category:
   913 ;;
   913 ;;
   914 ;; (defconst my/ipa-chars (list ?ˈ ?ˌ ?ː ?ǁ ?ʲ ?θ ?ð ?ŋ ?ɡ ?ʒ ?ʃ ?ʧ ?ə ?ɜ ?ɛ ?ʌ ?ɒ ?ɔ ?ɑ ?æ ?ʊ ?ɪ))
   914 ;; (defconst my-ipa-chars (list ?ˈ ?ˌ ?ː ?ǁ ?ʲ ?θ ?ð ?ŋ ?ɡ ?ʒ ?ʃ ?ʧ ?ə ?ɜ ?ɛ ?ʌ ?ɒ ?ɔ ?ɑ ?æ ?ʊ ?ɪ))
   915 ;; (define-category ?p "Phonetic")
   915 ;; (define-category ?p "Phonetic")
   916 ;; (mapc (lambda (ch)
   916 ;; (mapc (lambda (ch)
   917 ;;         (cond
   917 ;;         (cond
   918 ;;          ((eq (aref char-script-table ch) 'phonetic)
   918 ;;          ((eq (aref char-script-table ch) 'phonetic)
   919 ;;           (modify-category-entry ch ?p)
   919 ;;           (modify-category-entry ch ?p)
   920 ;;           (modify-category-entry ch ?l nil t))
   920 ;;           (modify-category-entry ch ?l nil t))
   921 ;;          ((eq (aref char-script-table ch) 'latin)   ; (aref char-script-table ?ˌ) is 'latin but (char-category-set ?ˌ) is ".j"
   921 ;;          ((eq (aref char-script-table ch) 'latin)   ; (aref char-script-table ?ˌ) is 'latin but (char-category-set ?ˌ) is ".j"
   922 ;;           (modify-category-entry ch ?l))))
   922 ;;           (modify-category-entry ch ?l))))
   923 ;;       my/ipa-chars)
   923 ;;       my-ipa-chars)
   924 ;; (add-to-list 'word-combining-categories '(?p . ?l))
   924 ;; (add-to-list 'word-combining-categories '(?p . ?l))
   925 ;; (add-to-list 'word-combining-categories '(?l . ?p))
   925 ;; (add-to-list 'word-combining-categories '(?l . ?p))
   926 
   926 
   927 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   927 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
   928 (message "mouse")
   928 (message "mouse")
  1103 
  1103 
  1104 (defun my--large-file-p ()
  1104 (defun my--large-file-p ()
  1105   "If buffer too large and my cause performance issue."
  1105   "If buffer too large and my cause performance issue."
  1106   (< large-file-warning-threshold (buffer-size)))
  1106   (< large-file-warning-threshold (buffer-size)))
  1107 
  1107 
  1108 (define-derived-mode my/large-file-mode fundamental-mode "LargeFile"
  1108 (define-derived-mode my-large-file-mode fundamental-mode "LargeFile"
  1109   "Fixes performance issues in Emacs for large files."
  1109   "Fixes performance issues in Emacs for large files."
  1110   ;; (setq buffer-read-only t)
  1110   ;; (setq buffer-read-only t)
  1111   (setq bidi-display-reordering nil)
  1111   (setq bidi-display-reordering nil)
  1112   (jit-lock-mode nil)
  1112   (jit-lock-mode nil)
  1113   (buffer-disable-undo)
  1113   (buffer-disable-undo)
  1115   ;; (setq mode-line-format (delq 'mode-line-position 'mode-line-format))
  1115   ;; (setq mode-line-format (delq 'mode-line-position 'mode-line-format))
  1116   (set (make-local-variable 'global-hl-line-mode) nil)
  1116   (set (make-local-variable 'global-hl-line-mode) nil)
  1117   (set (make-local-variable 'line-number-mode) nil)
  1117   (set (make-local-variable 'line-number-mode) nil)
  1118   (set (make-local-variable 'column-number-mode) nil) )
  1118   (set (make-local-variable 'column-number-mode) nil) )
  1119 
  1119 
  1120 (add-to-list 'magic-mode-alist (cons #'my--large-file-p #'my/large-file-mode))
  1120 (add-to-list 'magic-mode-alist (cons #'my--large-file-p #'my-large-file-mode))
  1121 
  1121 
  1122 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1122 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1123 (message "helm")
  1123 (message "helm")
  1124 
  1124 
  1125 (eval-when 'compile
  1125 (eval-when 'compile
  1140 (setq company-dabbrev-downcase nil)
  1140 (setq company-dabbrev-downcase nil)
  1141 (setq company-dabbrev-ignore-case nil)
  1141 (setq company-dabbrev-ignore-case nil)
  1142 
  1142 
  1143 ;; (setq company-backends (delete 'company-dabbrev company-backends))
  1143 ;; (setq company-backends (delete 'company-dabbrev company-backends))
  1144 
  1144 
  1145 (defun my/company-filter-out-numbers (lst)
  1145 (defun my-company-filter-out-numbers (lst)
  1146   (cl-remove-if (lambda (str) (string-match-p "^[0-9]" str)) lst))
  1146   (cl-remove-if (lambda (str) (string-match-p "^[0-9]" str)) lst))
  1147 
  1147 
  1148 (when (featurep 'company)
  1148 (when (featurep 'company)
  1149   (add-hook 'company-transformers #'my/company-filter-out-numbers))
  1149   (add-hook 'company-transformers #'my-company-filter-out-numbers))
  1150 
  1150 
  1151 (defun company-executable (command &optional arg &rest ignored)
  1151 (defun company-executable (command &optional arg &rest ignored)
  1152   "Company completion for executable in PATH."
  1152   "Company completion for executable in PATH."
  1153   (interactive (list 'interactive))
  1153   (interactive (list 'interactive))
  1154   (cl-case command
  1154   (cl-case command
  1156     (prefix (thing-at-point 'filename))
  1156     (prefix (thing-at-point 'filename))
  1157     (candidates (locate-file-completion-table exec-path exec-suffixes (thing-at-point 'filename) 'identity t))
  1157     (candidates (locate-file-completion-table exec-path exec-suffixes (thing-at-point 'filename) 'identity t))
  1158     ;; (annotation (concat " " (locate-file arg exec-path exec-suffixes)))
  1158     ;; (annotation (concat " " (locate-file arg exec-path exec-suffixes)))
  1159     (meta (concat "Full path: " (locate-file arg exec-path exec-suffixes)))))
  1159     (meta (concat "Full path: " (locate-file arg exec-path exec-suffixes)))))
  1160 
  1160 
  1161 (defun my/company-text-setup ()
  1161 (defun my-company-text-setup ()
  1162   (setq-local company-backends '((company-dabbrev company-files)))
  1162   (setq-local company-backends '((company-dabbrev company-files)))
  1163   (company-mode 1))
  1163   (company-mode 1))
  1164 
  1164 
  1165 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1165 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1166 (message "bookmark")
  1166 (message "bookmark")
  1193 ;; dangerous
  1193 ;; dangerous
  1194 ;; (setq
  1194 ;; (setq
  1195 ;;  dired-recursive-copies 'top
  1195 ;;  dired-recursive-copies 'top
  1196 ;;  dired-recursive-deletes 'top)
  1196 ;;  dired-recursive-deletes 'top)
  1197 
  1197 
  1198 (defun my/dired-up-dir ()
  1198 (defun my-dired-up-dir ()
  1199   "'Reuse' buffer if enter to dir or open new buffer if enter to file."
  1199   "'Reuse' buffer if enter to dir or open new buffer if enter to file."
  1200   (interactive)
  1200   (interactive)
  1201   ;; (dired-current-directory) always end with trailing '/' char.
  1201   ;; (dired-current-directory) always end with trailing '/' char.
  1202   (let* ( (dir (dired-current-directory)) (i (- (length dir) 2)) upperdir )
  1202   (let* ( (dir (dired-current-directory)) (i (- (length dir) 2)) upperdir )
  1203     (while (and
  1203     (while (and
  1209     (when (file-directory-p upperdir)
  1209     (when (file-directory-p upperdir)
  1210       (find-alternate-file upperdir)
  1210       (find-alternate-file upperdir)
  1211       (dired-goto-file dir)
  1211       (dired-goto-file dir)
  1212       )
  1212       )
  1213     ))
  1213     ))
  1214 (define-key dired-mode-map (kbd "<backspace>") 'my/dired-up-dir)
  1214 (define-key dired-mode-map (kbd "<backspace>") 'my-dired-up-dir)
  1215 
  1215 
  1216 (defun my/dired-enter-to-dir ()
  1216 (defun my-dired-enter-to-dir ()
  1217   "'Reuse' buffer if enter to dir or open new buffer if enter to file."
  1217   "'Reuse' buffer if enter to dir or open new buffer if enter to file."
  1218   (interactive)
  1218   (interactive)
  1219   (let ( (file (dired-get-file-for-visit)) )
  1219   (let ( (file (dired-get-file-for-visit)) )
  1220     (if (file-directory-p file)
  1220     (if (file-directory-p file)
  1221         (find-alternate-file file)
  1221         (find-alternate-file file)
  1222       (find-file file)
  1222       (find-file file)
  1223       )))
  1223       )))
  1224 (define-key dired-mode-map (kbd "<return>")
  1224 (define-key dired-mode-map (kbd "<return>")
  1225   'my/dired-enter-to-dir)
  1225   'my-dired-enter-to-dir)
  1226 
  1226 
  1227 ;; Make behaviour same as in GUI.
  1227 ;; Make behaviour same as in GUI.
  1228 (unless window-system
  1228 (unless window-system
  1229   (define-key dired-mode-map (kbd "DEL") 'my/dired-up-dir)
  1229   (define-key dired-mode-map (kbd "DEL") 'my-dired-up-dir)
  1230   (define-key dired-mode-map (kbd "RET") 'my/dired-enter-to-dir))
  1230   (define-key dired-mode-map (kbd "RET") 'my-dired-enter-to-dir))
  1231 
  1231 
  1232 ;; Enable 'a' command.
  1232 ;; Enable 'a' command.
  1233 (put 'dired-find-alternate-file 'disabled nil)
  1233 (put 'dired-find-alternate-file 'disabled nil)
  1234 
  1234 
  1235 (defvar my--file-name-tmp-refex
  1235 (defvar my--file-name-tmp-refex
  1300 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1300 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1301 (message "url")
  1301 (message "url")
  1302 
  1302 
  1303 ;; http://tools.ietf.org/html/rfc3986
  1303 ;; http://tools.ietf.org/html/rfc3986
  1304 ;; http://en.wikipedia.org/wiki/Percent-encoding
  1304 ;; http://en.wikipedia.org/wiki/Percent-encoding
  1305 (defun my/percent-decode (str)
  1305 (defun my-percent-decode (str)
  1306   (decode-coding-string
  1306   (decode-coding-string
  1307    (let* ( (s (split-string str "%")) )
  1307    (let* ( (s (split-string str "%")) )
  1308      (my/fold
  1308      (my-fold
  1309       'concat
  1309       'concat
  1310       (car s)
  1310       (car s)
  1311       (mapcar
  1311       (mapcar
  1312        (lambda (x)
  1312        (lambda (x)
  1313          (concat (unibyte-string (string-to-number (substring x 0 2) 16)) (substring x 2)))
  1313          (concat (unibyte-string (string-to-number (substring x 0 2) 16)) (substring x 2)))
  1314        (cdr s))
  1314        (cdr s))
  1315       )) 'utf-8))
  1315       )) 'utf-8))
  1316 
  1316 
  1317 (defun my/percent-decode-region (beg end &optional arg)
  1317 (defun my-percent-decode-region (beg end &optional arg)
  1318   "Convert percent encoded string to native."
  1318   "Convert percent encoded string to native."
  1319   (interactive "r\nP")
  1319   (interactive "r\nP")
  1320   (let ( (result (my/percent-decode (buffer-substring-no-properties beg end))) )
  1320   (let ( (result (my-percent-decode (buffer-substring-no-properties beg end))) )
  1321     (if (not arg)
  1321     (if (not arg)
  1322         result
  1322         result
  1323       (delete-region beg end)
  1323       (delete-region beg end)
  1324       (insert result))
  1324       (insert result))
  1325     ) )
  1325     ) )
  1326 
  1326 
  1327 (defun my/percent-encode (str)
  1327 (defun my-percent-encode (str)
  1328   (apply 'concat
  1328   (apply 'concat
  1329          (mapcar
  1329          (mapcar
  1330           (lambda (ch) (if (or (and (<= ?a ch) (>= ?z ch))
  1330           (lambda (ch) (if (or (and (<= ?a ch) (>= ?z ch))
  1331                           (and (<= ?A ch) (>= ?Z ch))
  1331                           (and (<= ?A ch) (>= ?Z ch))
  1332                           (memq ch '(?- ?_ ?. ?~)))
  1332                           (memq ch '(?- ?_ ?. ?~)))
  1333                       (char-to-string ch)
  1333                       (char-to-string ch)
  1334                     (format "%%%02X" ch)))
  1334                     (format "%%%02X" ch)))
  1335           (encode-coding-string str 'utf-8) )))
  1335           (encode-coding-string str 'utf-8) )))
  1336 
  1336 
  1337 (defun my/percent-encode-region (beg end &optional arg)
  1337 (defun my-percent-encode-region (beg end &optional arg)
  1338   "Encode string to percent encoding."
  1338   "Encode string to percent encoding."
  1339   (interactive "r\nP")
  1339   (interactive "r\nP")
  1340   (let ( (result (my/percent-encode (buffer-substring-no-properties beg end))) )
  1340   (let ( (result (my-percent-encode (buffer-substring-no-properties beg end))) )
  1341     (if (not arg)
  1341     (if (not arg)
  1342         result
  1342         result
  1343       (delete-region beg end)
  1343       (delete-region beg end)
  1344       (insert result))
  1344       (insert result))
  1345     ) )
  1345     ) )
  1353  ((boundp 'debian-emacs-flavor)
  1353  ((boundp 'debian-emacs-flavor)
  1354   (setq browse-url-browser-function 'browse-url-firefox))
  1354   (setq browse-url-browser-function 'browse-url-firefox))
  1355  (t
  1355  (t
  1356   (setq browse-url-browser-function 'browse-url-mozilla)))
  1356   (setq browse-url-browser-function 'browse-url-mozilla)))
  1357 
  1357 
  1358 (defun my/cygwin-search (str)
  1358 (defun my-cygwin-search (str)
  1359   "Search for Cygwin package on-line."
  1359   "Search for Cygwin package on-line."
  1360   (interactive (list (read-string "Search for Cygwin package on-line: ")))
  1360   (interactive (list (read-string "Search for Cygwin package on-line: ")))
  1361   (browse-url (format "http://cygwin.com/cgi-bin2/package-grep.cgi?grep=%s" str))
  1361   (browse-url (format "http://cygwin.com/cgi-bin2/package-grep.cgi?grep=%s" str))
  1362   )
  1362   )
  1363 
  1363 
  1432 (add-hook 'write-file-hooks 'time-stamp)
  1432 (add-hook 'write-file-hooks 'time-stamp)
  1433 
  1433 
  1434 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1434 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1435 (message "logging, logs")
  1435 (message "logging, logs")
  1436 
  1436 
  1437 (defun my/auto-revert-tail-mode-hook ()
  1437 (defun my-auto-revert-tail-mode-hook ()
  1438   (when (string-match "/logs?/\\|\\.\\(?:log\\|out\\)\\'\\|/.xsession-errors\\'"
  1438   (when (string-match "/logs?/\\|\\.\\(?:log\\|out\\)\\'\\|/.xsession-errors\\'"
  1439                       (buffer-file-name (current-buffer)))
  1439                       (buffer-file-name (current-buffer)))
  1440     (auto-revert-tail-mode 1)
  1440     (auto-revert-tail-mode 1)
  1441     (log4-hi-mode 1)
  1441     (log4-hi-mode 1)
  1442     (setq scroll-margin my/scroll-margin)
  1442     (setq scroll-margin my-scroll-margin)
  1443     ))
  1443     ))
  1444 (add-hook 'find-file-hook 'my/auto-revert-tail-mode-hook)
  1444 (add-hook 'find-file-hook 'my-auto-revert-tail-mode-hook)
  1445 
  1445 
  1446 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1446 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1447 (message "auto-fill")
  1447 (message "auto-fill")
  1448 
  1448 
  1449 (setq-default fill-column 78)
  1449 (setq-default fill-column 78)
  1450 
  1450 
  1451 (defvar my/fill-column 100
  1451 (defvar my-fill-column 100
  1452   "I use greater value then 78 for comment in prog source.")
  1452   "I use greater value then 78 for comment in prog source.")
  1453 
  1453 
  1454 ;; By default used American convention - sentence and with two spaces. Change
  1454 ;; By default used American convention - sentence and with two spaces. Change
  1455 ;; it to one space. Has affect on filling and M-a, M-e commands.
  1455 ;; it to one space. Has affect on filling and M-a, M-e commands.
  1456 (setq sentence-end-double-space nil)
  1456 (setq sentence-end-double-space nil)
  1463 (message "cacl, calculator")
  1463 (message "cacl, calculator")
  1464 
  1464 
  1465 (setq-default calc-group-digits t)
  1465 (setq-default calc-group-digits t)
  1466 (setq-default calc-group-char "'")
  1466 (setq-default calc-group-char "'")
  1467 
  1467 
  1468 (defun my/calc-region (arg beg end)
  1468 (defun my-calc-region (arg beg end)
  1469   "Calculate the region and display the result in the echo area.
  1469   "Calculate the region and display the result in the echo area.
  1470 With prefix ARG non-nil, insert the result at the end of region."
  1470 With prefix ARG non-nil, insert the result at the end of region."
  1471   (interactive "P\nr")
  1471   (interactive "P\nr")
  1472   (require 'calc)
  1472   (require 'calc)
  1473   (let* ((expr (buffer-substring-no-properties beg end))
  1473   (let* ((expr (buffer-substring-no-properties beg end))
  1476         (message "%s = %s" expr result)
  1476         (message "%s = %s" expr result)
  1477       (goto-char end)
  1477       (goto-char end)
  1478       (save-excursion
  1478       (save-excursion
  1479         (insert result)))))
  1479         (insert result)))))
  1480 
  1480 
  1481 (defun my/calc-line (arg)
  1481 (defun my-calc-line (arg)
  1482   "Evaluate expression in current line and display the result in
  1482   "Evaluate expression in current line and display the result in
  1483 the echo area by skipping final '=' sign. With prefix ARG
  1483 the echo area by skipping final '=' sign. With prefix ARG
  1484 non-nil, insert the result at the end of line and space if
  1484 non-nil, insert the result at the end of line and space if
  1485 necessary for delimiting."
  1485 necessary for delimiting."
  1486   (interactive "P")
  1486   (interactive "P")
  1524 
  1524 
  1525 (when (featurep 'flyspell)
  1525 (when (featurep 'flyspell)
  1526   (add-hook 'rst-mode-hook #'flyspell-mode))
  1526   (add-hook 'rst-mode-hook #'flyspell-mode))
  1527 
  1527 
  1528 (when (featurep 'company)
  1528 (when (featurep 'company)
  1529   (add-hook 'rst-mode-hook #'my/company-text-setup))
  1529   (add-hook 'rst-mode-hook #'my-company-text-setup))
  1530 
  1530 
  1531 ;; (add-hook 'rst-mode-hook #'abbrev-mode)
  1531 ;; (add-hook 'rst-mode-hook #'abbrev-mode)
  1532 ;; (remove-hook 'rst-mode-hook #'abbrev-mode)
  1532 ;; (remove-hook 'rst-mode-hook #'abbrev-mode)
  1533 
  1533 
  1534 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1534 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1607   (let ( (path-separator ":") )
  1607   (let ( (path-separator ":") )
  1608     (require 'info)
  1608     (require 'info)
  1609     (info-initialize) ))
  1609     (info-initialize) ))
  1610 
  1610 
  1611 ;; Info index nodes for automake under Debian.
  1611 ;; Info index nodes for automake under Debian.
  1612 (defvar my/fix-for-automake-info-lookup
  1612 (defvar my-fix-for-automake-info-lookup
  1613   '(("(automake-1.11)Macro Index" nil
  1613   '(("(automake-1.11)Macro Index" nil
  1614      "^`" "['(]")
  1614      "^`" "['(]")
  1615     ("(automake-1.11)Variable Index" nil
  1615     ("(automake-1.11)Variable Index" nil
  1616      "^`" "['(]")
  1616      "^`" "['(]")
  1617     ("(automake-1.11)General Index" nil
  1617     ("(automake-1.11)General Index" nil
  1618      "^`" "['(]")))
  1618      "^`" "['(]")))
  1619 
  1619 
  1620 ;; Add `my/fix-for-automake-info-lookup' entries to the end of doc-spec for
  1620 ;; Add `my-fix-for-automake-info-lookup' entries to the end of doc-spec for
  1621 ;; some modes.
  1621 ;; some modes.
  1622 (my--eval-after-load info-look
  1622 (my--eval-after-load info-look
  1623   (mapc
  1623   (mapc
  1624    (lambda (mode)
  1624    (lambda (mode)
  1625      (let ( (doc-spec (info-lookup->doc-spec 'symbol mode)) )
  1625      (let ( (doc-spec (info-lookup->doc-spec 'symbol mode)) )
  1626        (mapc
  1626        (mapc
  1627         (lambda (doc-spec-item)
  1627         (lambda (doc-spec-item)
  1628           (setcdr (last doc-spec) (list doc-spec-item)))
  1628           (setcdr (last doc-spec) (list doc-spec-item)))
  1629         my/fix-for-automake-info-lookup)))
  1629         my-fix-for-automake-info-lookup)))
  1630    '(makefile-mode autoconf-mode))
  1630    '(makefile-mode autoconf-mode))
  1631   (info-lookup-maybe-add-help
  1631   (info-lookup-maybe-add-help
  1632    :mode 'makefile-gmake-mode
  1632    :mode 'makefile-gmake-mode
  1633    :other-modes '(makefile-mode)))
  1633    :other-modes '(makefile-mode)))
  1634 
  1634 
  1676 (add-hook 'gadict-mode-hook 'whitespace-mode)
  1676 (add-hook 'gadict-mode-hook 'whitespace-mode)
  1677 
  1677 
  1678 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1678 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1679 (message "figlet")
  1679 (message "figlet")
  1680 
  1680 
  1681 (defun my/figlet-region (&optional b e)
  1681 (defun my-figlet-region (&optional b e)
  1682   (interactive "r")
  1682   (interactive "r")
  1683   (shell-command-on-region b e "figlet" (current-buffer) t)
  1683   (shell-command-on-region b e "figlet" (current-buffer) t)
  1684   (comment-region (mark) (point)))
  1684   (comment-region (mark) (point)))
  1685 
  1685 
  1686 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1686 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1693   (require 'org-agenda)
  1693   (require 'org-agenda)
  1694   (require 'org-archive))
  1694   (require 'org-archive))
  1695 
  1695 
  1696 ;; XXX org-todo-keywords '((sequence "TODO" "START" "|" "DONE")) for org-version 4.67c
  1696 ;; XXX org-todo-keywords '((sequence "TODO" "START" "|" "DONE")) for org-version 4.67c
  1697 (add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
  1697 (add-to-list 'auto-mode-alist '("\\.org$" . org-mode))
  1698 (setq org-directory "~/my/gtd")
  1698 (setq org-directory "~/my-gtd")
  1699 (setq
  1699 (setq
  1700  org-agenda-ndays 31
  1700  org-agenda-ndays 31
  1701  org-deadline-warning-days 7
  1701  org-deadline-warning-days 7
  1702  org-agenda-show-all-dates t
  1702  org-agenda-show-all-dates t
  1703  org-agenda-format-date "%Y-%m-%d, %A %e %B"
  1703  org-agenda-format-date "%Y-%m-%d, %A %e %B"
  1707  org-reverse-note-order t
  1707  org-reverse-note-order t
  1708  org-hide-leading-stars t
  1708  org-hide-leading-stars t
  1709  org-tags-column 64
  1709  org-tags-column 64
  1710  org-archive-save-context-info '(time file olpath todo itags)
  1710  org-archive-save-context-info '(time file olpath todo itags)
  1711  )
  1711  )
  1712 (defvar my/org-agenda-todo-file (concat org-directory "/TODO.org"))
  1712 (defvar my-org-agenda-todo-file (concat org-directory "/TODO.org"))
  1713 (defvar my/org-agenda-note-file (concat org-directory "/NOTE.org"))
  1713 (defvar my-org-agenda-note-file (concat org-directory "/NOTE.org"))
  1714 (setq org-agenda-file-regexp "\\`[^.#].*[^_]\\.org\\'"
  1714 (setq org-agenda-file-regexp "\\`[^.#].*[^_]\\.org\\'"
  1715       org-agenda-files (list org-directory))
  1715       org-agenda-files (list org-directory))
  1716 ;; (setq my/org-agenda-learning-file (concat org-directory "/LEARNING.org"))
  1716 ;; (setq my-org-agenda-learning-file (concat org-directory "/LEARNING.org"))
  1717 ;; (setq org-agenda-files `(,my/org-agenda-todo-file ,my/org-agenda-note-file ,my/org-agenda-learning-file))
  1717 ;; (setq org-agenda-files `(,my-org-agenda-todo-file ,my-org-agenda-note-file ,my-org-agenda-learning-file))
  1718 (define-key global-map "\C-va" 'org-agenda)
  1718 (define-key global-map "\C-va" 'org-agenda)
  1719 (define-key global-map "\C-ve" (lambda nil (interactive) (find-file my/org-agenda-note-file)))
  1719 (define-key global-map "\C-ve" (lambda nil (interactive) (find-file my-org-agenda-note-file)))
  1720 
  1720 
  1721 (setq org-todo-keywords '("|" "DONE"))
  1721 (setq org-todo-keywords '("|" "DONE"))
  1722 
  1722 
  1723 ;; My tags for remember buffer.
  1723 ;; My tags for remember buffer.
  1724 (setq org-tag-alist
  1724 (setq org-tag-alist
  1740 ;; `org-tag-alist' instead until bug fixed.
  1740 ;; `org-tag-alist' instead until bug fixed.
  1741 (setq org-tag-persistent-alist nil)
  1741 (setq org-tag-persistent-alist nil)
  1742 
  1742 
  1743 (setq org-support-shift-select t)
  1743 (setq org-support-shift-select t)
  1744 
  1744 
  1745 (setq org-default-notes-file my/org-agenda-todo-file)
  1745 (setq org-default-notes-file my-org-agenda-todo-file)
  1746 (setq org-capture-templates
  1746 (setq org-capture-templates
  1747       '(("t" "Todo" entry (file my/org-agenda-todo-file) "* %?\n  SCHEDULED: %T")))
  1747       '(("t" "Todo" entry (file my-org-agenda-todo-file) "* %?\n  SCHEDULED: %T")))
  1748 (define-key global-map "\C-vr"
  1748 (define-key global-map "\C-vr"
  1749   (lambda () (interactive) (org-capture nil "t")))
  1749   (lambda () (interactive) (org-capture nil "t")))
  1750 
  1750 
  1751 (when (featurep 'company)
  1751 (when (featurep 'company)
  1752   (add-hook 'org-mode-hook #'my/company-text-setup))
  1752   (add-hook 'org-mode-hook #'my-company-text-setup))
  1753 
  1753 
  1754 (defun my/org-archive-location (path)
  1754 (defun my-org-archive-location (path)
  1755   "For given PATH make path to archive. Currently add undescore
  1755   "For given PATH make path to archive. Currently add undescore
  1756 before file extention. If file name doesn't match
  1756 before file extention. If file name doesn't match
  1757 `org-agenda-file-regexp' or have no extention return `nil'."
  1757 `org-agenda-file-regexp' or have no extention return `nil'."
  1758   (if (and (file-name-extension path)
  1758   (if (and (file-name-extension path)
  1759            (string-match org-agenda-file-regexp (file-name-nondirectory path)))
  1759            (string-match org-agenda-file-regexp (file-name-nondirectory path)))
  1760       (concat (file-name-sans-extension path) "_." (file-name-extension path))
  1760       (concat (file-name-sans-extension path) "_." (file-name-extension path))
  1761     nil))
  1761     nil))
  1762 
  1762 
  1763 (defun my/org-archive-file (path)
  1763 (defun my-org-archive-file (path)
  1764   "Move marked by `org-done-keywords' entries to archive file.
  1764   "Move marked by `org-done-keywords' entries to archive file.
  1765 
  1765 
  1766 Archive file name constructed by `my/org-archive-location'."
  1766 Archive file name constructed by `my-org-archive-location'."
  1767   (let ( (archive (my/org-archive-location path))
  1767   (let ( (archive (my-org-archive-location path))
  1768          entry-re entry-done-re
  1768          entry-re entry-done-re
  1769          entry-beg entry-end )
  1769          entry-beg entry-end )
  1770     (unless archive
  1770     (unless archive
  1771       (error "'%s' looks like a non-org file..." path))
  1771       (error "'%s' looks like a non-org file..." path))
  1772     (save-excursion
  1772     (save-excursion
  1791             (insert ?\n)
  1791             (insert ?\n)
  1792             (yank)
  1792             (yank)
  1793             (save-buffer))
  1793             (save-buffer))
  1794           (save-buffer) )))))
  1794           (save-buffer) )))))
  1795 
  1795 
  1796 (defun my/org-archive (&optional prefix)
  1796 (defun my-org-archive (&optional prefix)
  1797   "Move all entries marked by `org-done-keywords' to archive
  1797   "Move all entries marked by `org-done-keywords' to archive
  1798 files with name mangled by `my/org-archive-location'.
  1798 files with name mangled by `my-org-archive-location'.
  1799 
  1799 
  1800 Without prefix work on current file. With prefix work on
  1800 Without prefix work on current file. With prefix work on
  1801 `org-agenda-files'."
  1801 `org-agenda-files'."
  1802   (interactive "P")
  1802   (interactive "P")
  1803   (loop for file in (if prefix (org-agenda-files) (list (buffer-file-name))) do
  1803   (loop for file in (if prefix (org-agenda-files) (list (buffer-file-name))) do
  1804         (my/org-archive-file file)))
  1804         (my-org-archive-file file)))
  1805 
  1805 
  1806 (setq org-agenda-include-diary nil)
  1806 (setq org-agenda-include-diary nil)
  1807 
  1807 
  1808 (defun my/org-kill-by-tag (tag)
  1808 (defun my-org-kill-by-tag (tag)
  1809   "Put all entries that matches TAG from current org-file to `kill-ring'."
  1809   "Put all entries that matches TAG from current org-file to `kill-ring'."
  1810   (interactive (list (completing-read "Enter tag: " (org-get-buffer-tags))))
  1810   (interactive (list (completing-read "Enter tag: " (org-get-buffer-tags))))
  1811   (let ( rs (last-command 'kill-region) )
  1811   (let ( rs (last-command 'kill-region) )
  1812     (setq rs (org-scan-tags
  1812     (setq rs (org-scan-tags
  1813               (lambda ()
  1813               (lambda ()
  1819       (apply #'kill-region r))))
  1819       (apply #'kill-region r))))
  1820 
  1820 
  1821 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1821 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1822 (message "TODO, XXX, FIXME highlight")
  1822 (message "TODO, XXX, FIXME highlight")
  1823 
  1823 
  1824 (dolist (mode (append my/devel-mode-list my/text-mode-list))
  1824 (dolist (mode (append my-devel-mode-list my-text-mode-list))
  1825   (font-lock-add-keywords
  1825   (font-lock-add-keywords
  1826    mode
  1826    mode
  1827    `(
  1827    `(
  1828      ( ,(concat "\\<\\(" (regexp-opt '("TODO" "FIX" "FIXME" "HACK" "XXX")) ":?\\)\\>") 1 'font-lock-warning-face t)
  1828      ( ,(concat "\\<\\(" (regexp-opt '("TODO" "FIX" "FIXME" "HACK" "XXX")) ":?\\)\\>") 1 'font-lock-warning-face t)
  1829      ;; 64 times, for highlight C-u C-u C-u <key>
  1829      ;; 64 times, for highlight C-u C-u C-u <key>
  1830      ;; ("\\([^[:space:]]\\)\\1\\{63\\}" 0 'my/contrasty-face t)
  1830      ;; ("\\([^[:space:]]\\)\\1\\{63\\}" 0 'my-contrasty-face t)
  1831      ))
  1831      ))
  1832   )
  1832   )
  1833 
  1833 
  1834 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1834 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  1835 (message "mail, message")
  1835 (message "mail, message")
  1836 
  1836 
  1837 (eval-when 'compile (require 'message))
  1837 (eval-when 'compile (require 'message))
  1838 
  1838 
  1839 (setq mail-user-agent 'message-user-agent)
  1839 (setq mail-user-agent 'message-user-agent)
  1840 
  1840 
  1841 (defun my/compose-mail ()
  1841 (defun my-compose-mail ()
  1842   (interactive)
  1842   (interactive)
  1843   (compose-mail nil nil `(("Organization" . ,(getenv "ORGANIZATION")))))
  1843   (compose-mail nil nil `(("Organization" . ,(getenv "ORGANIZATION")))))
  1844 (global-set-key (kbd "C-x m") #'my/compose-mail)
  1844 (global-set-key (kbd "C-x m") #'my-compose-mail)
  1845 
  1845 
  1846 (setq message-citation-line-format "On %Y-%m-%d, %N wrote:
  1846 (setq message-citation-line-format "On %Y-%m-%d, %N wrote:
  1847 ")
  1847 ")
  1848 (setq message-citation-line-function 'message-insert-formatted-citation-line)
  1848 (setq message-citation-line-function 'message-insert-formatted-citation-line)
  1849 
  1849 
  1861 
  1861 
  1862 (my--eval-after-load message
  1862 (my--eval-after-load message
  1863   (require 'mailabbrev)
  1863   (require 'mailabbrev)
  1864   (define-key message-mode-map "\e\t" 'mail-abbrev-complete-alias))
  1864   (define-key message-mode-map "\e\t" 'mail-abbrev-complete-alias))
  1865 
  1865 
  1866 (defun my/message-mode-hook ()
  1866 (defun my-message-mode-hook ()
  1867   (setq fill-column 78)
  1867   (setq fill-column 78)
  1868   (turn-on-auto-fill)
  1868   (turn-on-auto-fill)
  1869   (flyspell-mode 1))
  1869   (flyspell-mode 1))
  1870 (add-hook 'message-mode-hook 'my/message-mode-hook)
  1870 (add-hook 'message-mode-hook 'my-message-mode-hook)
  1871 
  1871 
  1872 ;; Mark all my messages by "common" string in "Message-Id" field to simplify
  1872 ;; Mark all my messages by "common" string in "Message-Id" field to simplify
  1873 ;; lookup for followups to me.
  1873 ;; lookup for followups to me.
  1874 (setq message-user-fqdn "gavenkoa.example.com")
  1874 (setq message-user-fqdn "gavenkoa.example.com")
  1875 
  1875 
  1944  gnus-backup-startup-file t
  1944  gnus-backup-startup-file t
  1945  gnus-use-dribble-file t
  1945  gnus-use-dribble-file t
  1946  gnus-save-killed-list t
  1946  gnus-save-killed-list t
  1947  )
  1947  )
  1948 
  1948 
  1949 (defun my/kill-gnus ()
  1949 (defun my-kill-gnus ()
  1950   "Kill Gnus when exiting Emacs."
  1950   "Kill Gnus when exiting Emacs."
  1951   (let ( (gnus-interactive-exit nil) )
  1951   (let ( (gnus-interactive-exit nil) )
  1952     (gnus-group-exit)
  1952     (gnus-group-exit)
  1953     ))
  1953     ))
  1954 (my--eval-after-load gnus
  1954 (my--eval-after-load gnus
  1955   (add-hook 'kill-emacs-hook 'my/kill-gnus))
  1955   (add-hook 'kill-emacs-hook 'my-kill-gnus))
  1956 
  1956 
  1957 (my--eval-after-load gnus-art
  1957 (my--eval-after-load gnus-art
  1958   (setq gnus-visible-headers (concat gnus-visible-headers "\\|^Archived-At:\\|^List-URL:\\|^Message-Id:")))
  1958   (setq gnus-visible-headers (concat gnus-visible-headers "\\|^Archived-At:\\|^List-URL:\\|^Message-Id:")))
  1959 
  1959 
  1960 ;; Store gnus specific files to '~/.gnus'.
  1960 ;; Store gnus specific files to '~/.gnus'.
  2030 (eval-when-compile
  2030 (eval-when-compile
  2031   (ignore-errors
  2031   (ignore-errors
  2032     ;; w3m-anchor is macros in newer Emacs, need definition during byte-compilation.
  2032     ;; w3m-anchor is macros in newer Emacs, need definition during byte-compilation.
  2033     (require 'w3m-util)))
  2033     (require 'w3m-util)))
  2034 
  2034 
  2035 (defun my/w3m-view-url ()
  2035 (defun my-w3m-view-url ()
  2036   (interactive)
  2036   (interactive)
  2037   (browse-url (w3m-anchor)))
  2037   (browse-url (w3m-anchor)))
  2038 
  2038 
  2039 (my--eval-after-load w3m
  2039 (my--eval-after-load w3m
  2040   (define-key w3m-minor-mode-map (kbd "RET") #'my/w3m-view-url)
  2040   (define-key w3m-minor-mode-map (kbd "RET") #'my-w3m-view-url)
  2041   (define-key w3m-minor-mode-map (kbd "S-RET") #'w3m-safe-view-this-url)
  2041   (define-key w3m-minor-mode-map (kbd "S-RET") #'w3m-safe-view-this-url)
  2042   (define-key w3m-minor-mode-map (kbd "<left>") #'backward-char)
  2042   (define-key w3m-minor-mode-map (kbd "<left>") #'backward-char)
  2043   (define-key w3m-minor-mode-map (kbd "<right>") #'forward-char)
  2043   (define-key w3m-minor-mode-map (kbd "<right>") #'forward-char)
  2044   (define-key w3m-minor-mode-map (kbd "<up>") #'previous-line)
  2044   (define-key w3m-minor-mode-map (kbd "<up>") #'previous-line)
  2045   (define-key w3m-minor-mode-map (kbd "<down>") #'next-line))
  2045   (define-key w3m-minor-mode-map (kbd "<down>") #'next-line))
  2162 ;; Increase the score for followups to a sent article.
  2162 ;; Increase the score for followups to a sent article.
  2163 (my--eval-after-load gnus-score
  2163 (my--eval-after-load gnus-score
  2164   ;; (add-hook 'message-sent-hook 'gnus-score-followup-article)
  2164   ;; (add-hook 'message-sent-hook 'gnus-score-followup-article)
  2165   (add-hook 'message-sent-hook 'gnus-score-followup-thread))
  2165   (add-hook 'message-sent-hook 'gnus-score-followup-thread))
  2166 
  2166 
  2167 (defvar my/gnus-summary-kill-same-subject-min-len 8
  2167 (defvar my-gnus-summary-kill-same-subject-min-len 8
  2168   "Minimal length of subject string to ignore this subject.")
  2168   "Minimal length of subject string to ignore this subject.")
  2169 (defun my/gnus-summary-kill-same-subject (&optional unmark)
  2169 (defun my-gnus-summary-kill-same-subject (&optional unmark)
  2170   "Add negative scores for all articles with same subject."
  2170   "Add negative scores for all articles with same subject."
  2171   (interactive "P")
  2171   (interactive "P")
  2172   (when (or (not (integerp unmark)) (< 0 unmark))
  2172   (when (or (not (integerp unmark)) (< 0 unmark))
  2173     (let ( (subj (gnus-simplify-subject-fuzzy (gnus-summary-article-subject))) )
  2173     (let ( (subj (gnus-simplify-subject-fuzzy (gnus-summary-article-subject))) )
  2174       (when (<= (length subj) my/gnus-summary-kill-same-subject-min-len)
  2174       (when (<= (length subj) my-gnus-summary-kill-same-subject-min-len)
  2175         (gnus-summary-score-entry
  2175         (gnus-summary-score-entry
  2176          "subject" subj
  2176          "subject" subj
  2177          's (- gnus-score-interactive-default-score) (current-time-string)))))
  2177          's (- gnus-score-interactive-default-score) (current-time-string)))))
  2178   (gnus-summary-kill-same-subject unmark))
  2178   (gnus-summary-kill-same-subject unmark))
  2179 (my--eval-after-load gnus-sum
  2179 (my--eval-after-load gnus-sum
  2180   (define-key gnus-summary-mode-map (kbd "C-k") #'my/gnus-summary-kill-same-subject))
  2180   (define-key gnus-summary-mode-map (kbd "C-k") #'my-gnus-summary-kill-same-subject))
  2181 
  2181 
  2182 (defun my/gnus-mark-thread-as-read ()
  2182 (defun my-gnus-mark-thread-as-read ()
  2183   "Mark unmarked articles in current thread as read and move to
  2183   "Mark unmarked articles in current thread as read and move to
  2184 next thread without selecting article."
  2184 next thread without selecting article."
  2185   (interactive)
  2185   (interactive)
  2186   (gnus-summary-top-thread)
  2186   (gnus-summary-top-thread)
  2187   (catch 'exit
  2187   (catch 'exit
  2189       (when (eq (gnus-summary-article-mark (gnus-summary-article-number)) gnus-unread-mark)
  2189       (when (eq (gnus-summary-article-mark (gnus-summary-article-number)) gnus-unread-mark)
  2190         (gnus-summary-mark-article (gnus-summary-article-number) gnus-del-mark))
  2190         (gnus-summary-mark-article (gnus-summary-article-number) gnus-del-mark))
  2191       (when (or (not (gnus-summary-search-forward)) (eq (gnus-summary-thread-level) 0))
  2191       (when (or (not (gnus-summary-search-forward)) (eq (gnus-summary-thread-level) 0))
  2192         (throw 'exit nil)) )))
  2192         (throw 'exit nil)) )))
  2193 (my--eval-after-load gnus-sum
  2193 (my--eval-after-load gnus-sum
  2194   (define-key gnus-summary-mode-map (kbd "H-k") #'my/gnus-mark-thread-as-read))
  2194   (define-key gnus-summary-mode-map (kbd "H-k") #'my-gnus-mark-thread-as-read))
  2195 
  2195 
  2196 (defun my/gnus-thread-score-function (&rest scores)
  2196 (defun my-gnus-thread-score-function (&rest scores)
  2197   "If any followup have positive score assign greater available
  2197   "If any followup have positive score assign greater available
  2198 score to thread, else assign lesser available score."
  2198 score to thread, else assign lesser available score."
  2199   (let ( (max (apply 'max scores)) (min (apply 'min scores)) )
  2199   (let ( (max (apply 'max scores)) (min (apply 'min scores)) )
  2200     (if (< 0 max) max min)))
  2200     (if (< 0 max) max min)))
  2201 (setq gnus-thread-score-function #'my/gnus-thread-score-function)
  2201 (setq gnus-thread-score-function #'my-gnus-thread-score-function)
  2202 (defun my/gnus-thread-total-score ()
  2202 (defun my-gnus-thread-total-score ()
  2203   "Helper to debug `gnus-thread-score-function' function."
  2203   "Helper to debug `gnus-thread-score-function' function."
  2204   (interactive)
  2204   (interactive)
  2205   (message
  2205   (message
  2206    (int-to-string
  2206    (int-to-string
  2207     (gnus-thread-total-score
  2207     (gnus-thread-total-score
  2208      (gnus-id-to-thread (mail-header-id (gnus-summary-article-header)))))))
  2208      (gnus-id-to-thread (mail-header-id (gnus-summary-article-header)))))))
  2209 
  2209 
  2210 ;; Especially highlight my message and replays to me.
  2210 ;; Especially highlight my message and replays to me.
  2211 (my--eval-after-load gnus-sum
  2211 (my--eval-after-load gnus-sum
  2212   (defface my/gnus-own-unread-face nil
  2212   (defface my-gnus-own-unread-face nil
  2213     "Use this face to display own postings in Summary Buffer"
  2213     "Use this face to display own postings in Summary Buffer"
  2214     :group 'my/gnus)
  2214     :group 'my-gnus)
  2215   (copy-face 'gnus-summary-high-unread-face 'my/gnus-own-unread-face)
  2215   (copy-face 'gnus-summary-high-unread-face 'my-gnus-own-unread-face)
  2216   (set-face-background 'my/gnus-own-unread-face "linen")
  2216   (set-face-background 'my-gnus-own-unread-face "linen")
  2217   (add-to-list 'gnus-summary-highlight
  2217   (add-to-list 'gnus-summary-highlight
  2218                '((and (> score 190) (eq mark gnus-unread-mark)) . my/gnus-own-unread-face))
  2218                '((and (> score 190) (eq mark gnus-unread-mark)) . my-gnus-own-unread-face))
  2219   (defface my/gnus-own-ancient-face nil
  2219   (defface my-gnus-own-ancient-face nil
  2220     "Use this face to display own postings in Summary Buffer"
  2220     "Use this face to display own postings in Summary Buffer"
  2221     :group 'my/gnus)
  2221     :group 'my-gnus)
  2222   (copy-face 'gnus-summary-high-ancient-face 'my/gnus-own-ancient-face)
  2222   (copy-face 'gnus-summary-high-ancient-face 'my-gnus-own-ancient-face)
  2223   (set-face-background 'my/gnus-own-ancient-face "linen")
  2223   (set-face-background 'my-gnus-own-ancient-face "linen")
  2224   (add-to-list 'gnus-summary-highlight
  2224   (add-to-list 'gnus-summary-highlight
  2225                '((and (> score 190) (eq mark gnus-ancient-mark)) . my/gnus-own-ancient-face))
  2225                '((and (> score 190) (eq mark gnus-ancient-mark)) . my-gnus-own-ancient-face))
  2226   (defface my/gnus-own-ticked-face nil
  2226   (defface my-gnus-own-ticked-face nil
  2227     "Use this face to display own postings in Summary Buffer"
  2227     "Use this face to display own postings in Summary Buffer"
  2228     :group 'my/gnus)
  2228     :group 'my-gnus)
  2229   (copy-face 'gnus-summary-high-ticked-face 'my/gnus-own-ticked-face)
  2229   (copy-face 'gnus-summary-high-ticked-face 'my-gnus-own-ticked-face)
  2230   (set-face-background 'my/gnus-own-ticked-face "linen")
  2230   (set-face-background 'my-gnus-own-ticked-face "linen")
  2231   (add-to-list 'gnus-summary-highlight
  2231   (add-to-list 'gnus-summary-highlight
  2232                '((and (> score 190) (or (eq mark gnus-dormant-mark) (eq mark gnus-ticked-mark))) . my/gnus-own-ticked-face))
  2232                '((and (> score 190) (or (eq mark gnus-dormant-mark) (eq mark gnus-ticked-mark))) . my-gnus-own-ticked-face))
  2233   (defface my/gnus-fup-face nil
  2233   (defface my-gnus-fup-face nil
  2234     "Use this face to display direct fups to my postings."
  2234     "Use this face to display direct fups to my postings."
  2235     :group 'my/gnus)
  2235     :group 'my-gnus)
  2236   (copy-face 'gnus-summary-high-unread-face 'my/gnus-fup-face)
  2236   (copy-face 'gnus-summary-high-unread-face 'my-gnus-fup-face)
  2237   (set-face-background 'my/gnus-fup-face "honeydew")
  2237   (set-face-background 'my-gnus-fup-face "honeydew")
  2238   (add-to-list 'gnus-summary-highlight
  2238   (add-to-list 'gnus-summary-highlight
  2239                '((and (<= 90 score) (<= score 110) (eq mark gnus-unread-mark)) . my/gnus-fup-face)) )
  2239                '((and (<= 90 score) (<= score 110) (eq mark gnus-unread-mark)) . my-gnus-fup-face)) )
  2240 
  2240 
  2241 ;; (setq gnus-home-score-file
  2241 ;; (setq gnus-home-score-file
  2242 ;;       ;; All groups that match the regexp `"\\.emacs"'
  2242 ;;       ;; All groups that match the regexp `"\\.emacs"'
  2243 ;;       '(("\\.emacs" "emacs.SCORE")
  2243 ;;       '(("\\.emacs" "emacs.SCORE")
  2244 ;;         ;; All the comp groups in one score file
  2244 ;;         ;; All the comp groups in one score file
  2249   (define-key gnus-summary-mode-map [(meta up)] '(lambda() (interactive) (scroll-other-window -1)))
  2249   (define-key gnus-summary-mode-map [(meta up)] '(lambda() (interactive) (scroll-other-window -1)))
  2250   (define-key gnus-summary-mode-map [(meta down)] '(lambda() (interactive) (scroll-other-window 1)))
  2250   (define-key gnus-summary-mode-map [(meta down)] '(lambda() (interactive) (scroll-other-window 1)))
  2251   (define-key gnus-summary-mode-map [(control down)] 'gnus-summary-next-thread)
  2251   (define-key gnus-summary-mode-map [(control down)] 'gnus-summary-next-thread)
  2252   (define-key gnus-summary-mode-map [(control up)] 'gnus-summary-prev-thread))
  2252   (define-key gnus-summary-mode-map [(control up)] 'gnus-summary-prev-thread))
  2253 
  2253 
  2254 (defun my/gnus-search-web-by-message-id ()
  2254 (defun my-gnus-search-web-by-message-id ()
  2255   "Search for article archive by Message-Id in Google."
  2255   "Search for article archive by Message-Id in Google."
  2256   (interactive)
  2256   (interactive)
  2257   (let ( (msgid (message-fetch-field "Message-Id")) (subj (message-fetch-field "Subject")) )
  2257   (let ( (msgid (message-fetch-field "Message-Id")) (subj (message-fetch-field "Subject")) )
  2258     (setq msgid (replace-regexp-in-string "[<>]" "" msgid))
  2258     (setq msgid (replace-regexp-in-string "[<>]" "" msgid))
  2259     (setq subj (replace-regexp-in-string "[\"#]" " " subj))
  2259     (setq subj (replace-regexp-in-string "[\"#]" " " subj))
  2260     (browse-url (format "https://www.google.com.ua/search?q=%s" (url-encode-url (format "%s OR \"%s\"" msgid subj))))
  2260     (browse-url (format "https://www.google.com.ua/search?q=%s" (url-encode-url (format "%s OR \"%s\"" msgid subj))))
  2261     (browse-url (format "http://mid.mail-archive.com/%s" (url-encode-url msgid)))))
  2261     (browse-url (format "http://mid.mail-archive.com/%s" (url-encode-url msgid)))))
  2262 
  2262 
  2263 (my--eval-after-load gnus-art
  2263 (my--eval-after-load gnus-art
  2264   (define-key gnus-article-mode-map [(control return)] #'my/gnus-search-web-by-message-id))
  2264   (define-key gnus-article-mode-map [(control return)] #'my-gnus-search-web-by-message-id))
  2265 
  2265 
  2266 ;; (setq imap-log t)
  2266 ;; (setq imap-log t)
  2267 
  2267 
  2268 ;; (setq mail-user-agent 'mh-e-user-agent)
  2268 ;; (setq mail-user-agent 'mh-e-user-agent)
  2269 
  2269 
  2298   (when (featurep 'fsm)
  2298   (when (featurep 'fsm)
  2299     (setq fsm-debug nil))               ; Disable *fsm-debug* buffer.
  2299     (setq fsm-debug nil))               ; Disable *fsm-debug* buffer.
  2300   ;; Handle Emacs exit.
  2300   ;; Handle Emacs exit.
  2301   (add-hook 'kill-emacs-hook 'jabber-disconnect))
  2301   (add-hook 'kill-emacs-hook 'jabber-disconnect))
  2302 
  2302 
  2303 (defvar my/chat-prompt "[%t] %n>\n")
  2303 (defvar my-chat-prompt "[%t] %n>\n")
  2304 (setq
  2304 (setq
  2305  jabber-chat-foreign-prompt-format my/chat-prompt
  2305  jabber-chat-foreign-prompt-format my-chat-prompt
  2306  jabber-chat-local-prompt-format my/chat-prompt
  2306  jabber-chat-local-prompt-format my-chat-prompt
  2307  jabber-groupchat-prompt-format my/chat-prompt
  2307  jabber-groupchat-prompt-format my-chat-prompt
  2308  jabber-muc-private-foreign-prompt-format "[%t] %g/%n>\n")
  2308  jabber-muc-private-foreign-prompt-format "[%t] %g/%n>\n")
  2309 
  2309 
  2310 (let ( (mgs-list '("Я тутачки, а где Вы меня ожидали?"
  2310 (let ( (mgs-list '("Я тутачки, а где Вы меня ожидали?"
  2311                    "Software Development == Church Development. Step 1. Build it. Step 2. Pray."
  2311                    "Software Development == Church Development. Step 1. Build it. Step 2. Pray."
  2312                    "Great books aren't written – they're rewritten."
  2312                    "Great books aren't written – they're rewritten."
  2314   (random t)
  2314   (random t)
  2315   (setq jabber-default-show (nth (random (length mgs-list)) mgs-list))
  2315   (setq jabber-default-show (nth (random (length mgs-list)) mgs-list))
  2316   (setq jabber-default-status (nth (random (length mgs-list)) mgs-list))
  2316   (setq jabber-default-status (nth (random (length mgs-list)) mgs-list))
  2317   )
  2317   )
  2318 
  2318 
  2319 (defvar my/jabber-users nil
  2319 (defvar my-jabber-users nil
  2320   "Assoc list of jabber user group. Keys are strings, values are lists of JIDs.")
  2320   "Assoc list of jabber user group. Keys are strings, values are lists of JIDs.")
  2321 
  2321 
  2322 (defun my/jabber-send (group)
  2322 (defun my-jabber-send (group)
  2323   "GROUP is keys from `my/jabber-users'"
  2323   "GROUP is keys from `my-jabber-users'"
  2324   (interactive
  2324   (interactive
  2325    (list (completing-read "Select group: " my/jabber-users))
  2325    (list (completing-read "Select group: " my-jabber-users))
  2326    )
  2326    )
  2327   (let (
  2327   (let (
  2328         (msg (if (use-region-p)
  2328         (msg (if (use-region-p)
  2329                  (buffer-substring (region-beginning) (region-end))
  2329                  (buffer-substring (region-beginning) (region-end))
  2330                (buffer-string)))
  2330                (buffer-string)))
  2333     (deactivate-mark)
  2333     (deactivate-mark)
  2334     (mapc
  2334     (mapc
  2335      (lambda (user)
  2335      (lambda (user)
  2336        (jabber-send-message jc user "" msg "normal")
  2336        (jabber-send-message jc user "" msg "normal")
  2337        )
  2337        )
  2338      (cdr (assoc group my/jabber-users))
  2338      (cdr (assoc group my-jabber-users))
  2339      )
  2339      )
  2340     )
  2340     )
  2341   )
  2341   )
  2342 
  2342 
  2343 (global-set-key (kbd "C-x C-j C-s") 'my/jabber-send)
  2343 (global-set-key (kbd "C-x C-j C-s") 'my-jabber-send)
  2344 
  2344 
  2345 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2345 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2346 (message "erc")
  2346 (message "erc")
  2347 
  2347 
  2348 (eval-when 'compile
  2348 (eval-when 'compile
  2403 
  2403 
  2404 (add-to-list 'magic-mode-alist '(my--c++-header-file-p . c++-mode))
  2404 (add-to-list 'magic-mode-alist '(my--c++-header-file-p . c++-mode))
  2405 
  2405 
  2406 (setq-default comment-style (quote indent))
  2406 (setq-default comment-style (quote indent))
  2407 (setq-default comment-column 44)
  2407 (setq-default comment-column 44)
  2408 (setq-default comment-fill-column my/fill-column)
  2408 (setq-default comment-fill-column my-fill-column)
  2409 
  2409 
  2410 (mapc (lambda (hook) (add-hook hook (lambda () (setq fill-column my/fill-column)) ))
  2410 (mapc (lambda (hook) (add-hook hook (lambda () (setq fill-column my-fill-column)) ))
  2411       (append my/devel-mode-hook-list my/text-mode-hook-list))
  2411       (append my-devel-mode-hook-list my-text-mode-hook-list))
  2412 
  2412 
  2413 (mapc (lambda (mode) (add-hook (my/mode2hook mode) #'hs-minor-mode))
  2413 (mapc (lambda (mode) (add-hook (my-mode2hook mode) #'hs-minor-mode))
  2414       '(c-mode c++-mode java-mode js-mode lisp-mode emacs-lisp-mode))
  2414       '(c-mode c++-mode java-mode js-mode lisp-mode emacs-lisp-mode))
  2415 
  2415 
  2416 (defun my/company-prog-mode-setup ()
  2416 (defun my-company-prog-mode-setup ()
  2417   (setq-local company-dabbrev-code-other-buffers 'code)
  2417   (setq-local company-dabbrev-code-other-buffers 'code)
  2418   (setq-local company-backends '((company-capf company-dabbrev-code company-files)))
  2418   (setq-local company-backends '((company-capf company-dabbrev-code company-files)))
  2419   (company-mode 1))
  2419   (company-mode 1))
  2420 
  2420 
  2421 (when (featurep 'company)
  2421 (when (featurep 'company)
  2422   (add-hook 'prog-mode-hook #'my/company-prog-mode-setup))
  2422   (add-hook 'prog-mode-hook #'my-company-prog-mode-setup))
  2423 
  2423 
  2424 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2424 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2425 (message "diff, patch, ediff, emerge")
  2425 (message "diff, patch, ediff, emerge")
  2426 
  2426 
  2427 (eval-when 'compile (require 'ediff))
  2427 (eval-when 'compile (require 'ediff))
  2433 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
  2433 (setq ediff-window-setup-function 'ediff-setup-windows-plain)
  2434 (setq ediff-split-window-function 'split-window-vertically)
  2434 (setq ediff-split-window-function 'split-window-vertically)
  2435 
  2435 
  2436 ;; Disable: sometimes it take a long time to process large hunks.
  2436 ;; Disable: sometimes it take a long time to process large hunks.
  2437 ;; Use C-c C-b on hunk by own.
  2437 ;; Use C-c C-b on hunk by own.
  2438 ;; (defun my/diff-auto-refine-mode-on () (diff-auto-refine-mode 1))
  2438 ;; (defun my-diff-auto-refine-mode-on () (diff-auto-refine-mode 1))
  2439 ;; (add-hook 'diff-mode-hook 'my/diff-auto-refine-mode-on)
  2439 ;; (add-hook 'diff-mode-hook 'my-diff-auto-refine-mode-on)
  2440 
  2440 
  2441 (when window-system
  2441 (when window-system
  2442   (my--eval-after-load diff-mode
  2442   (my--eval-after-load diff-mode
  2443     (set-face-foreground 'diff-added-face "DarkGreen")
  2443     (set-face-foreground 'diff-added-face "DarkGreen")
  2444     (set-face-foreground 'diff-removed-face "DarkRed")
  2444     (set-face-foreground 'diff-removed-face "DarkRed")
  2453 
  2453 
  2454 ;; `-b' switch to ignore changes in whitespaces.
  2454 ;; `-b' switch to ignore changes in whitespaces.
  2455 ;; (setq vc-git-diff-switches "-b")
  2455 ;; (setq vc-git-diff-switches "-b")
  2456 ;; (setq vc-diff-switches "-b")
  2456 ;; (setq vc-diff-switches "-b")
  2457 
  2457 
  2458 (defun my/vc-root-diff (prefix)
  2458 (defun my-vc-root-diff (prefix)
  2459   "Same as `vc-root-diff' but for Hg with C-u show latest MQ patch and
  2459   "Same as `vc-root-diff' but for Hg with C-u show latest MQ patch and
  2460 with C-u C-u show MQ patch and local changes."
  2460 with C-u C-u show MQ patch and local changes."
  2461   (interactive "P")
  2461   (interactive "P")
  2462   (when (eq 'non-hg-mq
  2462   (when (eq 'non-hg-mq
  2463             (catch 'break
  2463             (catch 'break
  2471                   (vc-diff-internal t (list 'Hg (list rootdir)) "qparent" "qtip"))
  2471                   (vc-diff-internal t (list 'Hg (list rootdir)) "qparent" "qtip"))
  2472                  ((equal prefix '(16))
  2472                  ((equal prefix '(16))
  2473                   (vc-diff-internal t (list 'Hg (list rootdir)) "qparent" nil)) ))))
  2473                   (vc-diff-internal t (list 'Hg (list rootdir)) "qparent" nil)) ))))
  2474     (call-interactively 'vc-root-diff nil) ))
  2474     (call-interactively 'vc-root-diff nil) ))
  2475 
  2475 
  2476 (global-set-key (kbd "C-x v D") 'my/vc-root-diff)
  2476 (global-set-key (kbd "C-x v D") 'my-vc-root-diff)
  2477 
  2477 
  2478 (when window-system
  2478 (when window-system
  2479   (setq
  2479   (setq
  2480    vc-annotate-very-old-color "#0b5b20"
  2480    vc-annotate-very-old-color "#0b5b20"
  2481    vc-annotate-background "white"
  2481    vc-annotate-background "white"
  2499      (320 . "#2780C6")
  2499      (320 . "#2780C6")
  2500      (340 . "#1A00D3")
  2500      (340 . "#1A00D3")
  2501      (360 . "#0D80E0")))
  2501      (360 . "#0D80E0")))
  2502   )
  2502   )
  2503 
  2503 
  2504 (defun my/log-edit-mode-hook ()
  2504 (defun my-log-edit-mode-hook ()
  2505   (setq fill-column 78)
  2505   (setq fill-column 78)
  2506   )
  2506   )
  2507 (add-hook 'log-edit-mode-hook 'my/log-edit-mode-hook t)
  2507 (add-hook 'log-edit-mode-hook 'my-log-edit-mode-hook t)
  2508 
  2508 
  2509 (eval-after-load 'log-edit
  2509 (eval-after-load 'log-edit
  2510   '(remove-hook 'log-edit-hook 'log-edit-insert-message-template))
  2510   '(remove-hook 'log-edit-hook 'log-edit-insert-message-template))
  2511 
  2511 
  2512 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2512 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2561     (add-to-list 'compilation-mode-font-lock-keywords '("\\(/[Oo][Uu][Tt]:[^[:blank:]]+\\)" . 1))
  2561     (add-to-list 'compilation-mode-font-lock-keywords '("\\(/[Oo][Uu][Tt]:[^[:blank:]]+\\)" . 1))
  2562     (add-to-list 'compilation-mode-font-lock-keywords '("[[:blank:]]\\(/F[oe][^[:blank:]]+\\)" . 1))))
  2562     (add-to-list 'compilation-mode-font-lock-keywords '("[[:blank:]]\\(/F[oe][^[:blank:]]+\\)" . 1))))
  2563 
  2563 
  2564 (ignore-errors
  2564 (ignore-errors
  2565   (require 'ansi-color)
  2565   (require 'ansi-color)
  2566   (defun my/colorize-compilation-buffer ()
  2566   (defun my-colorize-compilation-buffer ()
  2567     (when (eq major-mode 'compilation-mode)
  2567     (when (eq major-mode 'compilation-mode)
  2568       (ansi-color-apply-on-region compilation-filter-start (point-max))))
  2568       (ansi-color-apply-on-region compilation-filter-start (point-max))))
  2569   (add-hook 'compilation-filter-hook 'my/colorize-compilation-buffer))
  2569   (add-hook 'compilation-filter-hook 'my-colorize-compilation-buffer))
  2570 
  2570 
  2571 (defvar my/comint-send-hist-list nil
  2571 (defvar my-comint-send-hist-list nil
  2572   "History list for `my/comint-send-string'."
  2572   "History list for `my-comint-send-string'."
  2573   )
  2573   )
  2574 (defun my/comint-send-string (string)
  2574 (defun my-comint-send-string (string)
  2575   "Send string to comint buffers. Useful for *compilation* read-only buffer.
  2575   "Send string to comint buffers. Useful for *compilation* read-only buffer.
  2576 Automaticaly append final newline."
  2576 Automaticaly append final newline."
  2577   (interactive
  2577   (interactive
  2578    (list (read-string "Type string: " nil 'my/comint-send-hist-list))
  2578    (list (read-string "Type string: " nil 'my-comint-send-hist-list))
  2579    )
  2579    )
  2580   (comint-send-string (get-buffer-process (current-buffer)) (concat string "\n"))
  2580   (comint-send-string (get-buffer-process (current-buffer)) (concat string "\n"))
  2581   )
  2581   )
  2582 (my--eval-after-load compile
  2582 (my--eval-after-load compile
  2583   (define-key compilation-mode-map [C-return] 'my/comint-send-string))
  2583   (define-key compilation-mode-map [C-return] 'my-comint-send-string))
  2584 
  2584 
  2585 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2585 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2586 (message "scons")
  2586 (message "scons")
  2587 
  2587 
  2588 (add-to-list 'auto-mode-alist '("SConstruct\\'" . python-mode))
  2588 (add-to-list 'auto-mode-alist '("SConstruct\\'" . python-mode))
  2621   (global-set-key "\M-." 'etags-select-find-tag)
  2621   (global-set-key "\M-." 'etags-select-find-tag)
  2622   )
  2622   )
  2623 
  2623 
  2624 (setq tags-add-tables t)
  2624 (setq tags-add-tables t)
  2625 
  2625 
  2626 (defvar my/ido-tag-history nil
  2626 (defvar my-ido-tag-history nil
  2627   "History of tags selected using `my/ido-complete-tag'.")
  2627   "History of tags selected using `my-ido-complete-tag'.")
  2628 (defun my/ido-complete-tag (&optional substr)
  2628 (defun my-ido-complete-tag (&optional substr)
  2629   "Find a tag using ido."
  2629   "Find a tag using ido."
  2630   (tags-completion-table)
  2630   (tags-completion-table)
  2631   (let ( tag-names )
  2631   (let ( tag-names )
  2632     (mapatoms (lambda (x) (push (symbol-name x) tag-names)) tags-completion-table)
  2632     (mapatoms (lambda (x) (push (symbol-name x) tag-names)) tags-completion-table)
  2633     (ido-completing-read "Tag: " tag-names nil t substr 'my/ido-tag-history)))
  2633     (ido-completing-read "Tag: " tag-names nil t substr 'my-ido-tag-history)))
  2634 (defun my/complete-tag (prefix point)
  2634 (defun my-complete-tag (prefix point)
  2635   (interactive "P\nd")
  2635   (interactive "P\nd")
  2636   (if prefix
  2636   (if prefix
  2637       (funcall #'complete-tag)
  2637       (funcall #'complete-tag)
  2638     (let ( (bounds (find-tag-default-bounds)) tag )
  2638     (let ( (bounds (find-tag-default-bounds)) tag )
  2639       (if (or (not bounds) (< point (car bounds)) (< (cdr bounds) point))
  2639       (if (or (not bounds) (< point (car bounds)) (< (cdr bounds) point))
  2640           (setq tag (my/ido-complete-tag))
  2640           (setq tag (my-ido-complete-tag))
  2641         (setq tag (my/ido-complete-tag (buffer-substring (car bounds) (cdr bounds))))
  2641         (setq tag (my-ido-complete-tag (buffer-substring (car bounds) (cdr bounds))))
  2642         (delete-region (car bounds) (cdr bounds)))
  2642         (delete-region (car bounds) (cdr bounds)))
  2643       (insert tag))))
  2643       (insert tag))))
  2644 
  2644 
  2645 (global-set-key [M-return] #'my/complete-tag)
  2645 (global-set-key [M-return] #'my-complete-tag)
  2646 
  2646 
  2647 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2647 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2648 (message "CEDET, semantic, SRecord")
  2648 (message "CEDET, semantic, SRecord")
  2649 
  2649 
  2650 ;; For debug use 'semantic-debug-idle-function' and 'semantic-debug-idle-work-function'.
  2650 ;; For debug use 'semantic-debug-idle-function' and 'semantic-debug-idle-work-function'.
  2701   (defvar srecode-map-load-path nil)
  2701   (defvar srecode-map-load-path nil)
  2702   (add-to-list 'srecode-map-load-path (locate-user-emacs-file "srecode/"))
  2702   (add-to-list 'srecode-map-load-path (locate-user-emacs-file "srecode/"))
  2703   (global-srecode-minor-mode 1)
  2703   (global-srecode-minor-mode 1)
  2704   (add-hook 'prog-mode-hook 'srecode-minor-mode)
  2704   (add-hook 'prog-mode-hook 'srecode-minor-mode)
  2705 
  2705 
  2706   (defun my/srecode-reload-templates ()
  2706   (defun my-srecode-reload-templates ()
  2707     "Reload all templates under `srecode-map-load-path'. Useful
  2707     "Reload all templates under `srecode-map-load-path'. Useful
  2708 during template developing."
  2708 during template developing."
  2709     (interactive)
  2709     (interactive)
  2710     (setq srecode-mode-table-list nil
  2710     (setq srecode-mode-table-list nil
  2711           srecode-current-map nil)
  2711           srecode-current-map nil)
  2731   ;; (add-to-list 'ede-locate-setup-options 'ede-locate-idutils)
  2731   ;; (add-to-list 'ede-locate-setup-options 'ede-locate-idutils)
  2732   ;; (add-to-list 'ede-locate-setup-options 'ede-locate-global)
  2732   ;; (add-to-list 'ede-locate-setup-options 'ede-locate-global)
  2733 
  2733 
  2734   ;; (ignore-errors (require 'cedet-idutils))
  2734   ;; (ignore-errors (require 'cedet-idutils))
  2735 
  2735 
  2736   (defun my/c-mode-cedet-hook ()
  2736   (defun my-c-mode-cedet-hook ()
  2737     ;; (local-set-key [C-return] 'semantic-complete-symbol)
  2737     ;; (local-set-key [C-return] 'semantic-complete-symbol)
  2738     ;; (local-set-key [C-return] 'semantic-complete-analyze-inline)
  2738     ;; (local-set-key [C-return] 'semantic-complete-analyze-inline)
  2739     ;; (local-set-key "." 'semantic-complete-self-insert)
  2739     ;; (local-set-key "." 'semantic-complete-self-insert)
  2740     ;; (local-set-key ">" 'semantic-complete-self-insert)
  2740     ;; (local-set-key ">" 'semantic-complete-self-insert)
  2741     )
  2741     )
  2742   (add-hook 'c-mode-common-hook 'my/c-mode-cedet-hook)
  2742   (add-hook 'c-mode-common-hook 'my-c-mode-cedet-hook)
  2743 
  2743 
  2744   (ignore-errors
  2744   (ignore-errors
  2745     (require 'semantic/ia)
  2745     (require 'semantic/ia)
  2746     (define-key semantic-mode-map (kbd "C-c , .") 'semantic-ia-fast-jump)
  2746     (define-key semantic-mode-map (kbd "C-c , .") 'semantic-ia-fast-jump)
  2747     (define-key semantic-mode-map (kbd "C-c , d") 'semantic-ia-show-doc)
  2747     (define-key semantic-mode-map (kbd "C-c , d") 'semantic-ia-show-doc)
  2759 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2759 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2760 (message "imenu")
  2760 (message "imenu")
  2761 
  2761 
  2762 (require 'imenu)
  2762 (require 'imenu)
  2763 
  2763 
  2764 (defun my/imenu-to-menubar ()
  2764 (defun my-imenu-to-menubar ()
  2765   "Force imenu building when (menu-bar-mode -1)."
  2765   "Force imenu building when (menu-bar-mode -1)."
  2766   (when imenu-generic-expression
  2766   (when imenu-generic-expression
  2767     (imenu-add-menubar-index)
  2767     (imenu-add-menubar-index)
  2768     (run-hooks 'menu-bar-update-hook) ))
  2768     (run-hooks 'menu-bar-update-hook) ))
  2769 (mapc (lambda (hook) (add-hook hook 'my/imenu-to-menubar))
  2769 (mapc (lambda (hook) (add-hook hook 'my-imenu-to-menubar))
  2770       my/devel-mode-hook-list)
  2770       my-devel-mode-hook-list)
  2771 
  2771 
  2772 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2772 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2773 (message "windows inf files for driver installin")
  2773 (message "windows inf files for driver installin")
  2774 
  2774 
  2775 (add-to-list 'auto-mode-alist '("\\.inf\\'" . conf-mode))
  2775 (add-to-list 'auto-mode-alist '("\\.inf\\'" . conf-mode))
  2783 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2783 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2784 (message "makefile, make")
  2784 (message "makefile, make")
  2785 
  2785 
  2786 (add-to-list 'auto-mode-alist '("\\(Makefile\\|Makefile\\..+\\)\\'" . makefile-gmake-mode) t)
  2786 (add-to-list 'auto-mode-alist '("\\(Makefile\\|Makefile\\..+\\)\\'" . makefile-gmake-mode) t)
  2787 
  2787 
  2788 (defun my/makefile-setup ()
  2788 (defun my-makefile-setup ()
  2789   (add-hook 'completion-at-point-functions 'comint-filename-completion nil t))
  2789   (add-hook 'completion-at-point-functions 'comint-filename-completion nil t))
  2790 
  2790 
  2791 (add-hook 'makefile-mode-hook #'my/makefile-setup)
  2791 (add-hook 'makefile-mode-hook #'my-makefile-setup)
  2792 
  2792 
  2793 (defun my/makefile-company-setup ()
  2793 (defun my-makefile-company-setup ()
  2794   "Limit search for symbols to Makefiles."
  2794   "Limit search for symbols to Makefiles."
  2795   (setq-local company-dabbrev-code-other-buffers t)
  2795   (setq-local company-dabbrev-code-other-buffers t)
  2796   (setq-local company-backends '((company-capf company-dabbrev-code company-files company-executable)))
  2796   (setq-local company-backends '((company-capf company-dabbrev-code company-files company-executable)))
  2797   (company-mode 1))
  2797   (company-mode 1))
  2798 
  2798 
  2799 (when (featurep 'company)
  2799 (when (featurep 'company)
  2800   (add-hook 'makefile-mode-hook #'my/makefile-company-setup))
  2800   (add-hook 'makefile-mode-hook #'my-makefile-company-setup))
  2801 
  2801 
  2802 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2802 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2803 (message "asm, assembler")
  2803 (message "asm, assembler")
  2804 
  2804 
  2805 ;; (setq-default asm-comment-char 59)
  2805 ;; (setq-default asm-comment-char 59)
  2828 ;; Minor mode that highlights suspicious C and C++ constructions.
  2828 ;; Minor mode that highlights suspicious C and C++ constructions.
  2829 (global-cwarn-mode 1)
  2829 (global-cwarn-mode 1)
  2830 
  2830 
  2831 (setq c-echo-syntactic-information-p t)
  2831 (setq c-echo-syntactic-information-p t)
  2832 
  2832 
  2833 (defun my/c-mode-common-hook ()
  2833 (defun my-c-mode-common-hook ()
  2834   ;; Automatically inserte newlines after special characters such as brace, comma, semi-colon, and colon.
  2834   ;; Automatically inserte newlines after special characters such as brace, comma, semi-colon, and colon.
  2835   (c-toggle-auto-newline -1)
  2835   (c-toggle-auto-newline -1)
  2836   ;; Delete all preceding whitespace by DEL.
  2836   ;; Delete all preceding whitespace by DEL.
  2837   (c-toggle-hungry-state -1)
  2837   (c-toggle-hungry-state -1)
  2838   ;; Auto indent after typing colon according to `c-hanging-colons-alist'.
  2838   ;; Auto indent after typing colon according to `c-hanging-colons-alist'.
  2839   (c-toggle-electric-state 1)
  2839   (c-toggle-electric-state 1)
  2840   )
  2840   )
  2841 (add-hook 'c-mode-common-hook 'my/c-mode-common-hook)
  2841 (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
  2842 
  2842 
  2843 (defconst my/c-style
  2843 (defconst my-c-style
  2844   '((c-tab-always-indent . t)
  2844   '((c-tab-always-indent . t)
  2845     (c-comment-only-line-offset . 4)
  2845     (c-comment-only-line-offset . 4)
  2846     (c-hanging-braces-alist
  2846     (c-hanging-braces-alist
  2847      . (
  2847      . (
  2848         (brace-list-open)
  2848         (brace-list-open)
  2886     (c-report-syntactic-errors . t)
  2886     (c-report-syntactic-errors . t)
  2887     ;; Echo syntactic information on TAB in message buffer.
  2887     ;; Echo syntactic information on TAB in message buffer.
  2888     (c-echo-syntactic-information-p . t))
  2888     (c-echo-syntactic-information-p . t))
  2889   "My C Programming Style")
  2889   "My C Programming Style")
  2890 
  2890 
  2891 (defun my/c-mode-style-hook ()
  2891 (defun my-c-mode-style-hook ()
  2892   (c-add-style "my" my/c-style t)
  2892   (c-add-style "my" my-c-style t)
  2893   ;; If set 'c-default-style' before 'c-add-style'
  2893   ;; If set 'c-default-style' before 'c-add-style'
  2894   ;; "Undefined style: my" error occured from 'c-get-style-variables'.
  2894   ;; "Undefined style: my" error occured from 'c-get-style-variables'.
  2895   (setq c-default-style
  2895   (setq c-default-style
  2896         '(
  2896         '(
  2897           (java-mode . "my") (c-mode . "my") (csharp-mode . "my") (c++-mode . "my") (objc-mode . "my")
  2897           (java-mode . "my") (c-mode . "my") (csharp-mode . "my") (c++-mode . "my") (objc-mode . "my")
  2898           (idl-mode . "my")
  2898           (idl-mode . "my")
  2899           (awk-mode . "awk")
  2899           (awk-mode . "awk")
  2900           (other . "my")
  2900           (other . "my")
  2901           ))
  2901           ))
  2902   )
  2902   )
  2903 (add-hook 'c-mode-common-hook 'my/c-mode-style-hook)
  2903 (add-hook 'c-mode-common-hook 'my-c-mode-style-hook)
  2904 
  2904 
  2905 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2905 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2906 (message "python, python-mode")
  2906 (message "python, python-mode")
  2907 
  2907 
  2908 (eval-when 'compile
  2908 (eval-when 'compile
  3018   (add-to-list 'python-shell-setup-codes 'my-python/eldoc-setup-code) ; Used inside (python-shell-send-setup-code)
  3018   (add-to-list 'python-shell-setup-codes 'my-python/eldoc-setup-code) ; Used inside (python-shell-send-setup-code)
  3019   (define-key python-mode-map "\C-c\C-d" 'my-python/eldoc-at-point)
  3019   (define-key python-mode-map "\C-c\C-d" 'my-python/eldoc-at-point)
  3020   (define-key python-mode-map "\C-c\C-g" 'my-python/eldoc-at-point2)
  3020   (define-key python-mode-map "\C-c\C-g" 'my-python/eldoc-at-point2)
  3021   (define-key python-mode-map [?\C-c ?\C-h] 'my-python/send-paragraph))
  3021   (define-key python-mode-map [?\C-c ?\C-h] 'my-python/send-paragraph))
  3022 
  3022 
  3023 (defgroup my/python nil
  3023 (defgroup my-python nil
  3024   "My Python extentions in Emacs."
  3024   "My Python extentions in Emacs."
  3025   :group 'python)
  3025   :group 'python)
  3026 
  3026 
  3027 (defvar my-python/pylint-command "pylint"
  3027 (defvar my-python/pylint-command "pylint"
  3028   "Command to run pylint executable.")
  3028   "Command to run pylint executable.")
  3051     (pyflakes3 . (my-python/pyflakes3-command my-python/pyflakes3-args)))
  3051     (pyflakes3 . (my-python/pyflakes3-command my-python/pyflakes3-args)))
  3052   "Known Python source code checkers.")
  3052   "Known Python source code checkers.")
  3053 
  3053 
  3054 (defcustom my-python/default-checker 'pyflakes
  3054 (defcustom my-python/default-checker 'pyflakes
  3055   "Default Python source code checker. See `my-python/checker-alist' for full alist."
  3055   "Default Python source code checker. See `my-python/checker-alist' for full alist."
  3056   :group 'my/python
  3056   :group 'my-python
  3057   :type (cons 'choice (mapcar (lambda (e) (cons 'const e)) my-python/checker-alist)))
  3057   :type (cons 'choice (mapcar (lambda (e) (cons 'const e)) my-python/checker-alist)))
  3058 
  3058 
  3059 (defvar my-python/check-history nil)
  3059 (defvar my-python/check-history nil)
  3060 
  3060 
  3061 (defun my-python/check (&optional checker)
  3061 (defun my-python/check (&optional checker)
  3088   ;; (pymacs-load "ropemacs" "rope-")
  3088   ;; (pymacs-load "ropemacs" "rope-")
  3089   )
  3089   )
  3090 ;; Automatically save project python buffers before refactorings
  3090 ;; Automatically save project python buffers before refactorings
  3091 (setq ropemacs-confirm-saving 'nil)
  3091 (setq ropemacs-confirm-saving 'nil)
  3092 
  3092 
  3093 (defun my/python-add-to-path (path)
  3093 (defun my-python-add-to-path (path)
  3094   (interactive (list (read-directory-name "Enter new path for PYTHONPATH: ")))
  3094   (interactive (list (read-directory-name "Enter new path for PYTHONPATH: ")))
  3095   (when (featurep 'cygwin-mount)
  3095   (when (featurep 'cygwin-mount)
  3096     (setq path (my/dos2cygwin-path path)))
  3096     (setq path (my-dos2cygwin-path path)))
  3097   (python-send-string (format "import sys; sys.path.append(\"%s\")" (expand-file-name path))) )
  3097   (python-send-string (format "import sys; sys.path.append(\"%s\")" (expand-file-name path))) )
  3098 
  3098 
  3099 (defun my/python-django-fix (path)
  3099 (defun my-python-django-fix (path)
  3100   "XXX not work on Cygwin + naive Emacs."
  3100   "XXX not work on Cygwin + naive Emacs."
  3101   (interactive (list (read-directory-name "Enter new path for PYTHONPATH: ")))
  3101   (interactive (list (read-directory-name "Enter new path for PYTHONPATH: ")))
  3102   (when (featurep 'cygwin-mount)
  3102   (when (featurep 'cygwin-mount)
  3103     (setq path (my/dos2cygwin-path path))
  3103     (setq path (my-dos2cygwin-path path))
  3104     )
  3104     )
  3105   (let ((file (concat path "manage.py")))
  3105   (let ((file (concat path "manage.py")))
  3106     (if (file-exists-p file)
  3106     (if (file-exists-p file)
  3107         (python-send-string (format "import os; os.chdir(\"%s\"); execfile(\"%s\")" path file))
  3107         (python-send-string (format "import os; os.chdir(\"%s\"); execfile(\"%s\")" path file))
  3108       (error (format "file '%s' does not exist" file))
  3108       (error (format "file '%s' does not exist" file))
  3110 
  3110 
  3111 ;; Disable in flavor of Semantic and perfomance reason.
  3111 ;; Disable in flavor of Semantic and perfomance reason.
  3112 ;; (when (>= emacs-major-version 22)
  3112 ;; (when (>= emacs-major-version 22)
  3113 ;;   (add-hook 'python-mode-hook 'turn-on-eldoc-mode)
  3113 ;;   (add-hook 'python-mode-hook 'turn-on-eldoc-mode)
  3114 
  3114 
  3115 (defun my/python-mode-hook ()
  3115 (defun my-python-mode-hook ()
  3116   (when (and (eq window-system 'w32) (fboundp 'prettify-symbols-mode))
  3116   (when (and (eq window-system 'w32) (fboundp 'prettify-symbols-mode))
  3117     (prettify-symbols-mode -1)))
  3117     (prettify-symbols-mode -1)))
  3118 (add-hook 'python-mode-hook 'my/python-mode-hook)
  3118 (add-hook 'python-mode-hook 'my-python-mode-hook)
  3119 
  3119 
  3120 (when (equal window-system 'w32)
  3120 (when (equal window-system 'w32)
  3121   (add-to-list 'process-coding-system-alist '("python" cp1251-unix . cp1251-unix)))
  3121   (add-to-list 'process-coding-system-alist '("python" cp1251-unix . cp1251-unix)))
  3122 
  3122 
  3123 (add-to-list 'auto-mode-alist '("/requirements.txt\\'" . conf-mode))
  3123 (add-to-list 'auto-mode-alist '("/requirements.txt\\'" . conf-mode))
  3184 ;; (add-to-list 'auto-mode-alist '("\\.js$" . c++-mode))
  3184 ;; (add-to-list 'auto-mode-alist '("\\.js$" . c++-mode))
  3185 
  3185 
  3186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3186 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3187 (message "json")
  3187 (message "json")
  3188 
  3188 
  3189 (defun my/json-mode-hook ()
  3189 (defun my-json-mode-hook ()
  3190   (set (make-local-variable 'js-indent-level) 2))
  3190   (set (make-local-variable 'js-indent-level) 2))
  3191 (add-hook 'json-mode-hook #'my/json-mode-hook)
  3191 (add-hook 'json-mode-hook #'my-json-mode-hook)
  3192 
  3192 
  3193 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3193 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3194 (message "bat file, batch")
  3194 (message "bat file, batch")
  3195 
  3195 
  3196 ;; loaded from 'generic-x.el'
  3196 ;; loaded from 'generic-x.el'
  3207 (when (fboundp 'subword-mode)
  3207 (when (fboundp 'subword-mode)
  3208   (add-hook 'java-mode-hook #'subword-mode))
  3208   (add-hook 'java-mode-hook #'subword-mode))
  3209 
  3209 
  3210 (add-hook 'java-mode-hook #'auto-revert-mode)
  3210 (add-hook 'java-mode-hook #'auto-revert-mode)
  3211 
  3211 
  3212 (defun my/company-java-setup ()
  3212 (defun my-company-java-setup ()
  3213   (setq-local company-dabbrev-code-other-buffers t)
  3213   (setq-local company-dabbrev-code-other-buffers t)
  3214   (setq-local company-backends '((company-semantic company-capf company-dabbrev-code)))
  3214   (setq-local company-backends '((company-semantic company-capf company-dabbrev-code)))
  3215   (company-mode 1))
  3215   (company-mode 1))
  3216 (when (and (featurep 'semantic) (featurep 'company))
  3216 (when (and (featurep 'semantic) (featurep 'company))
  3217   (add-hook 'java-mode-hook #'my/company-java-setup))
  3217   (add-hook 'java-mode-hook #'my-company-java-setup))
  3218 
  3218 
  3219 (defvar my/java-exeption-dirs nil
  3219 (defvar my-java-exeption-dirs nil
  3220   "List of dirs to look by `my/java-exeption'.")
  3220   "List of dirs to look by `my-java-exeption'.")
  3221 
  3221 
  3222 (defun my/java-exeption ()
  3222 (defun my-java-exeption ()
  3223   "Look at current line if it like Java exaption and try find file using `my/java-exeption-dirs'"
  3223   "Look at current line if it like Java exaption and try find file using `my-java-exeption-dirs'"
  3224   (interactive)
  3224   (interactive)
  3225   (save-excursion
  3225   (save-excursion
  3226     (let ( path file line end )
  3226     (let ( path file line end )
  3227       (forward-line 1)
  3227       (forward-line 1)
  3228       (backward-char 1)
  3228       (backward-char 1)
  3236         (setq path (replace-regexp-in-string (concat "\\." file ".*") "" path))
  3236         (setq path (replace-regexp-in-string (concat "\\." file ".*") "" path))
  3237         (setq path (replace-regexp-in-string "\\." "/" path))
  3237         (setq path (replace-regexp-in-string "\\." "/" path))
  3238         (setq path (cl-some (lambda (dir)
  3238         (setq path (cl-some (lambda (dir)
  3239                               (let ((full-path (format "%s/%s/%s.java" dir path file)))
  3239                               (let ((full-path (format "%s/%s/%s.java" dir path file)))
  3240                                 (when (file-exists-p full-path) full-path)))
  3240                                 (when (file-exists-p full-path) full-path)))
  3241                             my/java-exeption-dirs))
  3241                             my-java-exeption-dirs))
  3242         (if (not path)
  3242         (if (not path)
  3243             (message "Can't find file %s.java" file)
  3243             (message "Can't find file %s.java" file)
  3244           (find-file-other-window path)
  3244           (find-file-other-window path)
  3245           (goto-line (string-to-int line)))))))
  3245           (goto-line (string-to-int line)))))))
  3246 
  3246 
  3247 (my--eval-after-load log4-hi-mode
  3247 (my--eval-after-load log4-hi-mode
  3248   (define-key log4-hi-mode-map [C-return] #'my/java-exeption))
  3248   (define-key log4-hi-mode-map [C-return] #'my-java-exeption))
  3249 
  3249 
  3250 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3250 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3251 (message "Pascal")
  3251 (message "Pascal")
  3252 
  3252 
  3253 (eval-when 'compile (require 'pascal))
  3253 (eval-when 'compile (require 'pascal))
  3303  htmlize-convert-nonascii-to-entities nil)
  3303  htmlize-convert-nonascii-to-entities nil)
  3304 
  3304 
  3305 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3305 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3306 (message "html")
  3306 (message "html")
  3307 
  3307 
  3308 (defun my/html-charref-escape-region (start end)
  3308 (defun my-html-charref-escape-region (start end)
  3309   (interactive "r")
  3309   (interactive "r")
  3310   (save-excursion
  3310   (save-excursion
  3311     (save-restriction
  3311     (save-restriction
  3312       (narrow-to-region start end)
  3312       (narrow-to-region start end)
  3313       (goto-char (point-min))
  3313       (goto-char (point-min))
  3316       (while (search-forward "<") (replace-match "&lt;"))
  3316       (while (search-forward "<") (replace-match "&lt;"))
  3317       (goto-char (point-min))
  3317       (goto-char (point-min))
  3318       (while (search-forward ">") (replace-match "&gt;"))
  3318       (while (search-forward ">") (replace-match "&gt;"))
  3319       )))
  3319       )))
  3320 
  3320 
  3321 (defun my/html-charref-from-char (char)
  3321 (defun my-html-charref-from-char (char)
  3322   (format "&#%d;" char)
  3322   (format "&#%d;" char)
  3323   )
  3323   )
  3324 
  3324 
  3325 (defun my/html-charref-from-string (string)
  3325 (defun my-html-charref-from-string (string)
  3326   (let ((res ""))
  3326   (let ((res ""))
  3327     (mapc
  3327     (mapc
  3328      (lambda (char) (setq res (concat res (my/html-charref-from-char char))))
  3328      (lambda (char) (setq res (concat res (my-html-charref-from-char char))))
  3329      string)
  3329      string)
  3330     res
  3330     res
  3331     ) )
  3331     ) )
  3332 
  3332 
  3333 (defun my/html-charref-escape-region2 (begin end &optional prefix)
  3333 (defun my-html-charref-escape-region2 (begin end &optional prefix)
  3334   (interactive "r\nP")
  3334   (interactive "r\nP")
  3335   (if prefix
  3335   (if prefix
  3336       (save-excursion
  3336       (save-excursion
  3337         (goto-char begin)
  3337         (goto-char begin)
  3338         (insert (my/html-charref-from-string (delete-and-extract-region begin end))))
  3338         (insert (my-html-charref-from-string (delete-and-extract-region begin end))))
  3339     (my/html-charref-from-string (buffer-substring begin end))
  3339     (my-html-charref-from-string (buffer-substring begin end))
  3340     ))
  3340     ))
  3341 
  3341 
  3342 (defun my/html-charref-to-string (html)
  3342 (defun my-html-charref-to-string (html)
  3343   "Return string with replaced decimal/hex and string charrefs by
  3343   "Return string with replaced decimal/hex and string charrefs by
  3344 correcponding UTF-8 symbol."
  3344 correcponding UTF-8 symbol."
  3345   (let (str)
  3345   (let (str)
  3346     (with-temp-buffer
  3346     (with-temp-buffer
  3347       (insert html)
  3347       (insert html)
  3365             (replace-match "\"" t t))
  3365             (replace-match "\"" t t))
  3366            ((equal str "amp")
  3366            ((equal str "amp")
  3367             (replace-match "&" t t)))) ))
  3367             (replace-match "&" t t)))) ))
  3368       (buffer-string))))
  3368       (buffer-string))))
  3369 
  3369 
  3370 (defun my/html-charref-unescape-region (begin end &optional prefix)
  3370 (defun my-html-charref-unescape-region (begin end &optional prefix)
  3371   (interactive "r\nP")
  3371   (interactive "r\nP")
  3372   (if prefix
  3372   (if prefix
  3373       (save-excursion
  3373       (save-excursion
  3374         (goto-char begin)
  3374         (goto-char begin)
  3375         (insert (my/html-charref-to-string (delete-and-extract-region begin end))))
  3375         (insert (my-html-charref-to-string (delete-and-extract-region begin end))))
  3376     (my/html-charref-to-string (buffer-substring begin end))
  3376     (my-html-charref-to-string (buffer-substring begin end))
  3377     ))
  3377     ))
  3378 
  3378 
  3379 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3379 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3380 (message "nxml")
  3380 (message "nxml")
  3381 
  3381 
  3464 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3464 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3465 (message "psgml")
  3465 (message "psgml")
  3466 
  3466 
  3467 (eval-when 'compile (require 'psgml nil t))
  3467 (eval-when 'compile (require 'psgml nil t))
  3468 
  3468 
  3469 (defvar my/html-template
  3469 (defvar my-html-template
  3470       '("html"
  3470       '("html"
  3471         (nil
  3471         (nil
  3472          "\n<head>" \n
  3472          "\n<head>" \n
  3473          "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" (read-string "Charset: ") "\">" \n
  3473          "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=" (read-string "Charset: ") "\">" \n
  3474          "<title>" (setq str (read-string "Title: ")) "</title>\n"
  3474          "<title>" (setq str (read-string "Title: ")) "</title>\n"
  3482 
  3482 
  3483 (my--eval-after-load sgml-mode
  3483 (my--eval-after-load sgml-mode
  3484   (unless (featurep 'psgml)
  3484   (unless (featurep 'psgml)
  3485     (setq html-tag-alist
  3485     (setq html-tag-alist
  3486           (cons
  3486           (cons
  3487            my/html-template
  3487            my-html-template
  3488            (my/filter
  3488            (my-filter
  3489             (lambda (item) (not (equal (car item) "html")))
  3489             (lambda (item) (not (equal (car item) "html")))
  3490             html-tag-alist)))
  3490             html-tag-alist)))
  3491     (add-to-list 'html-tag-alist '("script" (\n) ("type" "text/javascript") ))
  3491     (add-to-list 'html-tag-alist '("script" (\n) ("type" "text/javascript") ))
  3492     (add-to-list 'html-tag-alist '("style" (\n) ("type" "text/css") )) ))
  3492     (add-to-list 'html-tag-alist '("style" (\n) ("type" "text/css") )) ))
  3493 
  3493 
  3516 
  3516 
  3517 (setq sh-basic-offset 2)
  3517 (setq sh-basic-offset 2)
  3518 
  3518 
  3519 (add-to-list 'auto-mode-alist '("\\.cygport\\'" . shell-script-mode))
  3519 (add-to-list 'auto-mode-alist '("\\.cygport\\'" . shell-script-mode))
  3520 
  3520 
  3521 (defun my/sh-company-setup ()
  3521 (defun my-sh-company-setup ()
  3522   (setq-local company-backends '((company-capf company-files company-dabbrev-code)))
  3522   (setq-local company-backends '((company-capf company-files company-dabbrev-code)))
  3523   (setq-local company-dabbrev-code-other-buffers t)
  3523   (setq-local company-dabbrev-code-other-buffers t)
  3524   (company-mode 1))
  3524   (company-mode 1))
  3525 
  3525 
  3526 (when (featurep 'company)
  3526 (when (featurep 'company)
  3527   (add-hook 'sh-mode-hook #'my/sh-company-setup))
  3527   (add-hook 'sh-mode-hook #'my-sh-company-setup))
  3528 
  3528 
  3529 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3529 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3530 (message "pg, Proof General")
  3530 (message "pg, Proof General")
  3531 
  3531 
  3532 (eval-when 'compile (require 'proof nil t))
  3532 (eval-when 'compile (require 'proof nil t))
  3582 ;; This enable "define" and "&var" syntax.
  3582 ;; This enable "define" and "&var" syntax.
  3583 (setq sql-oracle-scan-on nil)
  3583 (setq sql-oracle-scan-on nil)
  3584 
  3584 
  3585 (add-hook 'sql-interactive-mode-hook (lambda () (toggle-truncate-lines 1)))
  3585 (add-hook 'sql-interactive-mode-hook (lambda () (toggle-truncate-lines 1)))
  3586 
  3586 
  3587 (defun my/sql-explain-paragraph ()
  3587 (defun my-sql-explain-paragraph ()
  3588   "Send the current paragraph to the SQL process with \"explain \" keyword.
  3588   "Send the current paragraph to the SQL process with \"explain \" keyword.
  3589 Works at least for MySql/MariaDB."
  3589 Works at least for MySql/MariaDB."
  3590   (interactive)
  3590   (interactive)
  3591   (let ((start (save-excursion
  3591   (let ((start (save-excursion
  3592                  (backward-paragraph)
  3592                  (backward-paragraph)
  3595                (forward-paragraph)
  3595                (forward-paragraph)
  3596                (point))))
  3596                (point))))
  3597     (sql-send-string (concat "explain " (buffer-substring-no-properties start end)))))
  3597     (sql-send-string (concat "explain " (buffer-substring-no-properties start end)))))
  3598 
  3598 
  3599 (my--eval-after-load sql
  3599 (my--eval-after-load sql
  3600   (define-key sql-mode-map (kbd "C-c C-e") 'my/sql-explain-paragraph))
  3600   (define-key sql-mode-map (kbd "C-c C-e") 'my-sql-explain-paragraph))
  3601 
  3601 
  3602 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3602 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  3603 (message "backuping")
  3603 (message "backuping")
  3604 
  3604 
  3605 (setq
  3605 (setq