[emacs] add emacs-nav, PeepOpen, new textmate.el
This commit is contained in:
parent
fd66a0c266
commit
8d05f2637b
8 changed files with 3764 additions and 95 deletions
9
emacs
9
emacs
|
|
@ -69,14 +69,21 @@
|
||||||
(setq track-eol t) ; When at EOL, C-n and C-p move to EOL on other lines
|
(setq track-eol t) ; When at EOL, C-n and C-p move to EOL on other lines
|
||||||
(setq indent-tabs-mode nil) ; never insert tabs
|
(setq indent-tabs-mode nil) ; never insert tabs
|
||||||
|
|
||||||
|
;; nav - awesome filesystem navigation, sort of like TextMate's project drawer
|
||||||
|
(add-to-load-path "~/config/emacs.d/emacs-nav")
|
||||||
|
(require 'nav)
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; textmate mode
|
;; peepopen and textmate mode
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(add-to-list 'load-path "~/.emacs.d/vendor/")
|
||||||
(require 'textmate)
|
(require 'textmate)
|
||||||
|
(require 'peepopen)
|
||||||
(textmate-mode)
|
(textmate-mode)
|
||||||
|
|
||||||
|
;; open files in current frame
|
||||||
|
(setq ns-pop-up-frames nil)
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; minimap
|
;; minimap
|
||||||
|
|
|
||||||
2778
emacs.d/emacs-nav/ack
Executable file
2778
emacs.d/emacs-nav/ack
Executable file
File diff suppressed because it is too large
Load diff
84
emacs.d/emacs-nav/ack.el
Normal file
84
emacs.d/emacs-nav/ack.el
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
;;; ack.el --- Use ack where you might usually use grep.
|
||||||
|
|
||||||
|
;; Copyright (C) 2008 Philip Jackson
|
||||||
|
|
||||||
|
;; Author: Philip Jackson <phil@shellarchive.co.uk>
|
||||||
|
;; Version: 0.1
|
||||||
|
|
||||||
|
;; This file is not currently part of GNU Emacs.
|
||||||
|
|
||||||
|
;; 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, 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 ; see the file COPYING. If not, write to
|
||||||
|
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||||
|
;; Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
|
;;; Commentary:
|
||||||
|
|
||||||
|
;; ack.el provides a simple compilation mode for the perl grep-a-like
|
||||||
|
;; ack (http://petdance.com/ack/).
|
||||||
|
|
||||||
|
;; If `ack-guess-type' is non-nil and `ack-mode-type-map' has a
|
||||||
|
;; reasonable value then ack.el will try and guess what you would like
|
||||||
|
;; in the --type argument for ack.
|
||||||
|
|
||||||
|
;; To install/use put ack.el in your load-path and (require 'ack) in
|
||||||
|
;; your initialisation file. You can then M-x ack and you're off.
|
||||||
|
|
||||||
|
(require 'compile)
|
||||||
|
|
||||||
|
(defvar ack-guess-type t
|
||||||
|
"Setting this value to `t' will have `ack' do its best to fill
|
||||||
|
in the --type argument to the ack command")
|
||||||
|
|
||||||
|
(defvar ack-mode-type-map
|
||||||
|
'(((c++-mode) . "cpp")
|
||||||
|
((c-mode) . "cc")
|
||||||
|
((css-mode) . "css")
|
||||||
|
((emacs-lisp-mode) . "elisp")
|
||||||
|
((fortran-mode) . "fortran")
|
||||||
|
((html-mode) . "html")
|
||||||
|
((xml-mode nxml-mode) . "xml")
|
||||||
|
((java-mode) . "java")
|
||||||
|
((lisp-mode) . "lisp")
|
||||||
|
((perl-mode cperl-mode yaml-mode) . "perl"))
|
||||||
|
"alist describing how to fill in the '--type=' argument to ack")
|
||||||
|
|
||||||
|
(defvar ack-command "ack --nocolor --nogroup "
|
||||||
|
"The command to be run by the ack function.")
|
||||||
|
|
||||||
|
(defun ack-find-type-for-mode ()
|
||||||
|
(catch 'found
|
||||||
|
(dolist (mode-type ack-mode-type-map)
|
||||||
|
(when (member major-mode (car mode-type))
|
||||||
|
(throw 'found (cdr mode-type))))))
|
||||||
|
|
||||||
|
(defun ack-build-command ()
|
||||||
|
(let ((type (ack-find-type-for-mode)))
|
||||||
|
(concat ack-command
|
||||||
|
(when (and ack-guess-type type)
|
||||||
|
(concat "--type=" type)) " ")))
|
||||||
|
|
||||||
|
(define-compilation-mode ack-mode "Ack"
|
||||||
|
"Ack compilation mode."
|
||||||
|
nil)
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun ack (command-args)
|
||||||
|
(interactive
|
||||||
|
(list (read-shell-command "Run ack (like this): "
|
||||||
|
(ack-build-command)
|
||||||
|
'ack-history
|
||||||
|
nil)))
|
||||||
|
(compilation-start command-args 'ack-mode))
|
||||||
|
|
||||||
|
(provide 'ack)
|
||||||
BIN
emacs.d/emacs-nav/ack.elc
Normal file
BIN
emacs.d/emacs-nav/ack.elc
Normal file
Binary file not shown.
651
emacs.d/emacs-nav/nav.el
Normal file
651
emacs.d/emacs-nav/nav.el
Normal file
|
|
@ -0,0 +1,651 @@
|
||||||
|
;;; nav.el --- Emacs mode for filesystem navigation
|
||||||
|
;;
|
||||||
|
;; Copyright 2010 Google Inc. All Rights Reserved.
|
||||||
|
;;
|
||||||
|
;; Author: issactrotts@google.com (Issac Trotts)
|
||||||
|
;; Version: 20110220
|
||||||
|
;;
|
||||||
|
|
||||||
|
;;; License:
|
||||||
|
;;
|
||||||
|
;; Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
;; you may not use this file except in compliance with the License.
|
||||||
|
;; You may obtain a copy of the License at
|
||||||
|
;;
|
||||||
|
;; http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
;;
|
||||||
|
;; Unless required by applicable law or agreed to in writing, software
|
||||||
|
;; distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
;; See the License for the specific language governing permissions and
|
||||||
|
;; limitations under the License.
|
||||||
|
|
||||||
|
;;; Commentary:
|
||||||
|
;;
|
||||||
|
;; To use this file, put something like the following in your
|
||||||
|
;; ~/.emacs:
|
||||||
|
;;
|
||||||
|
;; (add-to-list 'load-path "/directory/containing/nav/")
|
||||||
|
;; (require 'nav)
|
||||||
|
;;
|
||||||
|
;; Type M-x nav to start navigating.
|
||||||
|
;;
|
||||||
|
;; To set options for Nav, type M-x customize, then select
|
||||||
|
;; Applications, Nav.
|
||||||
|
|
||||||
|
;;; Key Bindings
|
||||||
|
;;
|
||||||
|
;; Press ? in the Nav window to display a list of key bindings.
|
||||||
|
;;
|
||||||
|
|
||||||
|
;;; History:
|
||||||
|
;;
|
||||||
|
;; See http://code.google.com/p/emacs-nav/source/list
|
||||||
|
;;
|
||||||
|
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
|
(condition-case err
|
||||||
|
(require 'ack)
|
||||||
|
(error
|
||||||
|
(message "Could not load ack.")))
|
||||||
|
|
||||||
|
(defgroup nav nil
|
||||||
|
"A lightweight filesystem navigator."
|
||||||
|
:group 'applications)
|
||||||
|
|
||||||
|
(defcustom nav-filtered-p t
|
||||||
|
"*If true, Nav will filter out files and directories such as
|
||||||
|
hidden files, backups and .elc files. The result depends on
|
||||||
|
`nav-boring-file-regexps'.
|
||||||
|
"
|
||||||
|
:type 'boolean
|
||||||
|
:group 'nav)
|
||||||
|
|
||||||
|
(defcustom nav-width 25
|
||||||
|
"*If non-nil, Nav will change its width to this when it opens files in
|
||||||
|
other windows.
|
||||||
|
"
|
||||||
|
:type 'integer
|
||||||
|
:group 'nav)
|
||||||
|
|
||||||
|
(defcustom nav-boring-file-regexps
|
||||||
|
(list "^[.][^.].*$" ; hidden files such as .foo
|
||||||
|
"^[.]$" ; current directory
|
||||||
|
"~$"
|
||||||
|
"[.]elc$"
|
||||||
|
"[.]pyc$"
|
||||||
|
"[.]o$"
|
||||||
|
"[.]bak$"
|
||||||
|
;; Stolen from Ack:
|
||||||
|
"^_MTN$" ; Monotone
|
||||||
|
"^blib$" ; Perl module building
|
||||||
|
"^CVS$" ; CVS
|
||||||
|
"^RCS$" ; RCS
|
||||||
|
"^SCCS$" ; SCCS
|
||||||
|
"^_darcs$" ; darcs
|
||||||
|
"^_sgbak$" ; Vault/Fortress
|
||||||
|
"^autom4te.cache$" ; autoconf
|
||||||
|
"^cover_db$" ; Devel::Cover
|
||||||
|
"^_build$" ; Module::Build
|
||||||
|
)
|
||||||
|
"*Nav ignores filenames that match any regular expression in this list."
|
||||||
|
:type '(repeat string)
|
||||||
|
:group 'nav)
|
||||||
|
|
||||||
|
|
||||||
|
;;
|
||||||
|
;; Fontification
|
||||||
|
;;
|
||||||
|
(require 'dired)
|
||||||
|
|
||||||
|
(defvar nav-directory-face 'dired-directory
|
||||||
|
"Face name used for directories.")
|
||||||
|
|
||||||
|
(defvar nav-font-lock-keywords
|
||||||
|
'(("^.*/$" . nav-directory-face))
|
||||||
|
"Regexes and associated faces used by Nav to fontify files and
|
||||||
|
directories."
|
||||||
|
)
|
||||||
|
|
||||||
|
(defun nav-make-mode-map ()
|
||||||
|
"Creates and returns a mode map with nav's key bindings."
|
||||||
|
(let ((keymap (make-sparse-keymap)))
|
||||||
|
(define-key keymap "a" 'ack)
|
||||||
|
(define-key keymap "c" 'nav-copy-file-or-dir)
|
||||||
|
(define-key keymap "C" 'nav-customize)
|
||||||
|
(define-key keymap "d" 'nav-delete-file-or-dir-on-this-line)
|
||||||
|
(define-key keymap "e" 'nav-invoke-dired)
|
||||||
|
(define-key keymap "f" 'nav-find-files)
|
||||||
|
(define-key keymap "g" 'grep-find)
|
||||||
|
(define-key keymap "h" 'nav-jump-to-home)
|
||||||
|
(define-key keymap "j" 'nav-jump-to-dir)
|
||||||
|
(define-key keymap "m" 'nav-move-file-or-dir)
|
||||||
|
(define-key keymap "n" 'nav-make-new-directory)
|
||||||
|
(define-key keymap "o" 'nav-open-file-under-cursor)
|
||||||
|
(define-key keymap "p" 'nav-pop-dir)
|
||||||
|
(define-key keymap "P" 'nav-print-current-dir)
|
||||||
|
(define-key keymap "q" 'delete-window)
|
||||||
|
(define-key keymap "r" 'nav-refresh)
|
||||||
|
(define-key keymap "s" 'nav-shell)
|
||||||
|
(define-key keymap "u" 'nav-go-up-one-dir)
|
||||||
|
(define-key keymap "w" 'nav-shrink-wrap)
|
||||||
|
(define-key keymap "W" 'nav-save-window-width)
|
||||||
|
(define-key keymap "!" 'nav-shell-command)
|
||||||
|
(define-key keymap "." 'nav-toggle-hidden-files)
|
||||||
|
(define-key keymap "?" 'nav-help-screen)
|
||||||
|
(define-key keymap "-" 'nav-shrink-a-bit)
|
||||||
|
(define-key keymap "_" 'nav-shrink-a-bit)
|
||||||
|
(define-key keymap "+" 'nav-expand-a-bit)
|
||||||
|
(define-key keymap "=" 'nav-expand-a-bit)
|
||||||
|
(define-key keymap " " 'nav-jump-to-name)
|
||||||
|
(define-key keymap [(control ?x) (control ?f)] 'find-file-other-window)
|
||||||
|
keymap))
|
||||||
|
|
||||||
|
(defun nav-shrink-window-horizontally (delta)
|
||||||
|
"First, compute a new value for the delta to make sure we don't
|
||||||
|
make the window too small, according to the following equation:
|
||||||
|
|
||||||
|
window-width - delta' = max(window-min-width, window-width - delta)
|
||||||
|
"
|
||||||
|
(let ((delta (- (window-width)
|
||||||
|
(max window-min-width
|
||||||
|
(- (window-width) delta)))))
|
||||||
|
(shrink-window-horizontally delta)
|
||||||
|
(nav-remember-current-width-during-this-session)))
|
||||||
|
|
||||||
|
(defun nav-enlarge-window-horizontally (delta)
|
||||||
|
(enlarge-window-horizontally delta)
|
||||||
|
(nav-remember-current-width-during-this-session))
|
||||||
|
|
||||||
|
(defun nav-remember-current-width-during-this-session ()
|
||||||
|
(customize-set-variable 'nav-width (window-width)))
|
||||||
|
|
||||||
|
(defun nav-shrink-a-bit ()
|
||||||
|
"Decreases the width of the nav window by one character."
|
||||||
|
(interactive)
|
||||||
|
(nav-shrink-window-horizontally 1))
|
||||||
|
|
||||||
|
(defun nav-expand-a-bit ()
|
||||||
|
"Increases the width of the nav window by one character."
|
||||||
|
(interactive)
|
||||||
|
(nav-enlarge-window-horizontally 1))
|
||||||
|
|
||||||
|
(defun nav-quit-help ()
|
||||||
|
"Exits the nav help screen."
|
||||||
|
(interactive)
|
||||||
|
(kill-buffer (current-buffer)))
|
||||||
|
|
||||||
|
(defun nav-help-screen ()
|
||||||
|
"Displays the help screen."
|
||||||
|
(interactive)
|
||||||
|
(switch-to-buffer-other-window "*nav-help*")
|
||||||
|
(insert "\
|
||||||
|
Nav Key Bindings
|
||||||
|
================
|
||||||
|
|
||||||
|
Enter/Return: Go to directory under cursor, or open file under
|
||||||
|
cursor in other window.
|
||||||
|
|
||||||
|
Tab: Move forward through filenames.
|
||||||
|
Shift-Tab: Move backward through filenames.
|
||||||
|
|
||||||
|
Space: Press spacebar, then any other letter to jump to filename
|
||||||
|
that starts with that letter.
|
||||||
|
|
||||||
|
a\t Recursively grep for a Perl regex using Ack (http://betterthangrep.com/).
|
||||||
|
c\t Copy file or directory under cursor.
|
||||||
|
C\t Customize Nav settings and bookmarks.
|
||||||
|
d\t Delete file or directory under cursor (asks to confirm first).
|
||||||
|
e\t Edit current directory in dired.
|
||||||
|
f\t Recursively find files whose titles match a Perl regex (using Ack).
|
||||||
|
g\t Grep recursively from current directory using grep-find
|
||||||
|
h\t Jump to home (~).
|
||||||
|
j\t Jump to another directory.
|
||||||
|
m\t Move or rename file or directory.
|
||||||
|
n\t Make a new directory.
|
||||||
|
o\t Open file under cursor in the nav window.
|
||||||
|
p\t Pop directory stack to go back to the previous directory.
|
||||||
|
P\t Print full path of current displayed directory.
|
||||||
|
q\t Quit nav.
|
||||||
|
r\t Refresh.
|
||||||
|
s\t Start a shell in an emacs window in the current directory.
|
||||||
|
u\t Go up to parent directory.
|
||||||
|
w\t Shrink-wrap Nav's window to fit the longest filename in the current directory.
|
||||||
|
\t Hit C-x + to roughly undo this by balancing windows.
|
||||||
|
!\t Run shell command.
|
||||||
|
.\t Toggle display of hidden files.
|
||||||
|
?\t Show this help screen.
|
||||||
|
-\t Narrow Nav window by one character.
|
||||||
|
+\t Widen Nav window by one character.
|
||||||
|
")
|
||||||
|
(nav-goto-line 1)
|
||||||
|
(view-mode -1)
|
||||||
|
(toggle-read-only 1))
|
||||||
|
|
||||||
|
(defvar nav-mode-map
|
||||||
|
(nav-make-mode-map)
|
||||||
|
"Mode map for nav mode")
|
||||||
|
|
||||||
|
(defvar nav-dir-stack '())
|
||||||
|
|
||||||
|
(defvar nav-map-dir-to-line-number (make-hash-table :test 'equal)
|
||||||
|
"Hash table from dir paths to most recent cursor pos in them.")
|
||||||
|
|
||||||
|
(defvar nav-button-face nil)
|
||||||
|
|
||||||
|
(defconst nav-default-line-num 2
|
||||||
|
"Line where cursor starts in directories that have not yet been
|
||||||
|
visited. A value of 1 would start the cursor off on ../.")
|
||||||
|
|
||||||
|
(defconst nav-shell-buffer-name "*nav-shell*"
|
||||||
|
"Name of the buffer used for the command line shell spawned by
|
||||||
|
nav on the 's' key.")
|
||||||
|
|
||||||
|
(defconst nav-buffer-name "*nav*"
|
||||||
|
"Name of the buffer where nav shows directory contents.")
|
||||||
|
|
||||||
|
(defconst nav-buffer-name-for-find-results "*nav-find*"
|
||||||
|
"Name of the buffer where nav shows find results.")
|
||||||
|
|
||||||
|
(defun nav-join (sep string-list)
|
||||||
|
(mapconcat 'identity string-list sep))
|
||||||
|
|
||||||
|
(defun nav-toggle-hidden-files ()
|
||||||
|
(interactive)
|
||||||
|
(setq nav-filtered-p (not nav-filtered-p))
|
||||||
|
(nav-refresh))
|
||||||
|
|
||||||
|
(defun nav-filename-matches-some-regexp (filename regexps)
|
||||||
|
(let ((matches-p nil))
|
||||||
|
(dolist (rx regexps)
|
||||||
|
(if (string-match rx filename)
|
||||||
|
(setq matches-p t)))
|
||||||
|
matches-p))
|
||||||
|
|
||||||
|
;; http://www.emacswiki.org/emacs/ElispCookbook#toc41
|
||||||
|
(defun nav-filter (condp lst)
|
||||||
|
(delq nil
|
||||||
|
(mapcar (lambda (x) (and (funcall condp x) x)) lst)))
|
||||||
|
|
||||||
|
(defun nav-filter-out-boring-filenames (filenames boring-regexps)
|
||||||
|
(nav-filter
|
||||||
|
(lambda (filename)
|
||||||
|
(not (nav-filename-matches-some-regexp filename boring-regexps)))
|
||||||
|
filenames))
|
||||||
|
|
||||||
|
(defun nav-get-line-for-cur-dir ()
|
||||||
|
(gethash (nav-get-working-dir) nav-map-dir-to-line-number))
|
||||||
|
|
||||||
|
(defun nav-cd (dirname)
|
||||||
|
"Changes to a different directory and pushes it onto the stack."
|
||||||
|
(let ((dirname (file-name-as-directory (file-truename dirname))))
|
||||||
|
(nav-save-cursor-line)
|
||||||
|
(setq default-directory dirname)
|
||||||
|
(nav-show-dir dirname)
|
||||||
|
(nav-restore-cursor-line)))
|
||||||
|
|
||||||
|
(defun nav-save-cursor-line ()
|
||||||
|
"Updates line number hash table."
|
||||||
|
(let ((line-num (nav-line-number-at-pos (point))))
|
||||||
|
(puthash (nav-get-working-dir) line-num nav-map-dir-to-line-number)))
|
||||||
|
|
||||||
|
(defun nav-goto-line (line)
|
||||||
|
"Jumps point to the given line."
|
||||||
|
(goto-char (point-min)) (forward-line (1- line)))
|
||||||
|
|
||||||
|
(defun nav-restore-cursor-line ()
|
||||||
|
"Remembers what line we were on last time we visited this directory."
|
||||||
|
(let ((line-num (or (nav-get-line-for-cur-dir)
|
||||||
|
nav-default-line-num)))
|
||||||
|
(nav-goto-line line-num)))
|
||||||
|
|
||||||
|
(defun nav-open-file (filename)
|
||||||
|
"Opens a file or directory from Nav."
|
||||||
|
(interactive "FFilename:")
|
||||||
|
(if (file-directory-p filename)
|
||||||
|
(nav-push-dir filename)
|
||||||
|
(find-file filename)))
|
||||||
|
|
||||||
|
(defun nav-open-file-other-window (filename)
|
||||||
|
"Opens a file or directory from Nav."
|
||||||
|
(interactive "FFilename:")
|
||||||
|
(if (file-directory-p filename)
|
||||||
|
(nav-push-dir filename)
|
||||||
|
(find-file-other-window filename)))
|
||||||
|
|
||||||
|
(defun nav-open-file-under-cursor ()
|
||||||
|
"Finds the file under the cursor."
|
||||||
|
(interactive)
|
||||||
|
(let ((filename (nav-get-cur-line-str)))
|
||||||
|
(nav-open-file filename)))
|
||||||
|
|
||||||
|
(defun nav-get-current-window ()
|
||||||
|
"Returns the currently selected window."
|
||||||
|
(get-buffer-window (current-buffer)))
|
||||||
|
|
||||||
|
(defun nav-get-current-window-width ()
|
||||||
|
"Returns the width of the currently selected window."
|
||||||
|
(window-width (nav-get-current-window)))
|
||||||
|
|
||||||
|
(defun nav-go-up-one-dir ()
|
||||||
|
"Points Nav to ../."
|
||||||
|
(interactive)
|
||||||
|
(nav-push-dir ".."))
|
||||||
|
|
||||||
|
(defun nav-get-shrink-wrap-width ()
|
||||||
|
(let* ((lines (split-string (buffer-string) "\n" t))
|
||||||
|
(num-lines (length lines))
|
||||||
|
(line-lengths (mapcar 'length lines))
|
||||||
|
(desired-width (+ 1 (apply 'max line-lengths)))
|
||||||
|
(max-width (/ (frame-width) 2))
|
||||||
|
(new-width (min desired-width max-width)))
|
||||||
|
new-width))
|
||||||
|
|
||||||
|
(defun nav-shrink-wrap ()
|
||||||
|
"Updates the width of the Nav window to fit the longest filename in the
|
||||||
|
current directory. Updates the global variable nav-width as a side effect."
|
||||||
|
(interactive)
|
||||||
|
(nav-set-window-width (nav-get-shrink-wrap-width)))
|
||||||
|
|
||||||
|
(defun nav-push-dir (dirname)
|
||||||
|
(let ((dirname (file-truename dirname)))
|
||||||
|
(when (not (string= dirname default-directory))
|
||||||
|
(push (file-truename default-directory) nav-dir-stack)
|
||||||
|
(nav-cd dirname))))
|
||||||
|
|
||||||
|
(defun nav-pop-dir ()
|
||||||
|
"Goes to the previous directory in Nav's history.
|
||||||
|
This works like a web browser's back button."
|
||||||
|
(interactive)
|
||||||
|
(let ((dir nil))
|
||||||
|
(while (and nav-dir-stack
|
||||||
|
(or (not dir)
|
||||||
|
(equal dir (file-name-as-directory (file-truename ".")))
|
||||||
|
(not (file-exists-p dir))))
|
||||||
|
(setq dir (pop nav-dir-stack)))
|
||||||
|
(setq dir (or dir "."))
|
||||||
|
(nav-cd dir)))
|
||||||
|
|
||||||
|
(defun nav-get-cur-line-str ()
|
||||||
|
(buffer-substring-no-properties (point-at-bol)
|
||||||
|
(point-at-eol)))
|
||||||
|
|
||||||
|
(defun nav-non-boring-directory-files (dir)
|
||||||
|
(nav-filter-out-boring-filenames (directory-files dir)
|
||||||
|
(if nav-filtered-p
|
||||||
|
nav-boring-file-regexps
|
||||||
|
'()
|
||||||
|
)))
|
||||||
|
|
||||||
|
(defun nav-dir-suffix (dir)
|
||||||
|
(replace-regexp-in-string ".*/" "" (directory-file-name dir)))
|
||||||
|
|
||||||
|
(defun nav-line-number-at-pos (p)
|
||||||
|
(let ((line-num 1))
|
||||||
|
(dotimes (i p line-num)
|
||||||
|
(if (eq ?\n (char-after i))
|
||||||
|
(setq line-num (+ line-num 1))))))
|
||||||
|
|
||||||
|
(defun nav-replace-buffer-contents (new-contents)
|
||||||
|
(let ((saved-line-number (nav-line-number-at-pos (point)))
|
||||||
|
;; Setting inhibit-read-only to t here lets us edit the buffer
|
||||||
|
;; in this let-block.
|
||||||
|
(inhibit-read-only t))
|
||||||
|
(erase-buffer)
|
||||||
|
(insert new-contents)
|
||||||
|
(nav-make-filenames-clickable)
|
||||||
|
(nav-goto-line saved-line-number)))
|
||||||
|
|
||||||
|
(defun nav-select-window (window)
|
||||||
|
(if window
|
||||||
|
(select-window window)
|
||||||
|
(message "Attempted to select nil window")))
|
||||||
|
|
||||||
|
(defun nav-button-action-to-open-file (button)
|
||||||
|
"Opens a file or directory in response to a button."
|
||||||
|
(let* ((buffer (overlay-buffer button))
|
||||||
|
(window-with-nav (get-buffer-window buffer)))
|
||||||
|
(nav-select-window window-with-nav)
|
||||||
|
(if (= 1 (count-windows))
|
||||||
|
(split-window-horizontally))
|
||||||
|
(nav-open-file-other-window (button-label button))
|
||||||
|
|
||||||
|
(if nav-width
|
||||||
|
(let ((other-window (nav-get-current-window)))
|
||||||
|
(select-window window-with-nav)
|
||||||
|
(nav-set-window-width nav-width)
|
||||||
|
(select-window other-window)))))
|
||||||
|
|
||||||
|
(defun nav-button-action-to-open-dir (button)
|
||||||
|
(let ((buffer (overlay-buffer button)))
|
||||||
|
(pop-to-buffer buffer)
|
||||||
|
(nav-push-dir (button-label button))))
|
||||||
|
|
||||||
|
(defun nav-make-filenames-clickable ()
|
||||||
|
(condition-case err
|
||||||
|
(save-excursion
|
||||||
|
(nav-goto-line 1)
|
||||||
|
(dotimes (i (count-lines 1 (point-max)))
|
||||||
|
(let* ((start (line-beginning-position))
|
||||||
|
(end (line-end-position))
|
||||||
|
(filename (buffer-substring-no-properties start end))
|
||||||
|
(action (if (file-directory-p filename)
|
||||||
|
'nav-button-action-to-open-dir
|
||||||
|
'nav-button-action-to-open-file)))
|
||||||
|
(make-button start end
|
||||||
|
'action action
|
||||||
|
'follow-link t
|
||||||
|
'face nav-button-face
|
||||||
|
'help-echo nil))
|
||||||
|
(forward-line 1)))
|
||||||
|
(error
|
||||||
|
;; This can happen for versions of emacs that don't have
|
||||||
|
;; make-button defined.
|
||||||
|
'failed)))
|
||||||
|
|
||||||
|
(defun nav-string< (s1 s2)
|
||||||
|
"Tells whether S1 comes lexically before S2, ignoring case."
|
||||||
|
(string< (downcase s1) (downcase s2)))
|
||||||
|
|
||||||
|
(defun nav-show-dir (dir)
|
||||||
|
(let ((new-contents '()))
|
||||||
|
(dolist (filename (nav-non-boring-directory-files dir))
|
||||||
|
(let ((line (concat filename
|
||||||
|
(if (file-directory-p filename)
|
||||||
|
"/"
|
||||||
|
"")
|
||||||
|
)))
|
||||||
|
(push line new-contents)))
|
||||||
|
(let* ((new-contents (sort new-contents 'nav-string<))
|
||||||
|
(new-contents (nav-join "\n" new-contents)))
|
||||||
|
(nav-replace-buffer-contents new-contents))
|
||||||
|
(setq mode-line-format (nav-make-mode-line "d" dir))
|
||||||
|
(force-mode-line-update)))
|
||||||
|
|
||||||
|
(defun nav-set-window-width (n)
|
||||||
|
(let ((n (max n window-min-width)))
|
||||||
|
(if (> (window-width) n)
|
||||||
|
(nav-shrink-window-horizontally (- (window-width) n)))
|
||||||
|
(if (< (window-width) n)
|
||||||
|
(nav-enlarge-window-horizontally (- n (window-width))))))
|
||||||
|
|
||||||
|
(defun nav-save-window-width ()
|
||||||
|
"Saves the width of the current window as the default width for Nav."
|
||||||
|
(interactive)
|
||||||
|
(let ((width (window-width (nav-get-current-window))))
|
||||||
|
(customize-save-variable 'nav-width width)))
|
||||||
|
|
||||||
|
(defun nav-get-working-dir ()
|
||||||
|
(file-name-as-directory (file-truename default-directory)))
|
||||||
|
|
||||||
|
(defun nav-invoke-dired ()
|
||||||
|
"Invokes dired on the current directory."
|
||||||
|
(interactive)
|
||||||
|
(dired (nav-get-working-dir)))
|
||||||
|
|
||||||
|
(defun nav-find-files (pattern)
|
||||||
|
"Recursively finds files whose names match a Perl regular expression."
|
||||||
|
(interactive "sPattern: ")
|
||||||
|
(let* ((pattern (format "%s[^/]*$" pattern))
|
||||||
|
(find-command (format "ack -a -l '.' | ack %s" pattern))
|
||||||
|
(inhibit-read-only t))
|
||||||
|
(erase-buffer)
|
||||||
|
(call-process-shell-command find-command nil (current-buffer))
|
||||||
|
(nav-make-filenames-clickable)
|
||||||
|
(message "Hit r to bring back Nav directory listing.")
|
||||||
|
(cond ((string= "" (buffer-string))
|
||||||
|
(insert "No matching files found."))
|
||||||
|
(t
|
||||||
|
;; Enable nav keyboard shortcuts, mainly so hitting enter will open
|
||||||
|
;; files.
|
||||||
|
(use-local-map nav-mode-map))
|
||||||
|
)
|
||||||
|
(forward-line -1)
|
||||||
|
))
|
||||||
|
|
||||||
|
(defun nav-refresh ()
|
||||||
|
"Resizes Nav window to original size, updates its contents."
|
||||||
|
(interactive)
|
||||||
|
(nav-show-dir ".")
|
||||||
|
(nav-restore-cursor-line))
|
||||||
|
|
||||||
|
(defun nav-jump-to-home ()
|
||||||
|
"Show home directory in Nav."
|
||||||
|
(interactive)
|
||||||
|
(nav-push-dir "~"))
|
||||||
|
|
||||||
|
(defun nav-jump-to-name (arg)
|
||||||
|
(interactive "K")
|
||||||
|
(nav-goto-line 2)
|
||||||
|
(let ((nav-search-string (concat "^" arg)))
|
||||||
|
(search-forward-regexp nav-search-string)))
|
||||||
|
|
||||||
|
(defun nav-jump-to-dir (dirname)
|
||||||
|
"Shows a specified directory in Nav."
|
||||||
|
(interactive "fDirectory: ")
|
||||||
|
(nav-push-dir dirname))
|
||||||
|
|
||||||
|
(defun nav-make-mode-line (mode dir)
|
||||||
|
(concat "-(nav)"
|
||||||
|
(nav-dir-suffix (file-truename dir))
|
||||||
|
"/"
|
||||||
|
" "
|
||||||
|
(format "[%s]"
|
||||||
|
(if nav-filtered-p
|
||||||
|
"filtered"
|
||||||
|
"unfiltered"))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
(defun nav-delete-file-or-dir (filename)
|
||||||
|
(nav-save-cursor-line)
|
||||||
|
(if (and (file-directory-p filename)
|
||||||
|
(not (file-symlink-p (directory-file-name filename))))
|
||||||
|
(when (yes-or-no-p (format "Really delete directory %s ?" filename))
|
||||||
|
(delete-directory filename t)
|
||||||
|
(nav-refresh))
|
||||||
|
;; We first use directory-file-name to strip the trailing slash
|
||||||
|
;; if it's a symlink to a directory.
|
||||||
|
(let ((filename (directory-file-name filename)))
|
||||||
|
(when (y-or-n-p (format "Really delete file %s ? " filename))
|
||||||
|
(delete-file filename)
|
||||||
|
(nav-refresh))))
|
||||||
|
(nav-restore-cursor-line))
|
||||||
|
|
||||||
|
(defun nav-delete-file-or-dir-on-this-line ()
|
||||||
|
"Deletes a file or directory."
|
||||||
|
(interactive)
|
||||||
|
(nav-delete-file-or-dir (nav-get-cur-line-str)))
|
||||||
|
|
||||||
|
(defun nav-copy-file-or-dir (target-name)
|
||||||
|
"Copies a file or directory."
|
||||||
|
(interactive "FCopy to: ")
|
||||||
|
(let ((filename (nav-get-cur-line-str)))
|
||||||
|
(if (file-directory-p filename)
|
||||||
|
(copy-directory filename target-name)
|
||||||
|
(copy-file filename target-name)))
|
||||||
|
(nav-refresh))
|
||||||
|
|
||||||
|
(defun nav-customize ()
|
||||||
|
"Starts customization for Nav."
|
||||||
|
(interactive)
|
||||||
|
(customize-group "nav"))
|
||||||
|
|
||||||
|
(defun nav-move-file-or-dir (target-name)
|
||||||
|
"Moves a file or directory."
|
||||||
|
(interactive "FMove to: ")
|
||||||
|
(let ((filename (nav-get-cur-line-str)))
|
||||||
|
(rename-file filename target-name))
|
||||||
|
(nav-refresh))
|
||||||
|
|
||||||
|
(defun nav-append-slashes-to-dir-names (names)
|
||||||
|
(mapcar (lambda (name)
|
||||||
|
(if (file-directory-p name)
|
||||||
|
(concat name "/")
|
||||||
|
name))
|
||||||
|
names))
|
||||||
|
|
||||||
|
(defun nav-make-new-directory (name)
|
||||||
|
"Creates a new directory."
|
||||||
|
(interactive "sMake directory: ")
|
||||||
|
(make-directory name)
|
||||||
|
(nav-refresh))
|
||||||
|
|
||||||
|
(defun nav-shell ()
|
||||||
|
"Starts up a shell on the current nav directory.
|
||||||
|
|
||||||
|
Thanks to claudio.bley for this new, improved version.
|
||||||
|
http://code.google.com/p/emacs-nav/issues/detail?id=78
|
||||||
|
"
|
||||||
|
(interactive)
|
||||||
|
(let ((default-directory (nav-get-working-dir)))
|
||||||
|
(shell nav-shell-buffer-name)))
|
||||||
|
|
||||||
|
(defun nav-shell-command (command)
|
||||||
|
"Runs a shell command and then refreshes the Nav window."
|
||||||
|
(interactive "sShell command: ")
|
||||||
|
(shell-command command)
|
||||||
|
(nav-refresh))
|
||||||
|
|
||||||
|
(defun nav-print-current-dir ()
|
||||||
|
"Shows the full path that nav is currently displaying"
|
||||||
|
(interactive)
|
||||||
|
(print default-directory))
|
||||||
|
|
||||||
|
(define-derived-mode nav-mode fundamental-mode
|
||||||
|
"Nav mode navigates filesystems."
|
||||||
|
(setq mode-name "Nav")
|
||||||
|
(use-local-map nav-mode-map)
|
||||||
|
(setq buffer-read-only t)
|
||||||
|
(setq truncate-lines t)
|
||||||
|
(setq font-lock-defaults '(nav-font-lock-keywords))
|
||||||
|
(nav-refresh))
|
||||||
|
|
||||||
|
(defun nav-disable-emacs23-window-splitting ()
|
||||||
|
"Turns off the new feature where Emacs 23 automatically splits windows when
|
||||||
|
opening files in a large frame."
|
||||||
|
(interactive)
|
||||||
|
(setq split-width-threshold most-positive-fixnum)
|
||||||
|
(setq split-height-threshold most-positive-fixnum))
|
||||||
|
|
||||||
|
(defun nav-in-place ()
|
||||||
|
"Starts Nav in the current window."
|
||||||
|
(interactive)
|
||||||
|
(switch-to-buffer (generate-new-buffer-name nav-buffer-name))
|
||||||
|
(nav-mode)
|
||||||
|
(nav-refresh))
|
||||||
|
|
||||||
|
;; The next line is for ELPA, the Emacs Lisp Package Archive.
|
||||||
|
;;;###autoload
|
||||||
|
(defun nav ()
|
||||||
|
"Opens Nav in a new window to the left of the current one."
|
||||||
|
(interactive)
|
||||||
|
(let ((default-directory (nav-get-working-dir)))
|
||||||
|
(split-window-horizontally)
|
||||||
|
(nav-in-place)
|
||||||
|
(nav-set-window-width nav-width)))
|
||||||
|
|
||||||
|
(provide 'nav)
|
||||||
|
|
||||||
|
;;; nav.el ends here
|
||||||
BIN
emacs.d/emacs-nav/nav.elc
Normal file
BIN
emacs.d/emacs-nav/nav.elc
Normal file
Binary file not shown.
96
emacs.d/vendor/peepopen.el
vendored
Normal file
96
emacs.d/vendor/peepopen.el
vendored
Normal file
|
|
@ -0,0 +1,96 @@
|
||||||
|
;; peepopen.el --- Graphical file chooser for Emacs on Mac OS X.
|
||||||
|
|
||||||
|
;; Copyright (C) 2010 Topfunky Corporation <http://peepcode.com>
|
||||||
|
|
||||||
|
;; Licensed under the same terms as Emacs.
|
||||||
|
|
||||||
|
;; Version: 0.1.0
|
||||||
|
;; Keywords: textmate osx mac
|
||||||
|
;; Created: 8 April 2010
|
||||||
|
;; Author: Geoffrey Grosenbach <boss@topfunky.com>
|
||||||
|
;;
|
||||||
|
;; Enhancements: Josh Peek http://joshpeek.com/
|
||||||
|
|
||||||
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
|
;; Licensed under the same terms as Emacs.
|
||||||
|
|
||||||
|
;;; Commentary:
|
||||||
|
|
||||||
|
;; A sensible fuzzy file chooser with a beautiful Mac OS X GUI.
|
||||||
|
;;
|
||||||
|
;; This minimal enhancement to textmate-mode calls the external
|
||||||
|
;; PeepOpen.app when you hit Command-T (or equivalent).
|
||||||
|
|
||||||
|
;; ⌘T - Go to File
|
||||||
|
|
||||||
|
;;; Installation:
|
||||||
|
|
||||||
|
;; This plugin assumes that you've already loaded Chris Wanstrath's
|
||||||
|
;; textmate.el in your emacs configuration. Load this file afterward.
|
||||||
|
;;
|
||||||
|
;; Copy this file to ~/.emacs.d/vendor/peepopen.el (or use the menu
|
||||||
|
;; item in the PeepOpen application).
|
||||||
|
;;
|
||||||
|
|
||||||
|
;; You'll also need textmate.el:
|
||||||
|
;;
|
||||||
|
;; $ cd ~/.emacs.d/vendor
|
||||||
|
;; $ git clone git://github.com/defunkt/textmate.el.git
|
||||||
|
|
||||||
|
;; Finally, require both libraries and activate textmate-mode.
|
||||||
|
;; In most Emacs distributions, you'll do this in ~/.emacs.d/init.el
|
||||||
|
;; or your personal configuration file.
|
||||||
|
;;
|
||||||
|
;; In Aquamacs, this goes in ~/Library/Preferences/Aquamacs Emacs/Preferences.el.
|
||||||
|
|
||||||
|
;; (add-to-list 'load-path "~/.emacs.d/vendor/textmate.el")
|
||||||
|
;; (require 'textmate)
|
||||||
|
;; (add-to-list 'load-path "~/.emacs.d/vendor/")
|
||||||
|
;; (require 'peepopen)
|
||||||
|
;; (textmate-mode)
|
||||||
|
|
||||||
|
;; For Emacs 23 or Aquamacs, use this to open files in the existing frame:
|
||||||
|
;;
|
||||||
|
;; (setq ns-pop-up-frames nil)
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun peepopen-goto-file-gui ()
|
||||||
|
"Uses external GUI app to quickly jump to a file in the project."
|
||||||
|
(interactive)
|
||||||
|
(defun string-join (separator strings)
|
||||||
|
"Join all STRINGS using SEPARATOR."
|
||||||
|
(mapconcat 'identity strings separator))
|
||||||
|
(let ((root (textmate-project-root)))
|
||||||
|
(when (null root)
|
||||||
|
(error
|
||||||
|
(concat
|
||||||
|
"Can't find a suitable project root ("
|
||||||
|
(string-join " " *textmate-project-roots* )
|
||||||
|
")")))
|
||||||
|
(shell-command-to-string
|
||||||
|
(format "open 'peepopen://%s?editor=%s'"
|
||||||
|
(expand-file-name root)
|
||||||
|
(invocation-name)))))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(defun peepopen-bind-keys ()
|
||||||
|
(cond ((featurep 'aquamacs) (peepopen-bind-aquamacs-keys))
|
||||||
|
((featurep 'mac-carbon) (peepopen-bind-carbon-keys))
|
||||||
|
((featurep 'ns) (peepopen-bind-ns-keys))))
|
||||||
|
|
||||||
|
(defun peepopen-bind-aquamacs-keys ()
|
||||||
|
;; Need `osx-key-mode-map' to override
|
||||||
|
(define-key osx-key-mode-map (kbd "A-t") 'peepopen-goto-file-gui)
|
||||||
|
(define-key *textmate-mode-map* (kbd "A-t") 'peepopen-goto-file-gui))
|
||||||
|
|
||||||
|
(defun peepopen-bind-carbon-keys ()
|
||||||
|
(define-key *textmate-mode-map* [(meta t)] 'peepopen-goto-file-gui))
|
||||||
|
|
||||||
|
(defun peepopen-bind-ns-keys ()
|
||||||
|
(define-key *textmate-mode-map* [(super t)] 'peepopen-goto-file-gui))
|
||||||
|
|
||||||
|
;;;###autoload
|
||||||
|
(add-hook 'textmate-mode-hook 'peepopen-bind-keys)
|
||||||
|
|
||||||
|
(provide 'peepopen)
|
||||||
141
emacs.d/textmate.el → emacs.d/vendor/textmate.el
vendored
141
emacs.d/textmate.el → emacs.d/vendor/textmate.el
vendored
|
|
@ -1,4 +1,4 @@
|
||||||
;; textmate.el --- TextMate minor mode for Emacs
|
;;; textmate.el --- TextMate minor mode for Emacs
|
||||||
|
|
||||||
;; Copyright (C) 2008, 2009 Chris Wanstrath <chris@ozmm.org>
|
;; Copyright (C) 2008, 2009 Chris Wanstrath <chris@ozmm.org>
|
||||||
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
;; Keywords: textmate osx mac
|
;; Keywords: textmate osx mac
|
||||||
;; Created: 22 Nov 2008
|
;; Created: 22 Nov 2008
|
||||||
;; Author: Chris Wanstrath <chris@ozmm.org>
|
;; Author: Chris Wanstrath <chris@ozmm.org>
|
||||||
;; Version: 1
|
;; Version: 2
|
||||||
|
|
||||||
;; This file is NOT part of GNU Emacs.
|
;; This file is NOT part of GNU Emacs.
|
||||||
|
|
||||||
|
|
@ -25,6 +25,8 @@
|
||||||
;; ⌘[ - Shift Left
|
;; ⌘[ - Shift Left
|
||||||
;; ⌥⌘] - Align Assignments
|
;; ⌥⌘] - Align Assignments
|
||||||
;; ⌥⌘[ - Indent Line
|
;; ⌥⌘[ - Indent Line
|
||||||
|
;; ⌥↑ - Column Up
|
||||||
|
;; ⌥↓ - Column Down
|
||||||
;; ⌘RET - Insert Newline at Line's End
|
;; ⌘RET - Insert Newline at Line's End
|
||||||
;; ⌥⌘T - Reset File Cache (for Go to File)
|
;; ⌥⌘T - Reset File Cache (for Go to File)
|
||||||
|
|
||||||
|
|
@ -65,11 +67,11 @@
|
||||||
;;; Minor mode
|
;;; Minor mode
|
||||||
|
|
||||||
(defvar *textmate-gf-exclude*
|
(defvar *textmate-gf-exclude*
|
||||||
"/(\\.|vendor|fixtures|tmp|log|[bB]uild|\\.xcodeproj|\\.nib|\\.framework|\\.app|\\.pbproj|\\.pbxproj|\\.xcode|\\.xcodeproj|\\.bundle|\\.pyc|Frameworks)"
|
"(/|^)(\\.+[^/]+|vendor|fixtures|tmp|log|classes|build)($|/)|(\\.xcodeproj|\\.nib|\\.framework|\\.app|\\.pbproj|\\.pbxproj|\\.xcode|\\.xcodeproj|\\.bundle|\\.pyc)(/|$)"
|
||||||
"Regexp of files to exclude from `textmate-goto-file'.")
|
"Regexp of files to exclude from `textmate-goto-file'.")
|
||||||
|
|
||||||
(defvar *textmate-project-roots*
|
(defvar *textmate-project-roots*
|
||||||
'(".git" ".hg" "Rakefile" "Makefile" "README" "build.xml")
|
'(".git" ".hg" "Rakefile" "Makefile" "README" "build.xml" ".emacs-project")
|
||||||
"The presence of any file/directory in this list indicates a project root.")
|
"The presence of any file/directory in this list indicates a project root.")
|
||||||
|
|
||||||
(defvar textmate-use-file-cache t
|
(defvar textmate-use-file-cache t
|
||||||
|
|
@ -79,9 +81,9 @@
|
||||||
"The library `textmade-goto-symbol' and `textmate-goto-file' should use for
|
"The library `textmade-goto-symbol' and `textmate-goto-file' should use for
|
||||||
completing filenames and symbols (`ido' by default)")
|
completing filenames and symbols (`ido' by default)")
|
||||||
|
|
||||||
(defvar textmate-find-files-command "find %s -type f"
|
(defvar textmate-find-files-command "find \"%s\" -type f"
|
||||||
"The command `textmate-project-root' uses to find files. %s will be replaced
|
"The command `textmate-project-files' uses to find files. %s will be replaced
|
||||||
the project root.")
|
by the project root.")
|
||||||
|
|
||||||
(defvar *textmate-completing-function-alist* '((ido ido-completing-read)
|
(defvar *textmate-completing-function-alist* '((ido ido-completing-read)
|
||||||
(icicles icicle-completing-read)
|
(icicles icicle-completing-read)
|
||||||
|
|
@ -106,7 +108,11 @@ the project root.")
|
||||||
(define-key map (kbd "A-/") 'comment-or-uncomment-region-or-line)
|
(define-key map (kbd "A-/") 'comment-or-uncomment-region-or-line)
|
||||||
(define-key map (kbd "A-L") 'textmate-select-line)
|
(define-key map (kbd "A-L") 'textmate-select-line)
|
||||||
(define-key map (kbd "A-t") 'textmate-goto-file)
|
(define-key map (kbd "A-t") 'textmate-goto-file)
|
||||||
(define-key map (kbd "A-T") 'textmate-goto-symbol))
|
(define-key map (kbd "A-T") 'textmate-goto-symbol)
|
||||||
|
(define-key map (kbd "M-<up>") 'textmate-column-up)
|
||||||
|
(define-key map (kbd "M-<down>") 'textmate-column-down)
|
||||||
|
(define-key map (kbd "M-S-<up>") 'textmate-column-up-with-select)
|
||||||
|
(define-key map (kbd "M-S-<down>") 'textmate-column-down-with-select))
|
||||||
((and (featurep 'mac-carbon) (eq window-system 'mac) mac-key-mode)
|
((and (featurep 'mac-carbon) (eq window-system 'mac) mac-key-mode)
|
||||||
(define-key map [(alt meta return)] 'textmate-next-line)
|
(define-key map [(alt meta return)] 'textmate-next-line)
|
||||||
(define-key map [(alt meta t)] 'textmate-clear-cache)
|
(define-key map [(alt meta t)] 'textmate-clear-cache)
|
||||||
|
|
@ -117,7 +123,11 @@ the project root.")
|
||||||
(define-key map [(meta /)] 'comment-or-uncomment-region-or-line)
|
(define-key map [(meta /)] 'comment-or-uncomment-region-or-line)
|
||||||
(define-key map [(alt t)] 'textmate-goto-file)
|
(define-key map [(alt t)] 'textmate-goto-file)
|
||||||
(define-key map [(alt shift l)] 'textmate-select-line)
|
(define-key map [(alt shift l)] 'textmate-select-line)
|
||||||
(define-key map [(alt shift t)] 'textmate-goto-symbol))
|
(define-key map [(alt shift t)] 'textmate-goto-symbol)
|
||||||
|
(define-key map [(alt up)] 'textmate-column-up)
|
||||||
|
(define-key map [(alt down)] 'textmate-column-down)
|
||||||
|
(define-key map [(alt shift up)] 'textmate-column-up-with-select)
|
||||||
|
(define-key map [(alt shift down)] 'textmate-column-down-with-select))
|
||||||
((featurep 'ns) ;; Emacs.app
|
((featurep 'ns) ;; Emacs.app
|
||||||
(define-key map [(super meta return)] 'textmate-next-line)
|
(define-key map [(super meta return)] 'textmate-next-line)
|
||||||
(define-key map [(super meta t)] 'textmate-clear-cache)
|
(define-key map [(super meta t)] 'textmate-clear-cache)
|
||||||
|
|
@ -126,9 +136,13 @@ the project root.")
|
||||||
(define-key map [(super \])] 'textmate-shift-right)
|
(define-key map [(super \])] 'textmate-shift-right)
|
||||||
(define-key map [(super \[)] 'textmate-shift-left)
|
(define-key map [(super \[)] 'textmate-shift-left)
|
||||||
(define-key map [(super /)] 'comment-or-uncomment-region-or-line)
|
(define-key map [(super /)] 'comment-or-uncomment-region-or-line)
|
||||||
;; (define-key map [(super t)] 'textmate-goto-file)
|
(define-key map [(super t)] 'textmate-goto-file)
|
||||||
(define-key map [(super shift l)] 'textmate-select-line)
|
(define-key map [(super shift l)] 'textmate-select-line)
|
||||||
(define-key map [(super shift t)] 'textmate-goto-symbol))
|
(define-key map [(super shift t)] 'textmate-goto-symbol)
|
||||||
|
(define-key map [(meta up)] 'textmate-column-up)
|
||||||
|
(define-key map [(meta down)] 'textmate-column-down)
|
||||||
|
(define-key map [(meta shift up)] 'textmate-column-up-with-select)
|
||||||
|
(define-key map [(meta shift down)] 'textmate-column-down-with-select))
|
||||||
(t ;; Any other version
|
(t ;; Any other version
|
||||||
(define-key map [(meta return)] 'textmate-next-line)
|
(define-key map [(meta return)] 'textmate-next-line)
|
||||||
(define-key map [(control c)(control t)] 'textmate-clear-cache)
|
(define-key map [(control c)(control t)] 'textmate-clear-cache)
|
||||||
|
|
@ -138,7 +152,11 @@ the project root.")
|
||||||
(define-key map [(control c)(control k)] 'comment-or-uncomment-region-or-line)
|
(define-key map [(control c)(control k)] 'comment-or-uncomment-region-or-line)
|
||||||
(define-key map [(meta t)] 'textmate-goto-file)
|
(define-key map [(meta t)] 'textmate-goto-file)
|
||||||
(define-key map [(meta shift l)] 'textmate-select-line)
|
(define-key map [(meta shift l)] 'textmate-select-line)
|
||||||
(define-key map [(meta shift t)] 'textmate-goto-symbol)))
|
(define-key map [(meta shift t)] 'textmate-goto-symbol)
|
||||||
|
(define-key map [(alt up)] 'textmate-column-up)
|
||||||
|
(define-key map [(alt down)] 'textmate-column-down)
|
||||||
|
(define-key map [(alt shift up)] 'textmate-column-up-with-select)
|
||||||
|
(define-key map [(alt shift down)] 'textmate-column-down-with-select)))
|
||||||
map))
|
map))
|
||||||
|
|
||||||
(defvar *textmate-project-root* nil
|
(defvar *textmate-project-root* nil
|
||||||
|
|
@ -146,6 +164,7 @@ the project root.")
|
||||||
(defvar *textmate-project-files* '()
|
(defvar *textmate-project-files* '()
|
||||||
"Used internally to cache the files in a project.")
|
"Used internally to cache the files in a project.")
|
||||||
|
|
||||||
|
(defcustom textmate-word-characters "a-zA-Z0-9_" "Word Characters for Column Movement")
|
||||||
;;; Bindings
|
;;; Bindings
|
||||||
|
|
||||||
(defun textmate-ido-fix ()
|
(defun textmate-ido-fix ()
|
||||||
|
|
@ -268,31 +287,25 @@ Symbols matching the text at point are put first in the completion list."
|
||||||
(setq symbol-names (cons symbol
|
(setq symbol-names (cons symbol
|
||||||
(delete symbol symbol-names))))
|
(delete symbol symbol-names))))
|
||||||
matching-symbols)))))
|
matching-symbols)))))
|
||||||
(let* ((selected-symbol (ido-completing-read "Symbol? " symbol-names))
|
(let* ((selected-symbol (ido-completing-read "Symbol? " (reverse symbol-names)))
|
||||||
(position (cdr (assoc selected-symbol name-and-pos))))
|
(position (cdr (assoc selected-symbol name-and-pos))))
|
||||||
(goto-char (if (overlayp position) (overlay-start position) position)))))
|
(goto-char (if (overlayp position) (overlay-start position) position)))))
|
||||||
|
|
||||||
;; this is from rails-lib.el in the emacs-rails package
|
|
||||||
(defun string-join (separator strings)
|
|
||||||
"Join all STRINGS using SEPARATOR."
|
|
||||||
(mapconcat 'identity strings separator))
|
|
||||||
|
|
||||||
(defun textmate-goto-file ()
|
(defun textmate-goto-file ()
|
||||||
"Uses your completing read to quickly jump to a file in a project."
|
"Uses your completing read to quickly jump to a file in a project."
|
||||||
(interactive)
|
(interactive)
|
||||||
(let ((root (textmate-project-root)))
|
(let ((root (textmate-project-root)))
|
||||||
(when (null root)
|
(when (null root)
|
||||||
(error
|
(error "Can't find any .git directory"))
|
||||||
(concat
|
|
||||||
"Can't find a suitable project root ("
|
|
||||||
(string-join " " *textmate-project-roots* )
|
|
||||||
")")))
|
|
||||||
(find-file
|
(find-file
|
||||||
(concat
|
(concat
|
||||||
(expand-file-name root) "/"
|
(expand-file-name root) "/"
|
||||||
(textmate-completing-read
|
(textmate-completing-read
|
||||||
"Find file: "
|
"Find file: "
|
||||||
(textmate-cached-project-files root))))))
|
(mapcar
|
||||||
|
(lambda (e)
|
||||||
|
(replace-regexp-in-string (textmate-project-root) "" e))
|
||||||
|
(textmate-cached-project-files (textmate-project-root))))))))
|
||||||
|
|
||||||
(defun textmate-clear-cache ()
|
(defun textmate-clear-cache ()
|
||||||
"Clears the project root and project files cache. Use after adding files."
|
"Clears the project root and project files cache. Use after adding files."
|
||||||
|
|
@ -301,28 +314,9 @@ Symbols matching the text at point are put first in the completion list."
|
||||||
(setq *textmate-project-files* nil)
|
(setq *textmate-project-files* nil)
|
||||||
(message "textmate-mode cache cleared."))
|
(message "textmate-mode cache cleared."))
|
||||||
|
|
||||||
|
|
||||||
;; FIXME:
|
|
||||||
;; - use *textmate-gf-exclude* instead of hard-coding ignored paths
|
|
||||||
;; - format results nicely (like TextMate)
|
|
||||||
(defun textmate-find-regex-in-project (regex)
|
|
||||||
"Search the project for a regular expression and quickly jump
|
|
||||||
to matches in a project.
|
|
||||||
|
|
||||||
This function just finds the project root and calls `RGREP'."
|
|
||||||
(interactive "sRegex: ")
|
|
||||||
(let ((root (textmate-project-root)))
|
|
||||||
(when (null root)
|
|
||||||
(error
|
|
||||||
(concat
|
|
||||||
"Can't find a suitable project root ("
|
|
||||||
(string-join " " *textmate-project-roots*)
|
|
||||||
")")))
|
|
||||||
(grep (concat "grep -Hn -E '" regex "' " root "/**/{*.j,*.js,*akefile,*.sh}(N) | grep -vE '/([Bb]uild|Frameworks|.git)/?' | sed -e 's#" root "/##'"))))
|
|
||||||
|
|
||||||
;;; Utilities
|
;;; Utilities
|
||||||
|
|
||||||
(defun textmate-project-files (root)
|
(defun textmate-find-project-files (root)
|
||||||
"Finds all files in a given project."
|
"Finds all files in a given project."
|
||||||
(split-string
|
(split-string
|
||||||
(shell-command-to-string
|
(shell-command-to-string
|
||||||
|
|
@ -334,6 +328,11 @@ This function just finds the project root and calls `RGREP'."
|
||||||
*textmate-project-root*
|
*textmate-project-root*
|
||||||
"/::'")) "\n" t))
|
"/::'")) "\n" t))
|
||||||
|
|
||||||
|
(defun textmate-project-files (root)
|
||||||
|
(sort
|
||||||
|
(textmate-find-project-files root)
|
||||||
|
'(lambda (a b) (< (length a) (length b)))))
|
||||||
|
|
||||||
;; http://snipplr.com/view/18683/stringreplace/
|
;; http://snipplr.com/view/18683/stringreplace/
|
||||||
(defun textmate-string-replace (this withthat in)
|
(defun textmate-string-replace (this withthat in)
|
||||||
"replace THIS with WITHTHAT' in the string IN"
|
"replace THIS with WITHTHAT' in the string IN"
|
||||||
|
|
@ -400,6 +399,60 @@ A place is considered `tab-width' character columns."
|
||||||
(interactive)
|
(interactive)
|
||||||
(textmate-shift-right (* -1 (or arg 1))))
|
(textmate-shift-right (* -1 (or arg 1))))
|
||||||
|
|
||||||
|
(defun textmate-go-column (direction arg)
|
||||||
|
"Move down a column"
|
||||||
|
(let* ((orig-line (line-number-at-pos))
|
||||||
|
(orig-column (current-column))
|
||||||
|
(prefix-match-regex (if (<= orig-column 1) "^" (format "^.\\{%d\\}" (- orig-column 1))) )
|
||||||
|
(word-regex (concat "[" textmate-word-characters "]"))
|
||||||
|
(non-word-regex (concat "[^\n" textmate-word-characters "]"))
|
||||||
|
(matching-regex (concat prefix-match-regex
|
||||||
|
(cond ((looking-back "^") "")
|
||||||
|
((looking-back word-regex) word-regex)
|
||||||
|
(t non-word-regex))
|
||||||
|
(cond ((looking-at "$") "$")
|
||||||
|
((looking-at word-regex) word-regex)
|
||||||
|
(t non-word-regex))))
|
||||||
|
(do-search (if (= direction 1)
|
||||||
|
(lambda () (search-forward-regexp matching-regex nil t))
|
||||||
|
(lambda () (search-backward-regexp matching-regex nil t)))))
|
||||||
|
(forward-char direction)
|
||||||
|
(funcall do-search)
|
||||||
|
(backward-char direction)
|
||||||
|
(move-to-column orig-column)
|
||||||
|
(if (= (line-number-at-pos) (+ orig-line direction)) ;; did you only move one line?
|
||||||
|
(progn
|
||||||
|
(while (= (line-number-at-pos) (+ orig-line direction))
|
||||||
|
(setq orig-line (line-number-at-pos))
|
||||||
|
(funcall do-search)
|
||||||
|
(move-to-column orig-column))
|
||||||
|
(goto-line orig-line)
|
||||||
|
(move-to-column orig-column)))))
|
||||||
|
|
||||||
|
(defun textmate-column-up (arg)
|
||||||
|
"Move up a column, textmate-style"
|
||||||
|
(interactive "P")
|
||||||
|
(textmate-go-column -1 arg))
|
||||||
|
|
||||||
|
(defun textmate-column-down (arg)
|
||||||
|
"Move down a column, textmate-style"
|
||||||
|
(interactive "P")
|
||||||
|
(textmate-go-column 1 arg))
|
||||||
|
|
||||||
|
(defun textmate-column-up-with-select (arg)
|
||||||
|
"Move up a column, selecting with shift-select"
|
||||||
|
(interactive "P")
|
||||||
|
(unless mark-active (progn (push-mark (point))
|
||||||
|
(setq mark-active t transient-mark-mode t)))
|
||||||
|
(let (deactivate-mark) (textmate-column-up arg)))
|
||||||
|
|
||||||
|
(defun textmate-column-down-with-select (arg)
|
||||||
|
"Move down a column, selecting with shift-select"
|
||||||
|
(interactive "P")
|
||||||
|
(unless mark-active (progn (push-mark (point))
|
||||||
|
(setq mark-active t transient-mark-mode t)))
|
||||||
|
(let (deactivate-mark) (textmate-column-down arg)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(define-minor-mode textmate-mode "TextMate Emulation Minor Mode"
|
(define-minor-mode textmate-mode "TextMate Emulation Minor Mode"
|
||||||
:lighter " mate" :global t :keymap *textmate-mode-map*
|
:lighter " mate" :global t :keymap *textmate-mode-map*
|
||||||
Loading…
Reference in a new issue