Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 95 lines (77 sloc) 3.383 kB
ee6736a @technomancy Add pcmpl-lein.el for eshell completion.
authored
1 ;;; pcmpl-lein.el --- pcomplete for Leiningen tasks; works with eshell
2
3 ;; Copyright (C) 2011 Phil Hagelberg
4 ;;
5 ;; Author: Phil Hagelberg
6 ;; URL: http://github.com/technomancy/leiningen
7 ;; Version: 0.1
8 ;; Keywords: eshell completion
9 ;; Created: 2011-01-15
10
11 ;; This file is not part of GNU Emacs.
12
13 ;;; Commentary:
14
15 ;; Provides completion of leiningen tasks using pcomplete, suitable
16 ;; for eshell. Does not support custom :source-path or :test-path.
17
18 ;;; License:
19
20 ;; This program is free software; you can redistribute it and/or
21 ;; modify it under the terms of the GNU General Public License
22 ;; as published by the Free Software Foundation; either version 3
23 ;; of the License, or (at your option) any later version.
24 ;;
25 ;; This program is distributed in the hope that it will be useful,
26 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
27 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 ;; GNU General Public License for more details.
29 ;;
30 ;; You should have received a copy of the GNU General Public License
31 ;; along with GNU Emacs; see the file COPYING. If not, write to the
32 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
33 ;; Boston, MA 02110-1301, USA.
34
35 ;;; Code:
36
37 (require 'cl)
38 (require 'pcomplete)
39 (require 'esh-util)
40
41 (defvar pcmpl-lein-tasks-alist nil
42 "Cached alist of project roots to task lists.")
43
44 (defvar pcmpl-lein-project-root nil)
45
46 (defun pcmpl-lein-tasks ()
47 (or (cdr (assoc pcmpl-lein-project-root pcmpl-lein-tasks-alist))
48 (let* ((help (progn (message "Getting Leiningen task list...")
49 (shell-command-to-string "lein help")))
50 (tasks (split-string help "\n"))
51 (tasks (subseq tasks 4 -3))
52 (tasks (mapcar (lambda (line)
53 (substring line 0 (string-match " " line)))
54 tasks)))
55 ;; OHAI MEMOIZE.
56 (add-to-list 'pcmpl-lein-tasks-alist
57 (cons pcmpl-lein-project-root tasks))
58 tasks)))
59
60 (defun pcmpl-lein-namespaces-dir ()
61 (let ((task (cadr pcomplete-args)))
62 (cond ((equal "test" task) "test")
63 ((or (equal "run" task) (equal "compile" task)) "src"))))
64
65 (defun pcmpl-lein-transform-filename (file)
66 (subst-char-in-string ?/ ?.
67 (substring file (+ (length pcmpl-lein-project-root)
68 (length namespaces-dir) 1) -4)))
69
70 (defun pcmpl-lein-namespaces-in-dir (file)
71 (if (not (file-directory-p file))
72 (if (string-match "\\.clj$" file)
73 (pcmpl-lein-transform-filename file))
74 (eshell-flatten-list (mapcar 'pcmpl-lein-namespaces-in-dir
75 (directory-files file t "^[^\\.]")))))
76
77 (defun pcmpl-lein-namespaces ()
78 (let ((namespaces-dir (pcmpl-lein-namespaces-dir)))
79 (when namespaces-dir
80 (pcmpl-lein-namespaces-in-dir namespaces-dir))))
81
82 ;;;###autoload
83 (defun pcomplete/lein ()
84 (let ((pcmpl-lein-project-root (expand-file-name
85 (locate-dominating-file
86 default-directory "project.clj"))))
87 (pcomplete-here (pcmpl-lein-tasks))
88 (if (not (string= "run" (cadr pcomplete-args)))
89 (pcomplete-here (pcmpl-lein-namespaces))
90 (pcomplete-here (list "-m"))
91 (pcomplete-here (pcmpl-lein-namespaces)))))
92
93 (provide 'pcmpl-lein)
94 ;;; pcmpl-lein.el ends here
Something went wrong with that request. Please try again.