Skip to content

Instantly share code, notes, and snippets.

@junmakii
Created August 4, 2017 19:12
Show Gist options
  • Select an option

  • Save junmakii/6cb5342219390646e29d3ab3462368a0 to your computer and use it in GitHub Desktop.

Select an option

Save junmakii/6cb5342219390646e29d3ab3462368a0 to your computer and use it in GitHub Desktop.
(run-at-time nil (* 5 60) 'recentf-save-list)
(setq recentf-max-saved-items 200
recentf-max-menu-items 15)
(recentf-mode +1)
; In markdown-mode, Press <TAB> on a ### line.
(windmove-default-keybindings (kbd "S"))
(setq linum-format "%4d \u2502 ")
; (require 'ido)
; (setq ido-enable-flex-matching t)
; (setq ido-everywhere t)
; (ido-mode t)
(fset 'yes-or-no-p 'y-or-n-p)
(setq ibuffer-expert t)
(setq ibuffer-show-empty-filter-groups nil)
(setq ibuffer-saved-filter-groups
'(("home"
("Magit" (name . "\*magit"))
("Help" (or (name . "\*Help\*")
(name . "\*Apropos\*")
(name . "\*info\*"))))))
(add-hook 'ibuffer-mode-hook
'(lambda ()
(ibuffer-auto-mode 1)
(ibuffer-switch-to-saved-filter-groups "home")))
(require 'cl)
(setq package-archives '(("gnu" . "https://elpa.gnu.org/packages/")
("marmalade" . "https://marmalade-repo.org/packages/")
("melpa" . "https://melpa.org/packages/")
("elpy" . "http://jorgenschaefer.github.io/packages/")))
(add-to-list 'package-archives '("melpa-stable" . "https://stable.melpa.org/packages/"))
; http://stackoverflow.com/questions/10092322/how-to-automatically-install-emacs-packages-by-specifying-a-list-of-package-name
(setq package-list
'(
auto-complete
company
elpy
jedi
jedi-core
yasnippet
markdown-mode
web-mode
company-jedi
f
flycheck
))
; activate all the packages (in particular autoloads)
(package-initialize)
; fetch the list of packages available
(unless package-archive-contents
(package-refresh-contents))
; install the missing packages
(dolist (package package-list)
(unless (package-installed-p package)
(package-install package)))
; (add-to-list 'package-archives '("marmalade" . "https://marmalade-repo.org/packages/"))
; (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
; (add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t) ; Org-mode's repository
(setq inhibit-splash-screen t)
(require 'bookmark)
(setq bookmark-default-file (concat "~/workspace/texts/" "emacs-bookmarks.el"))
(bookmark-bmenu-list)
(switch-to-buffer "*Bookmark List*")
; (bookmark-load bookmark-default-file t)
(setq browse-url-generic-program
(executable-find "/usr/bin/w3m"); (getenv "BROWSER"))
browse-url-browser-function 'browse-url-generic)
; (read-string "ask: ")
(setq here (file-name-directory (or load-file-name buffer-file-name)))
; (load-path (concat here "example/test-path.el"))
;(add-to-list 'load-path (expand-file-name "~/.emacs.d"))
(add-to-list 'load-path (expand-file-name "~/.emacs.d/site-lisp"))
(add-to-list 'load-path (expand-file-name "~/.emacs.d/elpa"))
(if (display-graphic-p)
(progn
(load-theme 'tango-dark)))
(setenv "LC_CTYPE" "UTF-8")
(setenv "LC_ALL" "en_US.UTF-8")
(setenv "LANG" "en_US.UTF-8")
(set-buffer-file-coding-system 'utf-8)
(setq locale-coding-system 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(set-selection-coding-system 'utf-8)
(prefer-coding-system 'utf-8)
(setq line-number-mode t)
(setq column-number-mode t)
(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
; (global-set-key (kbd "C-c M-r") 'revert-all-buffers)
;(defalias 'yes-or-no-p 'y-or-n-p)
;emacsclient --eval '(kill-emacs)'
(setq delete-auto-save-files t)
(setq backup-inhibited t)
(setq backup-directory-alist `(("." ."~/.emacs.d/backups")))
(setq auto-save-list-file-prefix "~/.emacs.d/auto-save-list/")
(setq backup-directory-alist
`((".*" . ,temporary-file-directory)))
(setq auto-save-file-name-transforms
`((".*" ,temporary-file-directory t)))
(setq-default indent-tabs-mode nil)
; (setq-default indent-tabs-mode 4)
(setq default-tab-width 4)
(setq tab-width 4)
(setq-default tab-width 4)
; (define-key global-map (kbd "RET") 'electric-newline-and-maybe-indent)
;(if (fboundp 'menu-bar-mode) (menu-bar-mode -1))
;(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
;(if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
(setq-default c-basic-offset 4)
;(line-number-mode)
;(hl-line-mode)
;(set-background-color "#141414")
;(set-foreground-color "#FFFFFF")
;(setq term-default-bg-color "#141414")
;(setq term-default-fg-color "#FFFFFF")
(set-default-font "-unknown-DejaVu Sans Mono-normal-normal-normal-12-12-12-12-12-m-0-iso10646-1")
;; japanese
(setq default-buffer-file-coding-system 'utf-8)
(set-locale-environment nil)
(defun i-clip ()
(interactive)
(insert (shell-command-to-string (concat "cat " "~/share/junmakii-clipboard-utils/log/clipboard.txt"))))
(define-prefix-command 'ring-map)
(global-unset-key (kbd "C-<up>"))
(global-unset-key (kbd "C-<down>"))
(global-unset-key (kbd "C-<left>"))
(global-unset-key (kbd "C-<right>"))
(global-set-key (kbd "C-<down>") 'scroll-up-command)
(global-set-key (kbd "C-<up>") 'scroll-down-command)
; (global-set-key (kbd "C-<right>") 'other-window)
(global-set-key (kbd "C-<right>") 'other-window)
(global-set-key (kbd "C-<left>") 'windmove-left)
; (global-set-key (kbd "C-<left>") '(lambda () (interactive) (switch-to-buffer (other-buffer))))
(global-unset-key (kbd "C-x C-z"))
(global-unset-key (kbd "C-z"))
(global-set-key (kbd "C-z") 'ring-map)
(global-set-key (kbd "C-z l") 'goto-line)
(global-set-key (kbd "C-z r") 'indent-region)
(global-set-key (kbd "C-z s") 'string-insert-rectangle)
(global-set-key (kbd "<f2>") 'shrink-window)
(global-set-key (kbd "<f3>") 'enlarge-window)
(global-set-key (kbd "<f4>") 'shrink-window-horizontally)
(global-set-key (kbd "<f5>") 'enlarge-window-horizontally)
; EmacsWiki: Iswitch Buffers <https://www.emacswiki.org/emacs/IswitchBuffers>
; (iswitchb-mode 1)
; (global-set-key (kbd "C-c C-b") 'iswitchb-buffer)
; (global-set-key (kbd "C-c p") 'i-clip)
(global-set-key (kbd "C-z h") 'hide-body)
(global-set-key (kbd "C-z e") 'show-all)
(global-unset-key (kbd "C-x b"))
(global-set-key (kbd "C-z b") 'ido-switch-buffer)
(global-set-key (kbd "C-c b") 'ibuffer)
(global-set-key (kbd "C-x b") 'ibuffer)
; (global-set-key (kbd "C-c b") 'buffer-menu)
(global-set-key (kbd "C-z l") 'linum-mode)
(global-set-key (kbd "C-z C-i") 'ring-map)
(global-set-key (kbd "C-z C-i i") 'string-insert-rectangle)
(global-set-key (kbd "C-x C-r") 'rename-buffer)
(global-set-key (kbd "C-z r") 'rename-buffer)
(global-set-key (kbd "C-c o") 'other-window)
(global-set-key (kbd "C-x <down>") 'windmove-down)
(global-set-key (kbd "C-x <up>") 'windmove-up)
(global-set-key (kbd "C-x <right>") 'windmove-right)
(global-set-key (kbd "C-x <left>") 'windmove-left)
(global-set-key (kbd "C-c <down>") 'windmove-down)
(global-set-key (kbd "C-c <up>") 'windmove-up)
(global-set-key (kbd "C-c <right>") 'windmove-right)
(global-set-key (kbd "C-c <left>") 'windmove-left)
(global-set-key (kbd "C-z C-d") 'dabbrev-completion)
(global-set-key (kbd "C-z c") 'dabbrev-completion)
(global-set-key (kbd "C-z C-x") 'dabbrev-expand)
;(global-set-key (kbd "C-c C-c") 'dabbrev-completion)
; (global-set-key (kbd "C-z t") 'text-mode)
(global-set-key (kbd "C-z C-t") 'term)
(global-set-key (kbd "C-<tab>") 'dabbrev-expand)
(define-key minibuffer-local-map (kbd "C-<tab>") 'dabbrev-expand)
(global-set-key (kbd "C-z C-z") 'dabbrev-exp)
(when (require 'company nil 'noerror)
(progn
(add-hook 'after-init-hook 'global-company-mode)
(global-unset-key (kbd "C-z C-z"))
(global-set-key (kbd "C-z C-z") 'company-complete-common)
(global-set-key (kbd "C-z z") 'company-complete)
))
(global-set-key (kbd "C-c C-c") 'scroll-down)
(global-set-key (kbd "C-f") 'ring-map)
(global-set-key (kbd "C-b") 'ring-map)
(global-set-key (kbd "C-f") 'forward-word)
(global-set-key (kbd "C-b") 'backward-word)
;(global-set-key (kbd "C-f C-v") 'scroll-down)
(global-set-key (kbd "C-o") 'ring-map)
(global-set-key (kbd "C-o") 'undo)
; (global-set-key (kbd "C-q") 'ring-map)
; (global-set-key (kbd "C-q") 'set-mark-command)
(global-set-key (kbd "C-r") 'ring-map)
(global-set-key (kbd "C-r") 'execute-extended-command)
(global-set-key (kbd "<f7>") 'scroll-up-command)
(global-set-key (kbd "<f8>") 'scroll-down-command)
(global-set-key (kbd "C-z d") 'dabbrev-completion)
(global-set-key (kbd "C-<tab>") 'dabbrev-expand)
(define-key minibuffer-local-map (kbd "C-<tab>") 'dabbrev-expand)
(add-to-list 'auto-mode-alist '("\\.htaccess\\'" . conf-mode))
(add-to-list 'auto-mode-alist '("\\.service\\'" . conf-unix-mode))
(add-to-list 'auto-mode-alist '("\\default\\'" . conf-space-mode))
(add-to-list 'auto-mode-alist '("\\.conf\\'" . conf-mode))
(add-to-list 'auto-mode-alist '("\\.cnf\\'" . conf-mode))
(add-to-list 'auto-mode-alist '("\\.pc\\'" . conf-space-mode))
(add-to-list 'auto-mode-alist '("\\.json\\'" . javascript-mode))
(add-to-list 'auto-mode-alist '("\\.jsx\\'" . javascript-mode))
(add-to-list 'auto-mode-alist '("\\usercron\\'" . shell-script-mode))
(add-to-list 'auto-mode-alist '("\\.less\\'" . css-mode))
;
(if (require 'web-mode nil 'noerror)
(add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.html\\'" . nxml-mode))
)
(when (require 'web-mode nil 'noerror)
(add-to-list 'auto-mode-alist '("\\.css\\'" . web-mode))
)
(if (require 'yaml-mode nil 'noerror)
(add-to-list 'auto-mode-alist '("\\.yml\\'" . yaml-mode))
(add-to-list 'auto-mode-alist '("\\.yml\\'" . ruby-mode)))
(defun switch-to-minibuffer ()
"Switch to minibuffer window."
(interactive)
(if (active-minibuffer-window)
(select-window (active-minibuffer-window))
(error "Minibuffer is not active")))
(global-set-key "\C-cm" 'switch-to-minibuffer)
(defun ipp ()
(interactive)
(insert "![image](http://s3.junmakii.com/thumbnails/600/)"))
(defun i-bcode ()
(interactive)
(insert "[Show a code.]({{site.codeurl}}/)"))
(defun i-rst-i ()
(interactive)
(insert ".. image:: img/"))
(defun i-t ()
(interactive)
(insert "title: ''
text: ''"))
(defun rst-c ()
(interactive)
(insert ".. literalinclude:: codes/
:language: python
"))
(defun i-python-exc ()
(interactive)
(insert "except Exception as err:
print(err, file=sys.stderr)"))
(defun i-python-head ()
(interactive)
(insert "#!/usr/bin/python
#-*- coding: utf-8 -*-"))
(defun i-md-img ()
(interactive)
(insert ((lambda (s)
(format "[![Image]({{ site.thumbnail_dir }}/%s)]({{ site.image_dir }}/%s)" s s))
(read-string "Image path: "))))
(defun i-mdi ()
(interactive)
(insert ((lambda (s)
(format "[![Image](/public/thumbs/%s)](/public/images/%s)" s s))
(read-string "Image path: "))))
(defun i-md-youtube ()
(interactive)
(insert (format "---
title: ''
description: ''
category: ''
tags: []
date: %s
author: 'Jun Makii'
permalink:
published: true
layout: 'post'
copyright: 'CC BY-SA 4.0'
lang: 'en'
info: 'http://static.junmakii.umu.us/info.html'
snippet:
categoryId: \"22\"
defaultLanguage: en
description: \"\"
tags: []
title:
status:
embeddable: true
license: youtube
privacyStatus: public
---
"
(format-time-string "%Y-%m-%dT%H:%M:%S +0900" (current-time)
))))
(defun i-md ()
(interactive)
(insert (format "---
title: ''
description: ''
category: ''
tags: []
date: %s
author: 'Jun Makii'
permalink:
published: true
layout: 'post'
copyright: 'CC BY-SA 4.0'
lang: 'ja'
info: 'http://static.junmakii.umu.us/info.html'
---
"
(format-time-string "%Y-%m-%dT%H:%M:%S +0900" (current-time)
))))
(defun _i-rst ()
(interactive)
(insert (format "
=
:Author: Jun Makii
:Contact: [email protected]
:Date: $Date: %s $
:Revision: $Revision: 1 $
:Copyright: 2016 Jun Makii
:Info: See <http://static.junmakii.umu.us/info.html>
:Description:
.. meta::
:date: %s
:author: Jun Makii, [email protected]
:description:
:language: en-US
:keywords:
:copyright: 2016 Jun Makii
"
(format-time-string "%Y-%m-%dT%H:%M:%SZ" (current-time))
(format-time-string "%Y-%m-%d" (current-time))
)))
(defun i-rst ()
(interactive)
(insert (format "
=
:Author: Jun Makii
:Contact: [email protected]
:Date: $Date: %s $
:Revision: $Revision: 1 $
:Copyright: CC BY-SA 4.0
:Info: See <http://static.junmakii.umu.us/info.html>
:Description:
.. meta::
:date: %s
:author: Jun Makii, [email protected]
:description:
:language: ja
:keywords:
:copyright: CC BY-SA 4.0
"
(format-time-string "%Y-%m-%dT%H:%M:%SZ" (current-time))
(format-time-string "%Y-%m-%d" (current-time))
)))
; (format "value: %s" )
(defun i-python-ospath ()
(interactive)
(insert "os.path.join(os.path.dirname(os.path.abspath(__file__)),
os.path.basename(__file__))"))
(defun i-php-tag ()
(interactive)
(insert "<?php ?>"))
(defun i-python-os-path ()
(interactive)
(insert "os.path.join(os.path.dirname(os.path.abspath(__file__)))"))
(defun i-python-os-walk ()
(interactive)
(insert "[os.path.join(root, file) for root, dirs, files in os.walk(path) for file in files]"))
(defun i-python-os-path-exists ()
(interactive)
(insert "if not os.path.exists(path):
os.makedirs(path)"))
(defun i-python-pprint ()
(interactive)
(insert "import pprint
pp = pprint.pprint"))
(defun i-python-raise-keyboardinterrupt ()
(interactive)
(insert "raise KeyboardInterrupt"))
(defun i-python-except-keyboardinterrupt ()
(interactive)
(insert "except KeyboardInterrupt as err:"))
(defun i-markdown-image-s ()
(interactive)
(insert "[![Image](http://s.junmakii.umu.us/static/thumbnails/640x360/asdf)](http://s.junmakii.umu.us/static/images/asdf)"))
(defun i-markdown-image ()
(interactive)
(insert "[![Image](thumbnails/)](images/)"))
(defun i-python-default ()
(interactive)
(insert (shell-command-to-string (concat "cat " here "templates/python_default.py"))))
(defun i-bash-default ()
(interactive)
(insert (shell-command-to-string (concat "cat " here "templates/bash_default.sh"))))
(defun i-python-main ()
(interactive)
(insert (shell-command-to-string "cat ~/Templates/python_main.py")))
(defun i-shell-head ()
(interactive)
(insert "#!/bin/bash"))
(defun i-datetime ()
(interactive)
(insert (shell-command-to-string "date --rfc-2822")))
(defun i-python-site ()
(interactive)
(insert "import site; site.addsitedir('/usr/local/workspace/lib/programs/python')"))
(defun i-python-optparse ()
(interactive)
(insert (shell-command-to-string (concat "cat " here "templates/python_optparse.py"))))
(defun i-rst-literal ()
(interactive)
(insert (shell-command-to-string (concat "cat " here "templates/rst-literalinclude.rst"))))
(defun i-rst-image ()
(interactive)
(insert ".. image:: img/thumb/
:target: img/
"))
(defun i-python-argparse ()
(interactive)
(insert (shell-command-to-string (concat "cat " here "templates/python_argparse.py"))))
(defun i-python-path ()
(interactive)
(insert (shell-command-to-string (concat "cat " here "templates/python_os_path_join.py"))))
(defun i-python-g ()
(interactive)
(insert (shell-command-to-string (concat "cat " here "templates/python_global.py"))))
(defun i-python-gpath ()
(interactive)
(insert (shell-command-to-string (concat "cat " here "templates/python_getpath.py"))))
(defun eee ()
(interactive)
(insert ".encode(\"utf-8\")"))
(defun ddd ()
(interactive)
(insert ".decode(\"utf-8\")"))
(defun i-c-file ()
(interactive)
(insert (shell-command-to-string (concat "cat " here "templates/c-file.c"))))
(defun i-f ()
(interactive)
(insert (shell-command-to-string (concat "cat " here "templates/" (read-string "File: ")))))
(defun get-string-from-file (filePath)
"Return filePath's file content."
(with-temp-buffer
(insert-file-contents filePath)
(buffer-string)))
; (format (get-string-from-file "/tmp/el") (read-string "Format: "))
(defun i-insert-file()
(interactive)
(insert
(shell-command-to-string
(concat
"python ~/workspace/texts/.emacs.d/scripts/renderer.py "
(concat "~/workspace/texts/snippets/"
(completing-read "Choose one: "
(mapcar '(lambda (i) (substring i (length (expand-file-name "~/workspace/texts/snippets/"))))
(f-entries
"~/workspace/texts/snippets" nil t))))
(concat " " (read-string "Format: "))
))))
(defun iiif ()
(interactive)
(insert
(format
(get-string-from-file
(completing-read "Choose file: "
(f-entries "~/workspace/junmakii-snippets/src" nil t))
(read-string "Format: ")
))))
(defun iii ()
(interactive)
(insert (shell-command-to-string (concat
"cat "
(completing-read "Choose one: " (f-entries "~/workspace/junmakii-snippets/src" nil t))))))
(defun i-html ()
(interactive)
(insert (shell-command-to-string (concat "cat " here "templates/default.html"))))
(defun i-html-script ()
(interactive)
(insert (shell-command-to-string (concat "cat " here "templates/script.html"))))
(defun i-ajax ()
(interactive)
(insert (shell-command-to-string (concat "cat " here "templates/xmlrequest.js"))))
(defun i-wsgi ()
(interactive)
(insert (shell-command-to-string (concat "cat " here "templates/wsgi.py"))))
(show-paren-mode)
(electric-pair-mode)
(setq nxml-slash-auto-complete-flag t)
(setq nxml-slash-auto-complete-flag t)
(require 'whitespace)
(global-whitespace-mode t)
;(setq whitespace-global-modes '(c-mode c++-mode python-mode))
(autoload 'whitespace-mode "" t)
(autoload 'whitespace-toggle-options "" t)
;; M-x whitespace-toggle-options
(setq whitespace-style (quote (spaces tabs newline space-mark tab-mark newline-mark)))
;
;(setq whitespace-global-modes '(c-mode c++-mode python-mode shell-script-mode nxml-mode rst-mode markdown-mode coffee-mode))
;
(add-hook 'find-file-hook (function (lambda () (whitespace-mode))))
(add-hook 'find-file-hook (function (lambda () (linum-mode))))
;
;(setq whitespace-mode-hook t)
;(setq whitespace-load-hook t)
;(setq show-trailing-whitespace t)
;
;(setq whitespace-line-column 80)
;(setq whitespace-style '(face lines-tail))
;
;(add-hook 'c-mode-hook (function (lambda () (whitespace-mode t))))
(setq whitespace-display-mappings
'(
(space-mark ?\ [? ]) ;; use space not dot
; (space-mark 32 [183] [46])
(newline-mark 10 [182 10])
; (tab-mark 9 [9655 9] [92 9])
))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Programming in Emacs Lisp: New insert-buffer - <https://www.gnu.org/software/emacs/manual/html_node/eintr/New-insert_002dbuffer.html>
;
; (insert-buffer-substring (get-buffer buffer))
(defun i-translate (beg end)
(interactive "*r")
((lambda (text)
(switch-to-buffer "*translation*")
(erase-buffer)
(insert text))
(shell-command-to-string (format "trans -no-theme -no-ansi -no-bidi -to ja %s" (buffer-substring beg end)))))
(defun i-translate-i (beg end)
(interactive "*r")
(goto-char (+ (region-beginning) (- end beg)))
(insert (format "(%s)"
(replace-regexp-in-string "
" "" (shell-command-to-string (format "trans -no-theme -no-ansi -no-bidi -to ja -b %s" (buffer-substring beg end)))))))
(global-set-key (kbd "C-z t") 'i-translate)
(global-set-key (kbd "C-z C-t") 'i-translate-i)
;(defun i-translate (beg end)
; (interactive "*r")
; (princ
; (shell-command-to-string (format "translate -t ja %s" (buffer-substring beg end)))))
(defun i-translate-dict (beg end)
(interactive "*r")
(princ
(shell-command-to-string (format "trans -no-theme -no-ansi -no-bidi -d %s" (buffer-substring beg end)))))
(when (require 'auto-complete nil 'noerror)
(ac-config-default))
; Start auto-completion after 2 characters of a word
(setq ac-auto-start 2)
; case sensitivity is important when finding matches
(setq ac-ignore-case nil)
(when (require 'yasnippet nil 'noerror)
(progn
(global-set-key (kbd "C-z i") 'yas-insert-snippet)
(yas-global-mode 1)
(setq yas-snippet-dirs
'("~/.emacs.d/snippets"
"~/workspace/texts/snippets"))
(add-hook 'python-mode-hook
'(lambda () (set (make-local-variable 'yas-indent-line) 'fixed)))
(add-hook 'yas-minor-mode-hook
(lambda ()
(yas-activate-extra-mode 'fundamental-mode)))
))
; (define-key yas-minor-mode-map (kbd "<tab>") nil)
; (define-key yas-minor-mode-map (kbd "TAB") nil)
; (define-key yas-minor-mode-map (kbd "<the new key>") 'yas-expand)
(autoload 'gfm-mode "markdown-mode.el" "Major mode for editing Markdown files" t)
(setq auto-mode-alist (cons '("\\.md$" . gfm-mode) auto-mode-alist))
; Installation · jorgenschaefer/elpy Wiki <https://github.com/jorgenschaefer/elpy/wiki/Installation>
; pip install jedi
(when (require 'elpy nil 'noerror)
(progn
(elpy-enable)
(elpy-use-cpython)))
; (if (package-installed-p 'w3m)
; (ignore
; (setq w3m-default-directory "/tmp/w3m-emacs")
; (setq w3m-default-save-directory "/tmp/w3m-emacs")
; (setq w3m-bookmark-file "~/workspace/w3m-bookmark.html")))
(defun i-line ()
(interactive)
(setq p (point))
(goto-line (string-to-number (read-string "line: ")))
(insert (read-string "string: "))
(newline)
(goto-char p))
(defun i-remove-newlines-in-region ()
"Removes all newlines in the region."
(interactive)
(save-restriction
(narrow-to-region (point) (mark))
(goto-char (point-min))
(while (search-forward "\n" nil t) (replace-match " " nil t))))
; (indent-for-tab-command)
(defconst junmakii-word-list (split-string
(with-temp-buffer
(insert-file-contents "~/.emacs.d/completions/english-words.txt")
(buffer-string))))
(defun company-junmakii-completions (command &optional arg &rest ignored)
(interactive (list 'interactive))
(cl-case command
(interactive (company-begin-backend 'company-junmakii-completions))
(prefix (and (eq major-mode 'gfm-mode)
(company-grab-symbol)))
(candidates (let ((lower-arg (downcase arg)))
(delq nil (mapcar
'(lambda (x) (if (string-prefix-p lower-arg x)
x
nil))
junmakii-word-list))))
(meta (format "This value %s" arg))))
(when (require 'company nil 'noerror)
(progn
(add-to-list 'company-backends 'company-junmakii-completions)
(add-to-list 'company-backends 'company-junmakii-completions)
(add-hook 'gfm-mode-hook
(lambda () (global-set-key (kbd "C-z a") 'company-junmakii-completions)))
))
; (setq desktop-save t)
; (desktop-save-mode 1)
; (setq history-length 250)
; (add-to-list 'desktop-globals-to-save 'file-name-history)
(setq desktop-dirname "~/.emacs.d/desktop/"
desktop-base-file-name "emacs.desktop"
desktop-base-lock-name "lock"
desktop-path (list desktop-dirname)
desktop-save t
desktop-files-not-to-save "^$" ;reload tramp paths
desktop-load-locked-desktop nil)
; (desktop-save-mode 1)
; (winner-mode 1)
(when (require 'markdown-mode nil 'noerror)
(add-hook 'gfm-mode-hook
(lambda ()
(progn
(add-to-list 'auto-mode-alist '("\\.md\\'" . gfm-mode))
(add-to-list 'auto-mode-alist '("README\\'" . gfm-mode))
(defun markdown-indent-line () nil)
(electric-indent-mode nil)))))
(when (require 'tern nil 'noerror)
(add-hook 'js-mode-hook
(lambda ()
(tern-mode t)
(tern-ac-setup)
)))
; (when (require 'company-jedi nil 'noerror)
; (add-to-list 'company-backends 'company-jedi))
;; (when (require 'company-tern nil 'noerror)
;; (add-to-list 'company-backends 'company-tern))
; (when (require 'jedi-core nil 'noerror)
; (progn
; (require 'jedi-core)
; (setq jedi:complete-on-dot t)
; (setq jedi:use-shortcuts t)
; (add-hook 'python-mode-hook 'jedi:setup)
; (add-to-list 'company-backends 'company-jedi)))
;(when (require 'jedi nil 'noerror)
; (progn
; (add-hook 'python-mode-hook 'jedi:setup)
; (setq jedi:complete-on-dot t)
; (add-to-list 'company-backends 'company-jedi)))
(defun i-replace-regexp-in-region (start end)
(interactive "*r")
(save-excursion
(save-restriction
(let ((regexp (read-string "Regexp: "))
(to-string (read-string "Replacement: ")))
(narrow-to-region start end)
(goto-char (point-min))
(while (re-search-forward regexp nil t)
(replace-match to-string nil nil))))))
(defun i-remove-spaces (start end)
(interactive "*r")
(save-excursion
(save-restriction
(let ((regexp "^ ")
(to-string ""))
(narrow-to-region start end)
(goto-char (point-min))
(while (re-search-forward regexp nil t)
(replace-match to-string nil nil))))))
(global-set-key (kbd "C-z S") 'i-remove-spaces)
(defun i-remove-indents (start end)
(interactive "*r")
(save-excursion
(save-restriction
(let ((regexp "\n")
(to-string " "))
(narrow-to-region start end)
(goto-char (point-min))
(while (re-search-forward regexp nil t)
(replace-match to-string nil nil))))))
(defun i-bold (start end)
(interactive "*r")
(goto-char (region-beginning))
(insert "**")
(goto-char (+ (+ (region-beginning) (- end start)) 2))
(insert "**")
)
(global-set-key (kbd "C-z C-a") 'i-bold)
(defun python-call (code)
(shell-command-to-string
(format "python -c '
import sys, os, io, pprint
pp = pprint.pprint
file = sys.argv[1]
%s
' '%s'"
(replace-regexp-in-string "'" "\"" code)
(buffer-file-name)
)))
(defun i-py ()
(interactive)
(insert (python-call (read-string "python -c "))))
; (shell-quote-argument)
(defun my-web-mode-hook ()
"Hooks for Web mode."
(progn
; (web-mode-set-content-type "jsx")
(tern-mode t)
(setq web-mode-markup-indent-offset 2)
(setq web-mode-html-offset 2)
(setq web-mode-css-offset 2)
(setq web-mode-script-offset 2)
(setq web-mode-php-offset 2)
(setq web-mode-java-offset 2)
(setq web-mode-asp-offset 2)
(setq web-mode-enable-auto-closing t)
(setq web-mode-auto-close-style 1)
(setq web-mode-tag-auto-close-style 1)
(setq indent-tabs-mode nil)
(setq tab-width 2)
(web-mode-set-content-type "jsx")
; (web-mode-set-content-type "html")
(flycheck-mode)
(tern-ac-setup)
(message "web-mode-hook loaded")
; To use web-mode in HTML file
; M-; (web-mode-set-content-type "html")
; (if (equal web-mode-content-type "javascript")
; (web-mode-set-content-type "jsx"))
(highlight-regexp "[^=]>" 'hi-red-b)
(highlight-regexp "<.+? " 'hi-red-b)
)
)
; (setq-default indent-tabs-mode t)
(when (require 'web-mode nil 'noerror)
(progn
(require 'web-mode)
(add-to-list 'auto-mode-alist '("\\.jsx\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.js\\'" . web-mode))
(add-to-list 'auto-mode-alist '("\\.html\\'" . web-mode))
(setq web-mode-enable-auto-pairing t)
(add-hook 'web-mode-hook 'my-web-mode-hook)
))
; (count-words)
; (count-lines-page)
; (what-line)
(defun i-scroll ()
""
(interactive)
(setq called-buffer (current-buffer))
(setq timer
(run-with-timer
t
1
'(lambda ()
(if (and (/= (point-max) (point)) (eq (current-buffer) called-buffer))
(progn
; (scroll-up)
(next-line)
(end-of-line)
)
(cancel-timer timer)))
)
))
(defun i-scroll-5 ()
""
(interactive)
(setq called-buffer (current-buffer))
(setq timer
(run-with-timer
t
1
'(lambda ()
(if (and (/= (point-max) (point)) (eq (current-buffer) called-buffer))
(progn
; (scroll-up)
(next-line)
(next-line)
(next-line)
(next-line)
(next-line)
(end-of-line)
)
(cancel-timer timer)))
)
))
; (read-key)
; minibuffer-exit-hook.
; (minibuffer-with-setup-hook (lambda () (message "1")))
; (add-hook 'after-change-functions '(lambda () (message "1")))
(defun i-web-mode-jsx ()
""
(interactive)
(web-mode-set-content-type "jsx")
)
(defun i-web-mode-html ()
""
(interactive)
(web-mode-set-content-type "html")
)
(defun i-java-execute ()
""
(interactive)
(let ((name (read-string "Name: "))
(args (read-string "Args: ")))
(message-box (shell-command-to-string (concat "javac " name ".java && java " name " " args)))))
(defun i-web-get-title-fn (title)
(insert (shell-command-to-string (format "python -c 'import sys, requests, bs4, chardet
url = sys.argv[1]
text = bs4.BeautifulSoup(requests.get(url).content, \"lxml\").title.text
text = text.decode(chardet.detect(text)[\"encoding\"]).encode(\"utf-8\")
sys.stdout.write(b\" - \" + bytes(text))' %s" title))))
(defun i-web-get-title (beg end)
(interactive "*r")
(i-web-get-title-fn (buffer-substring beg end)))
(require 'recentf)
(recentf-mode 1)
(setq recentf-max-menu-items 25)
(global-set-key (kbd "C-z C-r") 'recentf-open-files)
(defun i-insert-line ()
(interactive)
(insert "
----
"))
(defun i-insert-bang ()
(interactive)
(insert "(!!!!)"))
(global-set-key (kbd "C-z -") 'i-insert-line)
(global-set-key (kbd "C-z !") 'i-insert-bang)
(if (require 'meghanada nil 'noerror)
(require 'meghanada)
(add-hook 'java-mode-hook
(lambda ()
;; meghanada-mode on
(meghanada-mode t)
(add-hook 'before-save-hook 'meghanada-code-beautify-before-save)))
)
; (global-unset-key (kbd "C-<return>"))
; (global-set-key (kbd "C-<return>") '(lambda () (message "OK")))
(defun i-file-name ()
(interactive)
(insert (buffer-file-name)))
(defun i-w3m-duckduckgo ()
(interactive)
(w3m-browse-url (concat "https://duckduckgo.com/html/?q=" (read-string "Search Query: "))))
(defun i-w3m-google ()
(interactive)
(w3m-browse-url (concat "https://www.google.com/search?hl=en&cr=us&q=" (read-string "Search Query: "))))
(defun i-git-commit ()
(interactive)
(shell-command (concat "git add -A .; git commit -am " (read-string "Message: "))))
(defun i-git-commit-file ()
(interactive)
(shell-command (concat "git add -A " (completing-read "Choose one: " (f-entries
"./" nil t)) "; git commit -am " (read-string "Message: "))))
(defun i-grep ()
(interactive)
(shell-command (concat "grep -nr" " " (read-string "Pattern: ") " " (buffer-file-name))))
(defun i-display-in-other-buffer (name text)
(switch-to-buffer name)
(markdown-mode)
(erase-buffer)
(insert text))
(defun i-grep-apostrophes ()
(interactive)
(i-display-in-other-buffer "*i-grep*" (shell-command-to-string (concat "grep" " '\\*\\*' " (buffer-file-name)))))
(defun i-find ()
(interactive)
(shell-command (concat "find . -name '" (read-string "name: ") "' | awk '{print \"du\", $0}' | bash | sort" )))
(require 'f)
(defun i-create-snippet (start end)
(interactive "*r")
(let ((filename (concat "~/workspace/texts/snippets/fundamental-mode/" (read-string "File Name: "))))
(if (file-exists-p filename)
(message "Already exists")
(f-write-text (buffer-substring start end) 'utf-8 filename)
)))
(when (require 'window-number nil 'noerror)
(require 'window-number)
(window-number-mode 1))
(defun i-window-n ()
(interactive)
(window-number-select (string-to-number (read-string "Window Number: "))))
(global-set-key (kbd "C-z w") 'i-window-n)
(global-set-key (kbd "C-x w") 'i-window-n)
(global-set-key (kbd "C-c w") 'i-window-n)
(defun i-window-s ()
(interactive)
(split-window-vertically (floor (* 0.8 (window-height)))))
(defun i-ngrams ()
(interactive)
(let ((filePath (format "~/workspace/texts/data/ngrams/%s.txt" (downcase (thing-at-point 'word)))))
(progn
(let ((content (with-temp-buffer
(insert-file-contents filePath)
(buffer-string))))
(display-message-or-buffer content)))))
(defun i-python-command ()
(interactive)
(insert (shell-command-to-string
(concat "python -c" (shell-quote-argument (concat "
import os
import sys
import json
import jinja2
from jinja2 import *
" "print(" (read-string "Shell Command: ") ")"))))))
(when (require 'company nil 'noerror)
(require 'flycheck)
(flycheck-add-mode 'javascript-eslint 'web-mode))
;; Golang
;; (when (require 'go-mode nil 'noerror)
;; (add-to-list 'exec-path (expand-file-name "~/workspace/src/go/bin"))
;; (require 'exec-path-from-shell)
;; (let ((envs '("PATH" "GOPATH")))
;; (exec-path-from-shell-copy-envs envs)))
;; (with-eval-after-load 'go-mode
;; (require 'go-autocomplete))
(defun i-golang-run ()
(interactive)
(print (shell-command-to-string
(format "go run -v %s" (file-name-nondirectory (buffer-file-name))
))))
(defun i-git-commit-file ()
(interactive)
(let ((file (completing-read "File: "
(f-entries (file-name-directory buffer-file-name) nil t)))
(message (read-string "Message: ")))
(shell-command (format "git add %s; git commit -m '%s'" file message))
))
;; ### Abbrev
(setq-default abbrev-mode t)
(setq save-abbrevs t) ;; save abbrevs when files are saved
;; (setq junmakii-abbrev-table nil)
(define-abbrev-table 'python-mode-abbrev-table
'(
; ("btw" "By the way" '(lambda () (message "abbrev")))
)
)
;; (abbrev-table-put junmakii-abbrev-table :regex t)
;; (define-abbrev junmakii-abbrev-table "lambda" "(lambda (x▮) (interactive) BODY)" )
(load-file "~/workspace/src/auto-java-complete/ajc-java-complete.el")
(load-file "~/workspace/src/auto-java-complete/ajc-java-complete-config.el")
(require 'ajc-java-complete-config)
(add-hook 'java-mode-hook 'ajc-java-complete-mode)
(defun i-python-autoflake ()
(interactive)
(let (
(output-file (format "/tmp/%s.patch" (buffer-name)))
(target-file (buffer-name))
)
(shell-command (format "autoflake %s --remove-unused-variables --remove-all-unused-imports > %s" target-file output-file))
(progn (goto-char 0) (delete-char (buffer-size)) (insert (shell-command-to-string (format "patch %s %s -s -o -" target-file output-file)))
)))
(require 'json)
(defun run-python-file (file args)
(let* (
(command "python")
(command-string (mapconcat 'identity (append (list command file) (mapcar 'shell-quote-argument args)) " "))
(output (shell-command-to-string command-string))
(data (json-read-from-string output))
)
data))
(defun get-json-value-by-key (data key)
(cdr (assoc key data)))
(defun i-update-file ()
(run-python-file "test.py" (list (buffer-file-name)))
(revert-buffer (current-buffer) t))
; (get-json-value-by-key (run-python-file "test.py" '("a" "b")) 'args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment