1924
.emacs.d/plugins/awesome-tab.el
Normal file
1924
.emacs.d/plugins/awesome-tab.el
Normal file
File diff suppressed because it is too large
Load Diff
1723
.emacs.d/plugins/bash-completion.el
Normal file
1723
.emacs.d/plugins/bash-completion.el
Normal file
File diff suppressed because it is too large
Load Diff
138
.emacs.d/plugins/buffer-move.el
Normal file
138
.emacs.d/plugins/buffer-move.el
Normal file
@ -0,0 +1,138 @@
|
||||
;;; buffer-move.el ---
|
||||
|
||||
;; Copyright (C) 2004-2014 Lucas Bonnet <lucas@rincevent.net.fr>
|
||||
|
||||
;; Author: Lucas Bonnet <lucas@rincevent.net>
|
||||
;; Keywords: lisp,convenience
|
||||
;; Version: 0.5
|
||||
;; URL : https://github.com/lukhas/buffer-move
|
||||
|
||||
;; This program is free software; you can redistribute it and/or
|
||||
;; modify it under the terms of the GNU General Public License
|
||||
;; as published by the Free Software Foundation; either version 2
|
||||
;; of the License, or (at your option) any later version.
|
||||
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with this program; if not, write to the Free Software
|
||||
;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
|
||||
;; 02111-1307, USA.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; This file is for lazy people wanting to swap buffers without
|
||||
;; typing C-x b on each window. This is useful when you have :
|
||||
|
||||
;; +--------------+-------------+
|
||||
;; | | |
|
||||
;; | #emacs | #gnus |
|
||||
;; | | |
|
||||
;; +--------------+-------------+
|
||||
;; | |
|
||||
;; | .emacs |
|
||||
;; | |
|
||||
;; +----------------------------+
|
||||
|
||||
;; and you want to have :
|
||||
|
||||
;; +--------------+-------------+
|
||||
;; | | |
|
||||
;; | #gnus | .emacs |
|
||||
;; | | |
|
||||
;; +--------------+-------------+
|
||||
;; | |
|
||||
;; | #emacs |
|
||||
;; | |
|
||||
;; +----------------------------+
|
||||
|
||||
;; With buffer-move, just go in #gnus, do buf-move-left, go to #emacs
|
||||
;; (which now should be on top right) and do buf-move-down.
|
||||
|
||||
;; To use it, simply put a (require 'buffer-move) in your ~/.emacs and
|
||||
;; define some keybindings. For example, i use :
|
||||
|
||||
;; (global-set-key (kbd "<C-S-up>") 'buf-move-up)
|
||||
;; (global-set-key (kbd "<C-S-down>") 'buf-move-down)
|
||||
;; (global-set-key (kbd "<C-S-left>") 'buf-move-left)
|
||||
;; (global-set-key (kbd "<C-S-right>") 'buf-move-right)
|
||||
|
||||
|
||||
;;; Code:
|
||||
|
||||
|
||||
(require 'windmove)
|
||||
|
||||
;;;###autoload
|
||||
(defun buf-move-up ()
|
||||
"Swap the current buffer and the buffer above the split.
|
||||
If there is no split, ie now window above the current one, an
|
||||
error is signaled."
|
||||
;; "Switches between the current buffer, and the buffer above the
|
||||
;; split, if possible."
|
||||
(interactive)
|
||||
(let* ((other-win (windmove-find-other-window 'up))
|
||||
(buf-this-buf (window-buffer (selected-window))))
|
||||
(if (null other-win)
|
||||
(error "No window above this one")
|
||||
;; swap top with this one
|
||||
(set-window-buffer (selected-window) (window-buffer other-win))
|
||||
;; move this one to top
|
||||
(set-window-buffer other-win buf-this-buf)
|
||||
(select-window other-win))))
|
||||
|
||||
;;;###autoload
|
||||
(defun buf-move-down ()
|
||||
"Swap the current buffer and the buffer under the split.
|
||||
If there is no split, ie now window under the current one, an
|
||||
error is signaled."
|
||||
(interactive)
|
||||
(let* ((other-win (windmove-find-other-window 'down))
|
||||
(buf-this-buf (window-buffer (selected-window))))
|
||||
(if (or (null other-win)
|
||||
(string-match "^ \\*Minibuf" (buffer-name (window-buffer other-win))))
|
||||
(error "No window under this one")
|
||||
;; swap top with this one
|
||||
(set-window-buffer (selected-window) (window-buffer other-win))
|
||||
;; move this one to top
|
||||
(set-window-buffer other-win buf-this-buf)
|
||||
(select-window other-win))))
|
||||
|
||||
;;;###autoload
|
||||
(defun buf-move-left ()
|
||||
"Swap the current buffer and the buffer on the left of the split.
|
||||
If there is no split, ie now window on the left of the current
|
||||
one, an error is signaled."
|
||||
(interactive)
|
||||
(let* ((other-win (windmove-find-other-window 'left))
|
||||
(buf-this-buf (window-buffer (selected-window))))
|
||||
(if (null other-win)
|
||||
(error "No left split")
|
||||
;; swap top with this one
|
||||
(set-window-buffer (selected-window) (window-buffer other-win))
|
||||
;; move this one to top
|
||||
(set-window-buffer other-win buf-this-buf)
|
||||
(select-window other-win))))
|
||||
|
||||
;;;###autoload
|
||||
(defun buf-move-right ()
|
||||
"Swap the current buffer and the buffer on the right of the split.
|
||||
If there is no split, ie now window on the right of the current
|
||||
one, an error is signaled."
|
||||
(interactive)
|
||||
(let* ((other-win (windmove-find-other-window 'right))
|
||||
(buf-this-buf (window-buffer (selected-window))))
|
||||
(if (null other-win)
|
||||
(error "No right split")
|
||||
;; swap top with this one
|
||||
(set-window-buffer (selected-window) (window-buffer other-win))
|
||||
;; move this one to top
|
||||
(set-window-buffer other-win buf-this-buf)
|
||||
(select-window other-win))))
|
||||
|
||||
|
||||
(provide 'buffer-move)
|
||||
;;; buffer-move.el ends here
|
1195
.emacs.d/plugins/dired-sidebar.el
Executable file
1195
.emacs.d/plugins/dired-sidebar.el
Executable file
File diff suppressed because it is too large
Load Diff
68
.emacs.d/plugins/flymake-yaml.el
Normal file
68
.emacs.d/plugins/flymake-yaml.el
Normal file
@ -0,0 +1,68 @@
|
||||
;;; flymake-yaml.el --- A flymake handler for YAML
|
||||
|
||||
;; Copyright (C) 2013 Yasuyuki Oka
|
||||
|
||||
;; Author: Yasuyuki Oka <yasuyk@gmail.com>
|
||||
;; Version: 0.0.2
|
||||
;; URL: https://github.com/yasuyk/flymake-yaml
|
||||
;; Package-Requires: ((flymake-easy "0.1"))
|
||||
;; Keywords: yaml
|
||||
|
||||
;; This program is free software; you can redistribute it and/or modify
|
||||
;; it under the terms of the GNU General Public License as published by
|
||||
;; the Free Software Foundation, either version 3 of the License, or
|
||||
;; (at your option) any later version.
|
||||
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
;;
|
||||
;; Based in part on http://d.hatena.ne.jp/kitokitoki/20120306/p1
|
||||
;;
|
||||
;; Usage:
|
||||
;;
|
||||
;; (require 'flymake-yaml) ;; Not necessary if using ELPA package
|
||||
;; (add-hook 'yaml-mode-hook 'flymake-yaml-load)
|
||||
;;
|
||||
;; Uses flymake-easy, from https://github.com/purcell/flymake-easy
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'flymake-easy)
|
||||
|
||||
(defconst flymake-yaml-err-line-patterns
|
||||
;; Syck error message
|
||||
'(("syntax error on line \\([0-9]+\\), col \\([0-9]+\\): `\\(.*\\)'" nil 1 2 3)
|
||||
;; Psych error message
|
||||
(".*: \\(.*\\) at line \\([0-9]+\\) column \\([0-9]+\\)" nil 2 3 1)))
|
||||
|
||||
(defun flymake-yaml-command (filename)
|
||||
"Construct a command that flymake can use to check yaml source.
|
||||
Argument FILENAME
|
||||
YAML file name."
|
||||
(list "ruby" "-ryaml" "-e" "YAML.load(ARGF) rescue warn $!" filename))
|
||||
|
||||
;;;###autoload
|
||||
(defun flymake-yaml-load ()
|
||||
"Configure flymake mode to check the current buffer's YAML syntax."
|
||||
(interactive)
|
||||
(when (eq major-mode 'yaml-mode)
|
||||
(flymake-easy-load 'flymake-yaml-command
|
||||
flymake-yaml-err-line-patterns
|
||||
'tempdir
|
||||
"yml")))
|
||||
|
||||
(provide 'flymake-yaml)
|
||||
|
||||
;; Local Variables:
|
||||
;; coding: utf-8
|
||||
;; eval: (checkdoc-minor-mode 1)
|
||||
;; End:
|
||||
|
||||
;;; flymake-yaml.el ends here
|
27
.emacs.d/plugins/latexmk-mode.el
Normal file
27
.emacs.d/plugins/latexmk-mode.el
Normal file
@ -0,0 +1,27 @@
|
||||
;;; latexmk-mode.el --- LatexMK minor mode
|
||||
;;; Commentary:
|
||||
;;; none
|
||||
;;; Code:
|
||||
|
||||
(define-minor-mode latexmk-mode
|
||||
"Toggle LatexMK mode."
|
||||
:init-value nil
|
||||
:lighter " LatexMK "
|
||||
)
|
||||
|
||||
(defun my/run-latexmk ()
|
||||
(interactive)
|
||||
(start-process "latexmk" "latexmk out" "latexmk" "--silent" "--pdf" (buffer-file-name (current-buffer)))
|
||||
)
|
||||
|
||||
(defun my/try-run-latexmk ()
|
||||
"Try to run latexmk."
|
||||
|
||||
(if (bound-and-true-p latexmk-mode)
|
||||
(my/run-latexmk)
|
||||
)
|
||||
)
|
||||
|
||||
(add-hook 'after-save-hook 'my/try-run-latexmk)
|
||||
(add-hook 'latex-mode-hook 'latexmk-mode)
|
||||
;;; latexmk-mode.el ends here
|
75
.emacs.d/plugins/livedown.el
Normal file
75
.emacs.d/plugins/livedown.el
Normal file
@ -0,0 +1,75 @@
|
||||
;;; livedown.el --- Realtime Markdown previews for Emacs.
|
||||
|
||||
;; Copyright (C) 2014-2016 Hrvoje Simic
|
||||
|
||||
;; Author: Hrvoje Simic <hrvoje@twobucks.co>
|
||||
;; Version: 1.0.0
|
||||
;; Keywords: markdown, preview, live
|
||||
;; URL: https://github.com/shime/emacs-livedown
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; Realtime Markdown previews for Emacs.
|
||||
|
||||
;;; Code:
|
||||
|
||||
(defgroup livedown nil
|
||||
"Realtime Markdown previews"
|
||||
:group 'livedown
|
||||
:prefix "livedown-")
|
||||
|
||||
(defcustom livedown-port 1337
|
||||
"Port on which livedown server will run."
|
||||
:type 'integer
|
||||
:group 'livedown)
|
||||
|
||||
(defcustom livedown-open t
|
||||
"Open browser automatically."
|
||||
:type 'boolean
|
||||
:group 'livedown)
|
||||
|
||||
(defcustom livedown-browser nil
|
||||
"Open alternative browser."
|
||||
:type 'string
|
||||
:group 'livedown)
|
||||
|
||||
(defcustom livedown-autostart nil
|
||||
"Auto-open previews when opening markdown files."
|
||||
:type 'boolean
|
||||
:group 'livedown)
|
||||
|
||||
;;;###autoload
|
||||
(defun livedown-preview ()
|
||||
"Preview the current file in livedown."
|
||||
(interactive)
|
||||
|
||||
(call-process-shell-command
|
||||
(format "livedown stop --port %s &"
|
||||
livedown-port))
|
||||
|
||||
(start-process-shell-command
|
||||
(format "emacs-livedown")
|
||||
(format "emacs-livedown-buffer")
|
||||
(format "livedown start %s --port %s %s %s "
|
||||
buffer-file-name
|
||||
livedown-port
|
||||
(if livedown-browser (concat "--browser " livedown-browser) "")
|
||||
(if livedown-open "--open" "")))
|
||||
(print (format "%s rendered @ %s" buffer-file-name livedown-port) (get-buffer "emacs-livedown-buffer")))
|
||||
|
||||
;;;###autoload
|
||||
(defun livedown-kill (&optional async)
|
||||
"Stops the livedown process."
|
||||
(interactive)
|
||||
(let ((stop-livedown (if async 'async-shell-command 'call-process-shell-command)))
|
||||
(funcall stop-livedown
|
||||
(format "livedown stop --port %s &"
|
||||
livedown-port))))
|
||||
|
||||
(if livedown-autostart
|
||||
(eval-after-load 'markdown-mode '(livedown-preview)))
|
||||
|
||||
(add-hook 'kill-emacs-query-functions (lambda () (livedown-kill t)))
|
||||
|
||||
(provide 'livedown)
|
||||
;;; livedown.el ends here
|
261
.emacs.d/plugins/org-ac.el
Normal file
261
.emacs.d/plugins/org-ac.el
Normal file
@ -0,0 +1,261 @@
|
||||
;;; org-ac.el --- Some auto-complete sources for org-mode
|
||||
|
||||
;; Copyright (C) 2014 Hiroaki Otsu
|
||||
|
||||
;; Author: Hiroaki Otsu <ootsuhiroaki@gmail.com>
|
||||
;; Keywords: org, completion
|
||||
;; URL: https://github.com/aki2o/org-ac
|
||||
;; Version: 0.0.2
|
||||
;; Package-Requires: ((auto-complete-pcmp "0.0.1") (log4e "0.2.0") (yaxception "0.1"))
|
||||
|
||||
;; This program is free software; you can redistribute it and/or modify
|
||||
;; it under the terms of the GNU General Public License as published by
|
||||
;; the Free Software Foundation, either version 3 of the License, or
|
||||
;; (at your option) any later version.
|
||||
|
||||
;; This file is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
;;; Commentary:
|
||||
;;
|
||||
;; This extension provides auto-complete sources for org-mode.
|
||||
|
||||
;;; Dependency:
|
||||
;;
|
||||
;; - auto-complete-pcmp.el ( see <https://github.com/aki2o/auto-complete-pcmp> )
|
||||
;; - yaxception.el ( see <https://github.com/aki2o/yaxception> )
|
||||
;; - log4e.el ( see <https://github.com/aki2o/log4e> )
|
||||
|
||||
;;; Installation:
|
||||
;;
|
||||
;; Put this to your load-path.
|
||||
;; And put the following lines in your .emacs or site-start.el file.
|
||||
;;
|
||||
;; (require 'org-ac)
|
||||
|
||||
;;; Configuration:
|
||||
;;
|
||||
;; ;; Make config suit for you. About the config item, see Customization or eval the following sexp.
|
||||
;; ;; (customize-group "org-ac")
|
||||
;;
|
||||
;; (org-ac/config-default)
|
||||
|
||||
;;; Customization:
|
||||
;;
|
||||
;; [EVAL] (autodoc-document-lisp-buffer :type 'user-variable :prefix "org-ac/" :docstring t)
|
||||
;; `org-ac/ac-trigger-command-keys'
|
||||
;; Keystrokes for doing `ac-start' with self insert.
|
||||
;;
|
||||
;; *** END auto-documentation
|
||||
|
||||
;;; API:
|
||||
;;
|
||||
;; [EVAL] (autodoc-document-lisp-buffer :type 'command :prefix "org-ac/" :docstring t)
|
||||
;; `org-ac/setup-current-buffer'
|
||||
;; Do setup for using org-ac in current buffer.
|
||||
;;
|
||||
;; *** END auto-documentation
|
||||
;; [Note] Functions and variables other than listed above, Those specifications may be changed without notice.
|
||||
|
||||
;;; Tested On:
|
||||
;;
|
||||
;; - Emacs ... GNU Emacs 24.3.1 (i686-pc-linux-gnu, GTK+ Version 3.4.2) of 2013-08-22 on chindi02, modified by Debian
|
||||
;; - auto-complete-pcmp.el ... Version 0.0.1
|
||||
;; - yaxception.el ... Version 0.1
|
||||
;; - log4e.el ... Version 0.2.0
|
||||
|
||||
|
||||
;; Enjoy!!!
|
||||
|
||||
|
||||
(eval-when-compile (require 'cl))
|
||||
(require 'org)
|
||||
(require 'auto-complete-pcmp)
|
||||
(require 'rx)
|
||||
(require 'log4e)
|
||||
(require 'yaxception)
|
||||
|
||||
(defgroup org-ac nil
|
||||
"Auto completion for org-mode."
|
||||
:group 'org
|
||||
:prefix "org-ac/")
|
||||
|
||||
(defcustom org-ac/ac-trigger-command-keys '("\\" "*" "SPC" ":" "[" "+")
|
||||
"Keystrokes for doing `ac-start' with self insert."
|
||||
:type '(repeat string)
|
||||
:group 'org-ac)
|
||||
|
||||
|
||||
(log4e:deflogger "org-ac" "%t [%l] %m" "%H:%M:%S" '((fatal . "fatal")
|
||||
(error . "error")
|
||||
(warn . "warn")
|
||||
(info . "info")
|
||||
(debug . "debug")
|
||||
(trace . "trace")))
|
||||
(org-ac--log-set-level 'trace)
|
||||
|
||||
|
||||
(defun* org-ac--show-message (msg &rest args)
|
||||
(apply 'message (concat "[ORG-AC] " msg) args)
|
||||
nil)
|
||||
|
||||
(defun org-ac--complete-close-option-at-current-point ()
|
||||
(let ((pt (point)))
|
||||
(yaxception:$
|
||||
(yaxception:try
|
||||
(org-ac--trace "start complete close option at current point")
|
||||
(when (save-excursion
|
||||
(re-search-backward "#\\+\\(begin\\|BEGIN\\)_\\([a-zA-Z0-9]+\\) *\\=" nil t))
|
||||
(let* ((opennm (match-string-no-properties 1))
|
||||
(typenm (match-string-no-properties 2))
|
||||
(closenm (cond ((string= opennm "begin") "end")
|
||||
((string= opennm "BEGIN") "END")))
|
||||
(case-fold-search t))
|
||||
(if (or (not (re-search-forward "^[ \t]*#\\+" nil t))
|
||||
(not (re-search-forward (concat "\\=" closenm "_") nil t)))
|
||||
(progn (goto-char pt)
|
||||
(insert "\n#+" closenm "_" typenm)
|
||||
(org-cycle))
|
||||
(let ((currtypenm (if (re-search-forward "\\=\\([a-zA-Z0-9]+\\)" nil t)
|
||||
(match-string-no-properties 1)
|
||||
"")))
|
||||
(backward-delete-char (+ (length closenm)
|
||||
1
|
||||
(length currtypenm)))
|
||||
(insert closenm "_" typenm)))
|
||||
(goto-char pt))))
|
||||
(yaxception:catch 'error e
|
||||
(org-ac--show-message "Failed complete close option : %s" (yaxception:get-text e))
|
||||
(org-ac--error "failed complete close option at current point : %s\n%s"
|
||||
(yaxception:get-text e)
|
||||
(yaxception:get-stack-trace-string e))
|
||||
(goto-char pt)))))
|
||||
|
||||
(defun org-ac--get-link-head-candidates ()
|
||||
(append (ac-pcmp/get-ac-candidates)
|
||||
(mapcar (lambda (x) (concat x ":")) org-link-types)))
|
||||
|
||||
(defvar ac-source-org-ac-tex
|
||||
'((candidates . ac-pcmp/get-ac-candidates)
|
||||
(prefix . "\\\\\\([a-zA-Z0-9_-]*\\)")
|
||||
(symbol . "t")
|
||||
(requires . 0)
|
||||
(cache)
|
||||
(action . ac-pcmp/do-ac-action)))
|
||||
|
||||
(defvar ac-source-org-ac-head
|
||||
'((candidates . ac-pcmp/get-ac-candidates)
|
||||
(prefix . "[^\r\n*]\\*\\([^\t\r\n]*\\)")
|
||||
(symbol . "h")
|
||||
(requires . 0)
|
||||
(cache)
|
||||
(action . ac-pcmp/do-ac-action)))
|
||||
|
||||
(defvar ac-source-org-ac-todo
|
||||
'((candidates . ac-pcmp/get-ac-candidates)
|
||||
(prefix . "^\\*+ \\([a-zA-Z0-9_-]*\\)")
|
||||
(symbol . "d")
|
||||
(requires . 0)
|
||||
(cache)
|
||||
(action . ac-pcmp/do-ac-action)))
|
||||
|
||||
(defvar ac-source-org-ac-tag
|
||||
'((candidates . ac-pcmp/get-ac-candidates)
|
||||
(prefix . "[ \t]:\\([a-zA-Z0-9_-]*\\)")
|
||||
(symbol . "t")
|
||||
(requires . 0)
|
||||
(cache)
|
||||
(action . ac-pcmp/do-ac-action)))
|
||||
|
||||
(defvar org-ac--regexp-link-head (rx-to-string `(and "["
|
||||
(* (any " \t"))
|
||||
"["
|
||||
(group (* (not (any ":*]")))))))
|
||||
(defvar ac-source-org-ac-link-head
|
||||
`((candidates . org-ac--get-link-head-candidates)
|
||||
(prefix . ,org-ac--regexp-link-head)
|
||||
(symbol . "l")
|
||||
(requires . 0)
|
||||
(cache)
|
||||
(action . (lambda ()
|
||||
(ac-pcmp/do-ac-action)
|
||||
(ac-start)))))
|
||||
|
||||
(defvar ac-source-org-ac-option
|
||||
'((candidates . ac-pcmp/get-ac-candidates)
|
||||
(prefix . "^[ \t]*#\\+\\([a-zA-Z0-9_:=-]*\\)")
|
||||
(symbol . "o")
|
||||
(requires . 0)
|
||||
(cache)
|
||||
(action . (lambda ()
|
||||
(ac-pcmp/do-ac-action)
|
||||
(org-ac--complete-close-option-at-current-point)
|
||||
(auto-complete '(ac-source-org-ac-option-key))))))
|
||||
|
||||
(defvar ac-source-org-ac-option-key
|
||||
'((candidates . ac-pcmp/get-ac-candidates)
|
||||
(prefix . "^[ \t]*#\\+[a-zA-Z0-9_:=-]+ +\\([a-zA-Z0-9_-]*\\)")
|
||||
(symbol . "k")
|
||||
(requires . 0)
|
||||
(cache)
|
||||
(action . ac-pcmp/do-ac-action)))
|
||||
|
||||
(defvar ac-source-org-ac-option-options
|
||||
'((candidates . ac-pcmp/get-ac-candidates)
|
||||
(prefix . "^[ \t]*#\\+\\(?:options\\|OPTIONS\\):.* +\\([a-zA-Z0-9_-]*\\)")
|
||||
(symbol . "x")
|
||||
(requires . 0)
|
||||
(cache)
|
||||
(action . ac-pcmp/do-ac-action)))
|
||||
|
||||
(defvar ac-source-org-ac-file
|
||||
'((init . (setq ac-filename-cache nil))
|
||||
(candidates . org-ac/file-candidate)
|
||||
(prefix . "\\[file:\\(.*\\)")
|
||||
(symbol . "f")
|
||||
(requires . 0)
|
||||
(action . ac-start)
|
||||
(limit . nil)))
|
||||
|
||||
|
||||
;;;###autoload
|
||||
(defun org-ac/setup-current-buffer ()
|
||||
"Do setup for using org-ac in current buffer."
|
||||
(interactive)
|
||||
(when (eq major-mode 'org-mode)
|
||||
(loop for stroke in org-ac/ac-trigger-command-keys
|
||||
do (local-set-key (read-kbd-macro stroke) 'ac-pcmp/self-insert-command-with-ac-start))
|
||||
(add-to-list 'ac-sources 'ac-source-org-ac-tex)
|
||||
(add-to-list 'ac-sources 'ac-source-org-ac-head)
|
||||
(add-to-list 'ac-sources 'ac-source-org-ac-todo)
|
||||
(add-to-list 'ac-sources 'ac-source-org-ac-tag)
|
||||
(add-to-list 'ac-sources 'ac-source-org-ac-link-head)
|
||||
(add-to-list 'ac-sources 'ac-source-org-ac-option)
|
||||
(add-to-list 'ac-sources 'ac-source-org-ac-option-key)
|
||||
(add-to-list 'ac-sources 'ac-source-org-ac-option-options)
|
||||
(add-to-list 'ac-sources 'ac-source-org-ac-file)
|
||||
(auto-complete-mode t)))
|
||||
|
||||
;;;###autoload
|
||||
(defun org-ac/config-default ()
|
||||
"Do setting recommemded configuration."
|
||||
(add-to-list 'ac-modes 'org-mode)
|
||||
(add-hook 'org-mode-hook 'org-ac/setup-current-buffer t))
|
||||
|
||||
|
||||
(defun org-ac/file-candidate ()
|
||||
"Adds [file: to the normal file completition, plus allows relative paths"
|
||||
(if (string-match "^[~./]+" ac-prefix)
|
||||
(ac-filename-candidate)
|
||||
(let ((ac-prefix (concat "./" ac-prefix)))
|
||||
(mapcar (lambda (path) (substring path 2))
|
||||
(ac-filename-candidate)))))
|
||||
|
||||
|
||||
(provide 'org-ac)
|
||||
;;; org-ac.el ends here
|
483
.emacs.d/plugins/smex.el
Normal file
483
.emacs.d/plugins/smex.el
Normal file
@ -0,0 +1,483 @@
|
||||
;;; smex.el --- M-x interface with Ido-style fuzzy matching. -*- lexical-binding: t; -*-
|
||||
|
||||
;; Copyright (C) 2009-2014 Cornelius Mika and contributors
|
||||
;;
|
||||
;; Author: Cornelius Mika <cornelius.mika@gmail.com> and contributors
|
||||
;; URL: http://github.com/nonsequitur/smex/
|
||||
;; Package-Requires: ((emacs "24"))
|
||||
;; Version: 3.0
|
||||
;; Keywords: convenience, usability
|
||||
|
||||
;; This file is not part of GNU Emacs.
|
||||
|
||||
;;; License:
|
||||
|
||||
;; Licensed under the same terms as Emacs.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; Quick start:
|
||||
;; run (smex-initialize)
|
||||
;;
|
||||
;; Bind the following commands:
|
||||
;; smex, smex-major-mode-commands
|
||||
;;
|
||||
;; For a detailed introduction see:
|
||||
;; http://github.com/nonsequitur/smex/blob/master/README.markdown
|
||||
|
||||
;;; Code:
|
||||
|
||||
(require 'ido)
|
||||
|
||||
(defgroup smex nil
|
||||
"M-x interface with Ido-style fuzzy matching and ranking heuristics."
|
||||
:group 'extensions
|
||||
:group 'convenience
|
||||
:link '(emacs-library-link :tag "Lisp File" "smex.el"))
|
||||
|
||||
(defcustom smex-auto-update t
|
||||
"If non-nil, `Smex' checks for new commands each time it is run.
|
||||
Turn it off for minor speed improvements on older systems."
|
||||
:type 'boolean
|
||||
:group 'smex)
|
||||
|
||||
(defcustom smex-save-file (locate-user-emacs-file "smex-items" ".smex-items")
|
||||
"File in which the smex state is saved between Emacs sessions.
|
||||
Variables stored are: `smex-data', `smex-history'.
|
||||
Must be set before initializing Smex."
|
||||
:type 'string
|
||||
:group 'smex)
|
||||
|
||||
(defcustom smex-history-length 7
|
||||
"Determines on how many recently executed commands
|
||||
Smex should keep a record.
|
||||
Must be set before initializing Smex."
|
||||
:type 'integer
|
||||
:group 'smex)
|
||||
|
||||
(defcustom smex-prompt-string "M-x "
|
||||
"String to display in the Smex prompt."
|
||||
:type 'string
|
||||
:group 'smex)
|
||||
|
||||
(defcustom smex-flex-matching t
|
||||
"Enables Ido flex matching. On by default.
|
||||
Set this to nil to disable fuzzy matching."
|
||||
:type 'boolean
|
||||
:group 'smex)
|
||||
|
||||
(defvar smex-initialized-p nil)
|
||||
(defvar smex-cache)
|
||||
(defvar smex-ido-cache)
|
||||
(defvar smex-data)
|
||||
(defvar smex-history)
|
||||
(defvar smex-command-count 0)
|
||||
(defvar smex-custom-action nil)
|
||||
|
||||
;; Check if Smex is supported
|
||||
(when (equal (cons 1 1)
|
||||
(ignore-errors
|
||||
(subr-arity (symbol-function 'execute-extended-command))))
|
||||
(error "Your Emacs has a non-elisp version of `execute-extended-command', which is incompatible with Smex"))
|
||||
|
||||
;;--------------------------------------------------------------------------------
|
||||
;; Smex Interface
|
||||
|
||||
;;;###autoload
|
||||
(defun smex ()
|
||||
(interactive)
|
||||
(unless smex-initialized-p
|
||||
(smex-initialize))
|
||||
(if (smex-already-running)
|
||||
(smex-update-and-rerun)
|
||||
(and smex-auto-update
|
||||
(smex-detect-new-commands)
|
||||
(smex-update))
|
||||
(smex-read-and-run smex-ido-cache)))
|
||||
|
||||
(defun smex-already-running ()
|
||||
(and (boundp 'ido-choice-list)
|
||||
(eql ido-choice-list smex-ido-cache)
|
||||
(minibuffer-window-active-p (selected-window))))
|
||||
|
||||
(defun smex-update-and-rerun ()
|
||||
(smex-do-with-selected-item
|
||||
(lambda (_) (smex-update) (smex-read-and-run smex-ido-cache ido-text))))
|
||||
|
||||
(defun smex-read-and-run (commands &optional initial-input)
|
||||
(let* ((chosen-item-name (smex-completing-read commands initial-input))
|
||||
(chosen-item (intern chosen-item-name)))
|
||||
(if smex-custom-action
|
||||
(let ((action smex-custom-action))
|
||||
(setq smex-custom-action nil)
|
||||
(funcall action chosen-item))
|
||||
(unwind-protect
|
||||
(with-no-warnings ; Don't warn about interactive use of `execute-extended-command'
|
||||
(execute-extended-command current-prefix-arg chosen-item-name))
|
||||
(smex-rank chosen-item)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun smex-major-mode-commands ()
|
||||
"Like `smex', but limited to commands that are relevant to the active major mode."
|
||||
(interactive)
|
||||
(unless smex-initialized-p
|
||||
(smex-initialize))
|
||||
(let ((commands (delete-dups (append (smex-extract-commands-from-keymap (current-local-map))
|
||||
(smex-extract-commands-from-features major-mode)))))
|
||||
(setq commands (smex-sort-according-to-cache commands))
|
||||
(setq commands (mapcar #'symbol-name commands))
|
||||
(smex-read-and-run commands)))
|
||||
|
||||
(defun smex-completing-read (choices initial-input)
|
||||
(let ((ido-completion-map ido-completion-map)
|
||||
(ido-setup-hook (cons 'smex-prepare-ido-bindings ido-setup-hook))
|
||||
(ido-enable-prefix nil)
|
||||
(ido-enable-flex-matching smex-flex-matching)
|
||||
(ido-max-prospects 10)
|
||||
(minibuffer-completion-table choices))
|
||||
(ido-completing-read (smex-prompt-with-prefix-arg) choices nil nil
|
||||
initial-input 'extended-command-history (car choices))))
|
||||
|
||||
(defun smex-prompt-with-prefix-arg ()
|
||||
(if (not current-prefix-arg)
|
||||
smex-prompt-string
|
||||
(concat
|
||||
(if (eq current-prefix-arg '-)
|
||||
"- "
|
||||
(if (integerp current-prefix-arg)
|
||||
(format "%d " current-prefix-arg)
|
||||
(if (= (car current-prefix-arg) 4)
|
||||
"C-u "
|
||||
(format "%d " (car current-prefix-arg)))))
|
||||
smex-prompt-string)))
|
||||
|
||||
(defun smex-prepare-ido-bindings ()
|
||||
(define-key ido-completion-map (kbd "TAB") 'minibuffer-complete)
|
||||
(define-key ido-completion-map (kbd "C-h f") 'smex-describe-function)
|
||||
(define-key ido-completion-map (kbd "C-h w") 'smex-where-is)
|
||||
(define-key ido-completion-map (kbd "M-.") 'smex-find-function)
|
||||
(define-key ido-completion-map (kbd "C-a") 'move-beginning-of-line))
|
||||
|
||||
;;--------------------------------------------------------------------------------
|
||||
;; Cache and Maintenance
|
||||
|
||||
(defun smex-rebuild-cache ()
|
||||
(interactive)
|
||||
(setq smex-cache nil)
|
||||
|
||||
;; Build up list 'new-commands' and later put it at the end of 'smex-cache'.
|
||||
;; This speeds up sorting.
|
||||
(let (new-commands)
|
||||
(mapatoms (lambda (symbol)
|
||||
(when (commandp symbol)
|
||||
(let ((known-command (assq symbol smex-data)))
|
||||
(if known-command
|
||||
(setq smex-cache (cons known-command smex-cache))
|
||||
(setq new-commands (cons (list symbol) new-commands)))))))
|
||||
(if (eq (length smex-cache) 0)
|
||||
(setq smex-cache new-commands)
|
||||
(setcdr (last smex-cache) new-commands)))
|
||||
|
||||
(setq smex-cache (sort smex-cache 'smex-sorting-rules))
|
||||
(smex-restore-history)
|
||||
(setq smex-ido-cache (smex-convert-for-ido smex-cache)))
|
||||
|
||||
(defun smex-convert-for-ido (command-items)
|
||||
(mapcar (lambda (command-item) (symbol-name (car command-item))) command-items))
|
||||
|
||||
(defun smex-restore-history ()
|
||||
"Rearranges `smex-cache' according to `smex-history'"
|
||||
(if (> (length smex-history) smex-history-length)
|
||||
(setcdr (nthcdr (- smex-history-length 1) smex-history) nil))
|
||||
(mapc (lambda (command)
|
||||
(unless (eq command (caar smex-cache))
|
||||
(let ((command-cell-position (smex-detect-position
|
||||
smex-cache
|
||||
(lambda (cell)
|
||||
(eq command (caar cell))))))
|
||||
(when command-cell-position
|
||||
(let ((command-cell (smex-remove-nth-cell
|
||||
command-cell-position smex-cache)))
|
||||
(setcdr command-cell smex-cache)
|
||||
(setq smex-cache command-cell))))))
|
||||
(reverse smex-history)))
|
||||
|
||||
(defun smex-sort-according-to-cache (list)
|
||||
"Sorts a list of commands by their order in `smex-cache'"
|
||||
(let (sorted)
|
||||
(dolist (command-item smex-cache)
|
||||
(let ((command (car command-item)))
|
||||
(when (memq command list)
|
||||
(setq sorted (cons command sorted))
|
||||
(setq list (delq command list)))))
|
||||
(nreverse (append list sorted))))
|
||||
|
||||
(defun smex-update ()
|
||||
(interactive)
|
||||
(smex-save-history)
|
||||
(smex-rebuild-cache))
|
||||
|
||||
(defun smex-detect-new-commands ()
|
||||
(let ((i 0))
|
||||
(mapatoms (lambda (symbol) (if (commandp symbol) (setq i (1+ i)))))
|
||||
(unless (= i smex-command-count)
|
||||
(setq smex-command-count i))))
|
||||
|
||||
(defun smex-auto-update (&optional idle-time)
|
||||
"Update Smex when Emacs has been idle for IDLE-TIME."
|
||||
(unless idle-time (setq idle-time 60))
|
||||
(run-with-idle-timer idle-time t
|
||||
'(lambda () (if (smex-detect-new-commands) (smex-update)))))
|
||||
|
||||
;;;###autoload
|
||||
(defun smex-initialize ()
|
||||
(interactive)
|
||||
(unless ido-mode (smex-initialize-ido))
|
||||
(smex-load-save-file)
|
||||
(smex-detect-new-commands)
|
||||
(smex-rebuild-cache)
|
||||
(add-hook 'kill-emacs-hook 'smex-save-to-file)
|
||||
(setq smex-initialized-p t))
|
||||
|
||||
(defun smex-initialize-ido ()
|
||||
"Sets up a minimal Ido environment for `ido-completing-read'."
|
||||
(with-no-warnings ; `ido-init-completion-maps' is deprecated in Emacs 25
|
||||
(ido-init-completion-maps))
|
||||
(add-hook 'minibuffer-setup-hook 'ido-minibuffer-setup))
|
||||
|
||||
(defsubst smex-save-file-not-empty-p ()
|
||||
(string-match-p "\[^[:space:]\]" (buffer-string)))
|
||||
|
||||
(defun smex-load-save-file ()
|
||||
"Loads `smex-history' and `smex-data' from `smex-save-file'"
|
||||
(let ((save-file (expand-file-name smex-save-file)))
|
||||
(if (file-readable-p save-file)
|
||||
(with-temp-buffer
|
||||
(insert-file-contents save-file)
|
||||
(condition-case nil
|
||||
(setq smex-history (read (current-buffer))
|
||||
smex-data (read (current-buffer)))
|
||||
(error (if (smex-save-file-not-empty-p)
|
||||
(error "Invalid data in smex-save-file (%s). Can't restore history."
|
||||
smex-save-file)
|
||||
(unless (boundp 'smex-history) (setq smex-history nil))
|
||||
(unless (boundp 'smex-data) (setq smex-data nil))))))
|
||||
(setq smex-history nil smex-data nil))))
|
||||
|
||||
(defun smex-save-history ()
|
||||
"Updates `smex-history'"
|
||||
(setq smex-history nil)
|
||||
(let ((cell smex-cache))
|
||||
(dotimes (_ smex-history-length)
|
||||
(setq smex-history (cons (caar cell) smex-history))
|
||||
(setq cell (cdr cell))))
|
||||
(setq smex-history (nreverse smex-history)))
|
||||
|
||||
(defmacro smex-pp (list-var)
|
||||
`(smex-pp* ,list-var ,(symbol-name list-var)))
|
||||
|
||||
(defun smex-save-to-file ()
|
||||
(interactive)
|
||||
(smex-save-history)
|
||||
(with-temp-file (expand-file-name smex-save-file)
|
||||
(smex-pp smex-history)
|
||||
(smex-pp smex-data)))
|
||||
|
||||
;;--------------------------------------------------------------------------------
|
||||
;; Ranking
|
||||
|
||||
(defun smex-sorting-rules (command-item other-command-item)
|
||||
"Returns true if COMMAND-ITEM should sort before OTHER-COMMAND-ITEM."
|
||||
(let* ((count (or (cdr command-item ) 0))
|
||||
(other-count (or (cdr other-command-item) 0))
|
||||
(name (car command-item))
|
||||
(other-name (car other-command-item))
|
||||
(length (length (symbol-name name)))
|
||||
(other-length (length (symbol-name other-name))))
|
||||
(or (> count other-count) ; 1. Frequency of use
|
||||
(and (= count other-count)
|
||||
(or (< length other-length) ; 2. Command length
|
||||
(and (= length other-length)
|
||||
(string< name other-name))))))) ; 3. Alphabetical order
|
||||
|
||||
(defun smex-rank (command)
|
||||
(let ((command-item (or (assq command smex-cache)
|
||||
;; Update caches and try again if not found.
|
||||
(progn (smex-update)
|
||||
(assq command smex-cache)))))
|
||||
(when command-item
|
||||
(smex-update-counter command-item)
|
||||
|
||||
;; Don't touch the cache order if the chosen command
|
||||
;; has just been execucted previously.
|
||||
(unless (eq command-item (car smex-cache))
|
||||
(let (command-cell
|
||||
(pos (smex-detect-position smex-cache (lambda (cell)
|
||||
(eq command-item (car cell))))))
|
||||
;; Remove the just executed command.
|
||||
(setq command-cell (smex-remove-nth-cell pos smex-cache))
|
||||
;; And put it on top of the cache.
|
||||
(setcdr command-cell smex-cache)
|
||||
(setq smex-cache command-cell)
|
||||
|
||||
;; Repeat the same for the ido cache. Should this be DRYed?
|
||||
(setq command-cell (smex-remove-nth-cell pos smex-ido-cache))
|
||||
(setcdr command-cell smex-ido-cache)
|
||||
(setq smex-ido-cache command-cell)
|
||||
|
||||
;; Now put the last history item back to its normal place.
|
||||
(smex-sort-item-at smex-history-length))))))
|
||||
|
||||
(defun smex-update-counter (command-item)
|
||||
(let ((count (cdr command-item)))
|
||||
(setcdr command-item
|
||||
(if count
|
||||
(1+ count)
|
||||
;; Else: Command has just been executed for the first time.
|
||||
;; Add it to `smex-data'.
|
||||
(if smex-data
|
||||
(setcdr (last smex-data) (list command-item))
|
||||
(setq smex-data (list command-item)))
|
||||
1))))
|
||||
|
||||
(defun smex-sort-item-at (n)
|
||||
"Sorts item at position N in `smex-cache'."
|
||||
(let* ((command-cell (nthcdr n smex-cache))
|
||||
(command-item (car command-cell)))
|
||||
(let ((insert-at (smex-detect-position
|
||||
command-cell
|
||||
(lambda (cell)
|
||||
(smex-sorting-rules command-item (car cell))))))
|
||||
;; TODO: Should we handle the case of 'insert-at' being nil?
|
||||
;; This will never happen in practice.
|
||||
(when (> insert-at 1)
|
||||
(setq command-cell (smex-remove-nth-cell n smex-cache))
|
||||
;; smex-cache just got shorter by one element, so subtract '1' from insert-at.
|
||||
(setq insert-at (+ n (- insert-at 1)))
|
||||
(smex-insert-cell command-cell insert-at smex-cache)
|
||||
|
||||
;; Repeat the same for the ido cache. DRY?
|
||||
(setq command-cell (smex-remove-nth-cell n smex-ido-cache))
|
||||
(smex-insert-cell command-cell insert-at smex-ido-cache)))))
|
||||
|
||||
(defun smex-detect-position (cell function)
|
||||
"Detects, relatively to CELL, the position of the cell
|
||||
on which FUNCTION returns true.
|
||||
Only checks cells after CELL, starting with the cell right after CELL.
|
||||
Returns nil when reaching the end of the list."
|
||||
(let ((pos 1))
|
||||
(catch 'break
|
||||
(while t
|
||||
(setq cell (cdr cell))
|
||||
(if (not cell)
|
||||
(throw 'break nil)
|
||||
(if (funcall function cell) (throw 'break pos))
|
||||
(setq pos (1+ pos)))))))
|
||||
|
||||
(defun smex-remove-nth-cell (n list)
|
||||
"Removes and returns the Nth cell in LIST."
|
||||
(let* ((previous-cell (nthcdr (- n 1) list))
|
||||
(result (cdr previous-cell)))
|
||||
(setcdr previous-cell (cdr result))
|
||||
result))
|
||||
|
||||
(defun smex-insert-cell (new-cell n list)
|
||||
"Inserts cell at position N in LIST."
|
||||
(let* ((cell (nthcdr (- n 1) list))
|
||||
(next-cell (cdr cell)))
|
||||
(setcdr (setcdr cell new-cell) next-cell)))
|
||||
|
||||
;;--------------------------------------------------------------------------------
|
||||
;; Help and Reference
|
||||
|
||||
(defun smex-do-with-selected-item (fn)
|
||||
(setq smex-custom-action fn)
|
||||
(ido-exit-minibuffer))
|
||||
|
||||
(defun smex-describe-function ()
|
||||
(interactive)
|
||||
(smex-do-with-selected-item (lambda (chosen)
|
||||
(describe-function chosen)
|
||||
(pop-to-buffer "*Help*"))))
|
||||
|
||||
(defun smex-where-is ()
|
||||
(interactive)
|
||||
(smex-do-with-selected-item 'where-is))
|
||||
|
||||
(defun smex-find-function ()
|
||||
(interactive)
|
||||
(smex-do-with-selected-item 'find-function))
|
||||
|
||||
(defun smex-extract-commands-from-keymap (map)
|
||||
(let (commands)
|
||||
(smex-parse-keymap map commands)
|
||||
commands))
|
||||
|
||||
(defun smex-parse-keymap (map commands)
|
||||
(map-keymap (lambda (_binding element)
|
||||
(if (and (listp element) (eq 'keymap (car element)))
|
||||
(smex-parse-keymap element commands)
|
||||
;; Strings are commands, too. Reject them.
|
||||
(if (and (symbolp element) (commandp element))
|
||||
(push element commands))))
|
||||
map))
|
||||
|
||||
(defun smex-extract-commands-from-features (mode)
|
||||
(let ((library-path (symbol-file mode))
|
||||
(mode-name (symbol-name mode))
|
||||
commands)
|
||||
|
||||
(string-match "\\(.+?\\)\\(-mode\\)?$" mode-name)
|
||||
;; 'lisp-mode' -> 'lisp'
|
||||
(setq mode-name (match-string 1 mode-name))
|
||||
(if (string= mode-name "c") (setq mode-name "cc"))
|
||||
(setq mode-name (regexp-quote mode-name))
|
||||
|
||||
(dolist (feature load-history)
|
||||
(let ((feature-path (car feature)))
|
||||
(when (and feature-path (or (equal feature-path library-path)
|
||||
(string-match mode-name (file-name-nondirectory
|
||||
feature-path))))
|
||||
(dolist (item (cdr feature))
|
||||
(if (and (listp item) (eq 'defun (car item)))
|
||||
(let ((function (cdr item)))
|
||||
(when (commandp function)
|
||||
(setq commands (append commands (list function))))))))))
|
||||
commands))
|
||||
|
||||
(defun smex-show-unbound-commands ()
|
||||
"Shows unbound commands in a new buffer,
|
||||
sorted by frequency of use."
|
||||
(interactive)
|
||||
(setq smex-data (sort smex-data 'smex-sorting-rules))
|
||||
(let ((unbound-commands (delq nil
|
||||
(mapcar (lambda (command-item)
|
||||
(unless (where-is-internal (car command-item))
|
||||
command-item))
|
||||
smex-data))))
|
||||
(view-buffer-other-window "*Smex: Unbound Commands*")
|
||||
(setq buffer-read-only t)
|
||||
(let ((inhibit-read-only t))
|
||||
(erase-buffer)
|
||||
(smex-pp unbound-commands))
|
||||
(set-buffer-modified-p nil)
|
||||
(goto-char (point-min))))
|
||||
|
||||
;; A copy of `ido-pp' that's compatible with lexical bindings
|
||||
(defun smex-pp* (list list-name)
|
||||
(let ((print-level nil) (eval-expression-print-level nil)
|
||||
(print-length nil) (eval-expression-print-length nil))
|
||||
(insert "\n;; ----- " list-name " -----\n(\n ")
|
||||
(while list
|
||||
(let* ((elt (car list))
|
||||
(s (if (consp elt) (car elt) elt)))
|
||||
(if (and (stringp s) (= (length s) 0))
|
||||
(setq s nil))
|
||||
(if s
|
||||
(prin1 elt (current-buffer)))
|
||||
(if (and (setq list (cdr list)) s)
|
||||
(insert "\n "))))
|
||||
(insert "\n)\n")))
|
||||
|
||||
(provide 'smex)
|
||||
;;; smex.el ends here
|
Reference in New Issue
Block a user