Permalink
Browse files

Added PeepOpen to C-x C-o

 - See https://gist.github.com/1505658 if PeepOpen doesn't behave.
  • Loading branch information...
1 parent 3048343 commit e22ab3d614dac7f7a77ac97690366c7a4f378806 @magnars committed Dec 21, 2011
View
@@ -55,3 +55,6 @@
[submodule "site-lisp/bash-completion"]
path = site-lisp/bash-completion
url = https://github.com/szermatt/emacs-bash-completion.git
+[submodule "site-lisp/eproject"]
+ path = site-lisp/eproject
+ url = https://github.com/jrockway/eproject.git
View
@@ -63,6 +63,7 @@
(require 'inline-string-rectangle)
(require 'delsel)
(require 'iy-go-to-char)
+(require 'eproject)
;; Vimgolf
(load (expand-file-name "vimgolf/emacs/vimgolf.el" site-lisp-dir))
View
@@ -83,10 +83,8 @@
;; Edit file with sudo
(global-set-key (kbd "M-s e") 'sudo-edit)
-;; Window switching. (C-x o goes to the next window)
+;; Window switching
(windmove-default-keybindings) ;; Shift+direction
-(global-set-key (kbd "C-x O") (lambda () (interactive) (other-window -1))) ;; back one
-(global-set-key (kbd "C-x C-o") (lambda () (interactive) (other-window 2))) ;; forward two
(global-set-key (kbd "C-x -") 'rotate-windows)
;; Indentation help
View
7 mac.el
@@ -20,4 +20,11 @@
;; Ignore .DS_Store files with ido mode
(add-to-list 'ido-ignore-files "\\.DS_Store")
+;; Don't open files from the workspace in a new frame
+(setq ns-pop-up-frames nil)
+
+;; PeepOpen
+;; See https://gist.github.com/1505658 if PeepOpen opens selected files in a new Emacs instance
+(require 'eproject-peepopen)
+
(provide 'mac)
@@ -0,0 +1,21 @@
+# eproject-peepopen
+
+## About
+
+eproject-peepopen.el is a light-weight alternative to TopFunky's peepopen.el (https://github.com/topfunky/PeepOpen-EditorSupport), which depends on the presence of textmate.el for basic functionality.
+
+eproject-peepopen uses jrockway's eproject.el to provide the same PeepOpen integration without introducing any of textmate.el's extraneous functionality.
+
+## Prerequisites
+
+If you don't already have it, install eproject.el (https://github.com/jrockway/eproject)
+
+## Installation
+
+1. cd ~/.emacs.d/vendor (or your local equivalent)
+1. git clone git://github.com/mbarnett/eproject-peepopen
+1. Add the following to your emacs config file:
+
+ (add-to-list 'load-path "~/.emacs.d/vendor/eproject-peepopen")
+
+ (require 'eproject-peepopen)
@@ -0,0 +1,79 @@
+;; eproject-peepopen.el --- Graphical file chooser for Emacs on Mac OS X.
+;; Modified from peepopen.el at https://github.com/topfunky/PeepOpen-EditorSupport/blob/master/peepopen.el
+
+;; 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/
+;;
+;; Further Modified & Renamed, 2011-05-08: Matthew Barnett (matt@wtmworldwide.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 version replaces peeopen.el's dependency on the heavy-weight
+;; textmate mode with a lighter weight dependency on jrockway's eproject
+;; needed only for identifying the root directory of a project
+;;
+;; Calls the external PeepOpen.app when you hit Meta-t (or equivalent) in eproject-mode.
+
+;; C-x C-o - Go to File
+
+;;; Installation:
+
+;; This plugin assumes that you've already loaded Jonathan Rockway's
+;; eproject.el in your emacs configuration. Load this file afterward.
+;;
+;; Copy this file to ~/.emacs.d/vendor/eproject-peepopen.el
+;;
+
+;; You'll also need eproject.el:
+;;
+;; $ cd ~/.emacs.d/vendor
+;; $ git clone https://github.com/jrockway/eproject.git
+
+;; Require both libraries and activate eproject.
+;; 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/eproject.el")
+;; (require 'eproject)
+;; (add-to-list 'load-path "~/.emacs.d/vendor/")
+;; (require 'eproject-peepopen)
+
+;; For Emacs 23 or Aquamacs, use this to open files in the existing frame:
+;;
+;; (setq ns-pop-up-frames nil)
+
+;;;###autoload
+(defun eproject-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 (eproject-root)))
+ (when (null root)
+ (error
+ (concat
+ "Can't find a suitable project root")))
+ (shell-command-to-string
+ (format "open 'peepopen://%s?editor=%s'"
+ (expand-file-name root)
+ "EmacsClient"))))
+
+(define-key eproject-mode-map (kbd "C-x C-o") #'eproject-peepopen-goto-file-gui)
+
+(provide 'eproject-peepopen)
@@ -0,0 +1,2 @@
+*.elc
+TAGS
@@ -0,0 +1,39 @@
+This is the contrib section, an area for eproject-using features that
+are more complicated than a few functions, or may not be suitable for
+eproject-extras.
+
+Please contribute anything you want here, but keep the following in
+mind:
+
+ * The code must be released under the same license as Emacs itself.
+
+ * Nothing in here will be loaded by default; if your file is being
+ loaded, it's because the user wants it to take effect. Therefore,
+ feel free to add hooks and keybindings, if necessary.
+
+ * Ensure that any configuration is made customizable via defcustom.
+
+ * Follow the proper conventions for keybindings that you create by
+ default.
+
+ * Namespace your functions with
+ eproject-<extension>-<function-name>. If you don't want the
+ function to be public, use two dashes between your extension name
+ and the function name, like: eproject-foo--internal-foobar.
+ Public functions should retain backwards compatability between
+ releases, so if you're not sure you want to obligate yourself to
+ that, keep the function internal.
+
+ * Commands (interactive functions) should have a docstring that
+ checkdoc (M-x checkdoc) likes. Yes, you really need to write
+ "Return FOO.", not "Returns foo".
+
+ * Documentation is always helpful. Feel free to write long-form
+ documentation in another file, perhaps your-extension.txt or
+ your-extension.md.
+
+ * Do not define project types here. Do that in the lang/ section.
+
+The eproject community thanks you for your contribution! Please do
+not hesitate to ask for direct commit access to the main repository.
+It will be granted.
@@ -0,0 +1,122 @@
+;;; eproject-tags.el --- visit project-specific tags table and keep it up to date
+
+;; Copyright (C) 2011 Jonathan Rockway
+
+;; Author: Jonathan Rockway <jon@jrock.us>
+;; Keywords: convenience, programming, tags
+
+;; 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:
+
+;;
+
+;;; Code:
+
+(eval-when-compile
+ (require 'cl))
+(require 'eproject)
+
+(defvar eproject-tags-etags "etags"
+ "The command you want to run to generate the tags file.
+
+It must accept a list of relative filenames and send its output
+to a file named TAGS.")
+
+(defvar eproject-tags-verbose t
+ "Set to T if you want the verbose output of etags to stick around.
+
+Only works with exuberant-ctags; this will cause standard etags to blow up in a giant ball of fire.")
+
+(defvar eproject-tags-callback nil)
+(defvar eproject-tags-state nil)
+(make-variable-buffer-local 'eproject-tags-callback)
+(make-variable-buffer-local 'eproject-tags-state)
+
+(defun eproject-tags--buffer (root)
+ (let* ((name (concat (eproject-attribute :name root) "-TAGS"))
+ (buf (get-buffer-create (format "*%s*" name))))
+ buf))
+
+(defun eproject-tags--debug-message (root format &rest rest)
+ (when eproject-tags-verbose
+ (with-current-buffer (eproject-tags--buffer root)
+ (goto-char (point-max))
+ (insert (apply #'format (concat "** " format) rest))
+ (insert "\n"))))
+
+(defun eproject-tags--generate (cb &optional state root)
+ "Generate a tags table for this project (or the project in ROOT), calling CB with the project root and STATE upon completion.
+
+All project-relevant files are considered and output goes to root/TAGS. The tags table is not visited after generation."
+ (let* ((root (or root (eproject-root)))
+ (default-directory root)
+ (files (eproject-list-project-files-relative root))
+ (name (concat (eproject-attribute :name root) "-TAGS"))
+ (buf (eproject-tags--buffer root))
+ (args (append '("-o" ".TAGS-tmp")
+ (if eproject-tags-verbose '("--verbose"))))
+ (proc (apply #'start-process name buf eproject-tags-etags
+ (append args files))))
+
+ (with-current-buffer buf
+ (setq eproject-tags-callback cb)
+ (setq eproject-tags-state state)
+ (setq eproject-root root))
+
+ (set-process-sentinel proc #'eproject-tags--sentinel))
+ nil)
+
+(defun eproject-tags--sentinel (process event)
+ (with-current-buffer (process-buffer process)
+ (let ((default-directory eproject-root))
+ (when (and eproject-tags-callback (equal event "finished\n"))
+ (rename-file ".TAGS-tmp" "TAGS" t)
+ (apply eproject-tags-callback eproject-tags-state)
+ (delete-process process)
+ (when (not eproject-tags-verbose)
+ (kill-buffer))))))
+
+;;; TODO: un-visit this table when all project buffers go away?
+;;; TODO: make the tags table "project-local"
+
+(defun eproject-tags (&optional root)
+ "Update (or generate) and visit a tags table for the project in ROOT."
+ (interactive)
+ (let ((root (or root (eproject-root))))
+ (eproject-tags--generate
+ #'eproject-tags--visit-table (list root) root)))
+
+(defun eproject-tags--visit-table (root &rest state)
+ "Callback called by eproject-tags after tags table has been created."
+ (let ((table (concat (file-name-as-directory root) "TAGS"))
+ (tags-revert-without-query t))
+ (add-to-list 'tags-table-list table t #'equal)
+ (tags-verify-table table)))
+
+(defun eproject-tags--from-hook ()
+ (let ((root (ignore-errors (eproject-root)))
+ (file (ignore-errors (buffer-file-name))))
+ (when (and root file
+ (eproject-classify-file file root)
+ (not (eproject-attribute :suppress-tags root)))
+ (eproject-tags--debug-message
+ root "Regenerating tags table for %s because %s changed" root file)
+ (eproject-tags root))))
+
+(add-hook 'eproject-first-buffer-hook #'eproject-tags--from-hook)
+(add-hook 'eproject-project-change-hook #'eproject-tags--from-hook)
+
+(provide 'eproject-tags)
+;;; eproject-tags.el ends here
Oops, something went wrong.

0 comments on commit e22ab3d

Please sign in to comment.