Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
445 lines (383 sloc) 16.2 KB
(require 'comint)
(require 'dss-paths)
(eval-when-compile (require 'cl))
(setq-default abbrev-mode t)
(setq save-abbrevs t)
(setq abbrev-file-name (concat dss-ephemeral-dir "abbrev_defs"))
(if (file-exists-p abbrev-file-name)
(read-abbrev-file abbrev-file-name t))
;; ido
(require 'ido)
(ido-mode t) ; use 'buffer rather than t to use only buffer switching
(ido-everywhere t)
(setq ido-enable-flex-matching t)
(setq ido-auto-merge-work-directories-length -1)
;; from
ido-ignore-buffers '("\\` " "^\*Back" ".*Completions\*" "^\*Ido" "^\*trace"
"^\*compilation" "^\*GTAGS" "^session\.*")
;ido-work-directory-list '("~/" "~/Desktop" "~/Documents" "~src")
ido-case-fold t
ido-enable-last-directory-history t ; remember last used dirs
ido-max-work-file-list 50 ; remember many
ido-use-filename-at-point nil
ido-use-url-at-point nil
;ido-max-prospects 8 ; don't spam my minibuffer
;ido-confirm-unique-completion t ; wait for RET, even with unique completion
ido-save-directory-list-file (concat dss-ephemeral-dir "ido.last"))
(defvar dss-minibuffer-truncate-lines t)
(defun dss/minibuffer-setup-hook ()
;; in the future I'll change this so it looks to see if
;; linum-mode is active in any of this frame's windows. if the mini
;; buffer lines are not truncated, and linum-mode is active the line
;; numbers interactive the margin flicker annoyingly.
(when dss-minibuffer-truncate-lines
(setq truncate-lines t)))
(add-hook 'minibuffer-setup-hook 'dss/minibuffer-setup-hook)
(defun dss/ido-find-file-at-point ()
(let ((ido-use-filename-at-point t)
(ido-use-url-at-point t))
(call-interactively 'ido-find-file)))
(defvar ido-enable-replace-completing-read t
"If t, use ido-completing-read instead of completing-read if possible.
Set it to nil using let in around-advice for functions where the
original completing-read is required. For example, if a function
foo absolutely must use the original completing-read, define some
advice like this:
\(defadvice foo (around original-completing-read-only activate)
(let (ido-enable-replace-completing-read) ad-do-it))")
;; Replace completing-read wherever possible, unless directed otherwise
(defadvice completing-read
(around use-ido-when-possible activate)
(if (or (not ido-enable-replace-completing-read) ; Manual override disable ido
(boundp 'ido-cur-list)) ; Avoid infinite loop from ido calling this
(let ((allcomp (all-completions "" collection predicate)))
(if allcomp
(setq ad-return-value
(ido-completing-read prompt
nil require-match initial-input hist def))
ad-do-it))) " ")
;; (setq ido-enable-replace-completing-read t)
;; (defadvice where-is
;; (around where-is-completing-read-only activate)
;; (let (ido-enable-replace-completing-read) ad-do-it))
(defun dss/where-is ()
"wrapper around where-is that doesn't use ido for completion"
(let (ido-enable-replace-completing-read)
(call-interactively 'where-is)))
(defun dss/execute-extended-command ()
"wrapper around execute-extended-command that doesn't use ido for completion"
(let (ido-enable-replace-completing-read)
(call-interactively 'execute-extended-command)))
(defun dss/load-library ()
"wrapper around load-library that doesn't use ido for completion"
(let (ido-enable-replace-completing-read)
(call-interactively 'load-library)))
(defun dss/ido-search-file (dir pattern ex-pattern)
(let* ((file-list
"DIR=" dir ";"
"find $DIR -type f -regex '" pattern "'"
" -not -regex '" ex-pattern "' "
"| sed -e's#'$DIR'##'"))))
(choice (ido-completing-read "Which file: " file-list)))
(find-file (concat dir choice))))
(defun dss/insert-path (file)
"insert file"
(interactive "FPath: ")
(insert (replace-regexp-in-string (getenv "HOME") "~" (expand-file-name file))))
;; dabbrev and hippie-expand
(setq-default dabbrev-case-replace nil)
(setq-default hippie-expand-try-functions-list '(try-expand-abbrev try-expand-dabbrev-visible try-expand-dabbrev))
;; auto-complete mode
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories (concat dss-dotfiles-dir "ac-dict"))
(setq ac-delay 0.2)
(setq ac-auto-show-menu 0.3)
(setq ac-menu-height 20)
(setq ac-use-comphist nil)
(setq ac-candidate-limit 25)
(setq ac-use-quick-help nil)
(defun dss/ac-hide-help ()
(setq ac-use-quick-help nil))
(defun dss/ac-show-help ()
(setq ac-use-quick-help t))
(require 'dss-codenav-helpers)
(defun ac-complete-no-fallback ()
"a hacked version of ac-complete with fallback disabled.
For some reason this is very sensitive to the function name
prefix 'ac-'."
(let* ((candidate (ac-selected-candidate))
(action (popup-item-property candidate 'action))
(fallback nil))
(when candidate
(unless (ac-expand-string candidate)
(setq fallback nil)) ;
;; Remember to show help later
(when (and ac-point candidate)
(unless ac-last-completion
(setq ac-last-completion (cons (make-marker) nil)))
(set-marker (car ac-last-completion) ac-point ac-buffer)
(setcdr ac-last-completion candidate)))
(funcall action))
(defun dss/ac-electric-pair ()
(defun dss/ac-electric-char ()
(call-interactively 'self-insert-command))
(define-key ac-completing-map "(" 'dss/ac-electric-pair)
(define-key ac-completing-map "[" 'dss/ac-electric-pair)
(define-key ac-completing-map "," 'dss/ac-electric-char)
;; (define-key ac-completing-map " " 'dss/ac-electric-char)
(define-key ac-completing-map "\r" 'ac-complete-no-fallback)
;; (define-key ac-completing-map (kbd "M-/") 'dabbrev-completion)
;; (define-key ac-completing-map (kbd "M-/") 'dss/hippie-expand)
(define-key ac-completing-map (kbd "M-/") 'ac-expand)
;;; <up/down> in terminal
(define-key ac-completing-map "\e[A" 'ac-previous)
(define-key ac-completing-map "\e[B" 'ac-next)
;;; C-<up/down> in terminal
(define-key ac-completing-map "\eOa" 'ac-quick-help-scroll-up)
(define-key ac-completing-map "\eOb" 'ac-quick-help-scroll-down)
;;; this seems to be little bit buggy with the most recent version of auto-complete.el ...
(defvar dss-ropemacs-completions-cache nil)
(defun dss/rope-candidates (prefix)
(setq dss-ropemacs-completions-cache
(delete ""
(lambda (completion)
(concat ac-prefix completion))
(ac-define-source dss-rope
'((candidates . (dss/rope-candidates ac-prefix))
(requires . 0)
(cache . t)
(symbol . "f")))
(ac-define-source dss-rope-dot
'((candidates . (dss/rope-candidates ac-prefix))
(prefix . c-dot)
(requires . 0)
(symbol . "f")))
(defvar ac-source-dss-filename '((init setq ac-filename-cache nil)
(candidates . ac-filename-candidate)
(requires . 0)
(action . ac-start)
(prefix . file)
;; also see dss/ropemacs-init in dss-python.el
(defun dss/load-rope-completion()
(setq ac-sources (list
(defun dss/unload-rope-completion()
(setq ac-sources (list
;;; partially working support for using auto complete in ipython buffers
(require 'ipython)
(defun dss-ipython-completion-candidate (&optional use-ido)
"This is a hacked version of ipython-complete from ipython.el,
which can be used with either autocomplete-mode or ido.
It mostly works but there are a few bugs that need resolving...
(defun dss/start-ipy-complete ()
(setq ac-sources '(ac-source-dss-ipy-dot
(add-hook 'ipython-shell-hook 'dss/start-ipy-complete)
(add-hook 'py-shell-hook 'dss/start-ipy-complete)
(let* ((ugly-return nil)
(sep ";")
(python-process (or (get-buffer-process (current-buffer))
;XXX hack for .py buffers
(get-process py-which-bufname)))
(beg (save-excursion (skip-chars-backward "a-z0-9A-Z_." (point-at-bol))
(end (point))
(pattern (buffer-substring-no-properties beg end))
(completions nil)
(completion nil)
(append comint-preoutput-filter-functions
(lambda (string)
(setq ugly-return (concat ugly-return string))
(message pattern)
(process-send-string python-process
(format ipython-completion-command-string pattern))
(accept-process-output python-process)
(setq completions
(split-string (substring ugly-return 0 (position ?\n ugly-return)) sep))
(setq completions (if (string-match "\\." pattern)
(lambda (completion)
(car (last (cdr (split-string completion "\\.")))))
(if use-ido
(let* ((prefix-beg (if (string-match "\\." pattern)
(save-excursion (skip-chars-backward "a-z0-9A-Z_" (point-at-bol))
(prefix (buffer-substring-no-properties prefix-beg end))
(choice (if (<= (length completions) 1)
(car completions)
(ido-completing-read "Choice:" completions nil nil prefix nil prefix)))
(if (and choice (not (string= pattern choice)))
(message "%s %s %s %s" prefix prefix-beg beg (point-at-bol))
(delete-region prefix-beg end)
(insert choice))))
;(message "not using ido")
(defun dss/ido-ipython-complete ()
(dss-ipython-completion-candidate t))
(ac-define-source dss-ipy
'((candidates . dss-ipython-completion-candidate)
(requires . 0)
(symbol . "f")))
(ac-define-source dss-ipy-dot
'((candidates . dss-ipython-completion-candidate)
(prefix . c-dot)
(requires . 0)
(symbol . "f")))
(defvar ac-org-candidates nil)
(defvar ac-org-pattern nil)
(defun ac-org-construct-candidates ()
"Pabbrev source for org."
(let* ((end (point))
(beg1 (save-excursion
(skip-chars-backward (org-re "[:alnum:]_@"))
(beg (save-excursion
(skip-chars-backward "a-zA-Z0-9_:$")
(confirm (lambda (x) (stringp (car x))))
(searchhead (equal (char-before beg) ?*))
(when (and (member (char-before beg1) '(?. ?<))
(setq a (assoc (buffer-substring beg1 (point))
(org-complete-expand-structure-template (1- beg1) a)
(throw 'exit t)))
(tag (and (equal (char-before beg1) ?:)
(equal (char-after (point-at-bol)) ?*)))
(prop (and (equal (char-before beg1) ?:)
(not (equal (char-after (point-at-bol)) ?*))))
(texp (equal (char-before beg) ?\\))
(link (equal (char-before beg) ?\[))
(opt (equal (buffer-substring (max (point-at-bol) (- beg 2))
(startup (string-match "^#\\+STARTUP:.*"
(buffer-substring (point-at-bol) (point))))
(completion-ignore-case opt)
(type nil)
(tbl nil)
(table (cond
(setq type :opt)
(require 'org-exp)
(lambda (x)
(string-match "^#\\+\\(\\([A-Z_]+:?\\).*\\)" x)
(cons (match-string 2 x) (match-string 1 x)))
(org-split-string (org-get-current-options) "\n"))
(mapcar 'list org-additional-option-like-keywords)))
(setq type :startup)
(link (append org-link-abbrev-alist-local
(setq type :tex)
((string-match "\\`\\*+[ \t]+\\'"
(buffer-substring (point-at-bol) beg))
(setq type :todo)
(mapcar 'list org-todo-keywords-1))
(setq type :searchhead)
(goto-char (point-min))
(while (re-search-forward org-todo-line-regexp nil t)
(push (list
(match-string 3) t))
(tag (setq type :tag beg beg1)
(or org-tag-alist (org-get-buffer-tags)))
(prop (setq type :prop beg beg1)
(mapcar 'list (org-buffer-property-keys nil t t)))
(t (progn
(call-interactively org-completion-fallback-command)
(throw 'exit nil))))))
(setq ac-org-pattern (buffer-substring-no-properties beg end))
(defvar ac-source-org nil)
(setq ac-source-org
`((sigil . "o")
(init . (lambda () (setq ac-org-candidates
(condition-case nil
(candidates . (lambda ()
(all-completions ac-target ac-org-candidates)))))
(defun ac-emacs-lisp-mode-setup ()
(setq ac-sources '(ac-source-words-in-buffer ac-source-functions ac-source-variables ac-source-symbols ac-source-features ac-source-yasnippet)))
(provide 'dss-completion)