Skip to content

Commit

Permalink
Lots of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ignacy committed Dec 6, 2010
1 parent 5e07ea0 commit 3724861
Show file tree
Hide file tree
Showing 7 changed files with 827 additions and 66 deletions.
56 changes: 30 additions & 26 deletions bookmarks
Expand Up @@ -2,29 +2,33 @@
;;; This format is meant to be slightly human-readable;
;;; nevertheless, you probably don't want to edit it.
;;; -*- End Of Bookmark File Format Version Stamp -*-
(("customer_show_view"
(filename . "~/code/middleware/app/views/customers/show.html.haml")
(front-context-string . "\n%tbody\n %tr\n ")
(rear-context-string . "_to 'Calls', '#'")
(position . 49))
("rc.lua "
(filename . "~/.config/awesome/rc.lua")
(front-context-string . "-- Standard awes")
(rear-context-string)
(position . 1))
("org-remember-last-stored"
(filename . "~/Dropbox/org/notes.org")
(front-context-string . "** [2010-12-06 p")
(rear-context-string . "ories present]]\n")
(position . 72363))
("zshr"
(filename . "~/.zshrc")
(front-context-string . "# Lines configur")
(rear-context-string)
(position . 1))
("init"
(filename . "~/.emacs.d/init.el")
(front-context-string . "(setq dotfiles-d")
(rear-context-string)
(position . 1))
)
(("ruby-setup.el"
(filename . "~/.emacs.d/imoryc/ruby-setup.el")
(front-context-string . ";; Setup ruby\n\n(")
(rear-context-string)
(position . 1))
("customer_show_view"
(filename . "~/code/middleware/app/views/customers/show.html.haml")
(front-context-string . "\n%tbody\n %tr\n ")
(rear-context-string . "_to 'Calls', '#'")
(position . 49))
("rc.lua "
(filename . "~/.config/awesome/rc.lua")
(front-context-string . "-- Standard awes")
(rear-context-string)
(position . 1))
("org-remember-last-stored"
(filename . "~/Dropbox/org/notes.org")
(front-context-string . "** [2010-12-06 p")
(rear-context-string . "ories present]]\n")
(position . 72363))
("zshr"
(filename . "~/.zshrc")
(front-context-string . "# Lines configur")
(rear-context-string)
(position . 1))
("init"
(filename . "~/.emacs.d/init.el")
(front-context-string . "(setq dotfiles-d")
(rear-context-string)
(position . 1)))
65 changes: 65 additions & 0 deletions imoryc/project-top.el
@@ -0,0 +1,65 @@
;; Find the top of a project

(defconst project-top-default-top-files '(".git" "Rakefile" "rakelib" "lib" "config"))

(defun project-top (&rest top-files)
"Return the file-name to the top of the project containing the current buffer."
(project-top-from
(project-top-starting-point)
(if (null top-files)
project-top-default-top-files
(project-top-from (project-top-starting-point) top-files))))

(defun project-top-find-file (&rest args)
"Return the path to the file given a relative path from the project top.
Usage: (project-top-find-file config/database.yml)
(project-top-find-file config/database.yml starting-file)
(project-top-file-file config/database.yml starting-file top-files)"
(let ((file-path (apply 'project-top-path-to args)))
(if (and file-path (file-exists-p file-path))
(find-file file-path)
(message (concat "Can't find file " (car args))))))

(defun project-top-path-to (file-from-top &rest args)
"Return the path to the file given a relative path from the project top.
Usage: (project-path-to config/database.yml)
(project-path-to config/database.yml starting-file)
(project-path-to config/database.yml starting-file top-files)"
(let* ((from-path (project-top-arg args (project-top-starting-point)))
(top-files (project-top-arg (cdr args) project-top-default-top-files))
(path (project-top-from from-path top-files)))
(if path (concat (file-name-as-directory path) file-from-top))))

(defun project-top-from (path top-files)
"Return the path to the top of the project containing path.
Returns nil if no project top found. Use the list of possible
top-files to determine the top of the project."
(cond ((null path) nil)
((project-top-at-top-p path top-files) path)
(t (project-top-from (project-top-parent path) top-files))))

(defun project-top-at-top-p (path top-files)
"Is the path at the top level of a project?"
(cond ((null top-files) nil)
((project-top-contains-p path (car top-files)) t)
(t (project-top-at-top-p path (cdr top-files)))))

(defun project-top-parent (path)
"Return the parent directory of path. The parent of / is nil."
(cond ((string-equal "/" path) nil)
(t (file-name-directory (directory-file-name path))) ) )

(defun project-top-contains-p (dir file)
(file-exists-p (concat (file-name-as-directory dir) file)))

(defun project-top-arg (opt default-value)
"Return the car of opt if it is not null, otherwise return the default value."
(if (null opt) default-value (car opt)))

(defun project-top-starting-point ()
(let ((cur (buffer-file-name (current-buffer))))
(if cur
cur
(directory-file-name (substring (pwd) 10)))))

(provide 'project-top)
67 changes: 67 additions & 0 deletions imoryc/rake-setup.el
@@ -0,0 +1,67 @@
;;; ==================================================================
;;; Author: Jim Weirich
;;; File: ini-rake
;;; Purpose: Rake / Emacs Integration
;;; ==================================================================

;;; Name of the buffer used to capture rake output.
(defconst jw-rake-buffer-name "*rake*")

;;; Name of the buffer used to capture rake tasks.
(defconst jw-rake-task-buffer-name "*rake-tasks*")

;;; Name of the rake command.
(defconst jw-run-rake-command "rake")

;;; Name of the rake process.
(defconst jw-rake-process-name "*rake-process*")

(defun jw-rake-tasks ()
(if (get-buffer jw-rake-task-buffer-name)
(kill-buffer jw-rake-task-buffer-name))
(call-process "rake" nil jw-rake-task-buffer-name nil "-T"))

(defun jw-rake-parse-task-names ()
(save-current-buffer
(set-buffer jw-rake-task-buffer-name)
(goto-char (point-min))
(let ((result nil) (n 0))
(while (re-search-forward "^rake \\([a-zA-Z0-9_:]+\\)" nil t)
(setq n (+ n 1))
(setq result (cons (list (buffer-substring (match-beginning 1) (match-end 1)) n)
result)) )
result)))

(defun jw-rake-read-task ()
"Fill the rake task buffer with the rake commands available at the moment."
(interactive)
(jw-rake-tasks)
(completing-read "Rake Task: " (jw-rake-parse-task-names)))

(defun jw-rake-process-filter (proc string)
"Process the output from the rake process.
Just insert into the rake output buffer, removing any carriage
returns along the way."
(with-current-buffer (process-buffer proc)
(let ((moving (= (point) (process-mark proc))))
(save-excursion
(goto-char (process-mark proc))
(insert (replace-regexp-in-string "
" "" string))
(set-marker (process-mark proc) (point)))
(if moving (goto-char (process-mark proc))))))

(defun jw-start-rake-process (task)
"Start the rake process using *cmd* and any optional *args*.
The process is run asynchronously and the output is placed in the
buffer identified by jw-rake-buffer-name."
(let* ((process
(start-process jw-rake-process-name
jw-rake-buffer-name jw-run-rake-command task)))
(set-process-filter process 'jw-rake-process-filter) ))

(defun rake ()
(interactive)
(if (get-buffer jw-rake-buffer-name) (kill-buffer jw-rake-buffer-name))
(jw-start-rake-process (jw-rake-read-task))
(pop-to-buffer jw-rake-buffer-name))
189 changes: 189 additions & 0 deletions imoryc/ruby-electric.el
@@ -0,0 +1,189 @@
;; -*-Emacs-Lisp-*-
;;
;; ruby-electric.el --- electric commands editing for ruby files
;;
;; Copyright (C) 2005 by Dee Zsombor <dee dot zsombor at gmail dot com>.
;; Released under same license terms as Ruby.
;;
;; Due credit: this work was inspired by a code snippet posted by
;; Frederick Ros at http://rubygarden.org/ruby?EmacsExtensions.
;;
;; Following improvements where added:
;;
;; - handling of strings of type 'here document'
;; - more keywords, with special handling for 'do'
;; - packaged into a minor mode
;;
;; Usage:
;;
;; 0) copy ruby-electric.el into directory where emacs can find it.
;;
;; 1) modify your startup file (.emacs or whatever) by adding
;; following line:
;;
;; (require 'ruby-electric)
;;
;; 2) toggle Ruby Electric Mode on/off with ruby-electric-mode.
;;
;; Changelog:
;;
;; 2005/Jan/14: inserts matching pair delimiters like {, [, (, ', ",
;; ' and | .
;;
;; 2005/Jan/14: added basic Custom support for configuring keywords
;; with electric closing.
;;
;; 2005/Jan/18: more Custom support for configuring characters for
;; which matching expansion should occur.
;;
;; 2005/Jan/18: no longer uses 'looking-back' or regexp character
;; classes like [:space:] since they are not implemented on XEmacs.



(require 'ruby-mode)

(defconst ruby-electric-expandable-do-re
"do\\s-$")

(defconst ruby-electric-expandable-bar
"\\s-\\(do\\|{\\)\\s-+|")

(defvar ruby-electric-matching-delimeter-alist
'((?\[ . ?\])
(?\( . ?\))
(?\' . ?\')
(?\` . ?\`)
(?\" . ?\")))

(defcustom ruby-electric-simple-keywords-re
"\\(def\\|if\\|class\\|module\\|unless\\|case\\|while\\|do\\|until\\|for\\|begin\\)"
"*Regular expresion matching keywords for which closing 'end'
is to be inserted."
:type 'regexp :group 'ruby-electric)

(defcustom ruby-electric-expand-delimiters-list '(all)
"*List of contexts where matching delimiter should be
inserted. The word 'all' will do all insertions."
:type '(set :extra-offset 8
(const :tag "Everything" all )
(const :tag "Curly brace" ?\{ )
(const :tag "Square brace" ?\[ )
(const :tag "Round brace" ?\( )
(const :tag "Quote" ?\' )
(const :tag "Double quote" ?\" )
(const :tag "Back quote" ?\` )
(const :tag "Veritcal bar" ?\| ))
:group 'ruby-electric)

(defcustom ruby-electric-newline-before-closing-bracket nil
"*Controls whether a newline should be inserted before the
closing bracket or not."
:type 'boolean :group 'ruby-electric)

(define-minor-mode ruby-electric-mode
"Toggle Ruby Electric mode.
With no argument, this command toggles the mode. Non-null prefix
argument turns on the mode. Null prefix argument turns off the
mode.
When Ruby Electric mode is enabled, an indented 'end' is
heuristicaly inserted whenever typing a word like 'module',
'class', 'def', 'if', 'unless', 'case', 'until', 'for', 'begin',
'do'. Simple, double and back quotes as well as braces are paired
auto-magically. Expansion does not occur inside comments and
strings. Note that you must have Font Lock enabled."
;; initial value.
nil
;;indicator for the mode line.
" REl"
;;keymap
ruby-mode-map
(ruby-electric-setup-keymap))

(defun ruby-electric-setup-keymap()
(define-key ruby-mode-map " " 'ruby-electric-space)
(define-key ruby-mode-map "{" 'ruby-electric-curlies)
(define-key ruby-mode-map "(" 'ruby-electric-matching-char)
(define-key ruby-mode-map "[" 'ruby-electric-matching-char)
(define-key ruby-mode-map "\"" 'ruby-electric-matching-char)
(define-key ruby-mode-map "\'" 'ruby-electric-matching-char)
(define-key ruby-mode-map "|" 'ruby-electric-bar))

(defun ruby-electric-space (arg)
(interactive "P")
(self-insert-command (prefix-numeric-value arg))
(if (ruby-electric-space-can-be-expanded-p)
(save-excursion
(ruby-indent-line t)
(newline)
(ruby-insert-end))))

(defun ruby-electric-code-at-point-p()
(and ruby-electric-mode
(let* ((properties (text-properties-at (point))))
(and (null (memq 'font-lock-string-face properties))
(null (memq 'font-lock-comment-face properties))))))

(defun ruby-electric-string-at-point-p()
(and ruby-electric-mode
(consp (memq 'font-lock-string-face (text-properties-at (point))))))

(defun ruby-electric-is-last-command-char-expandable-punct-p()
(or (memq 'all ruby-electric-expand-delimiters-list)
(memq last-command-char ruby-electric-expand-delimiters-list)))

(defun ruby-electric-space-can-be-expanded-p()
(if (ruby-electric-code-at-point-p)
(let* ((ruby-electric-keywords-re
(concat ruby-electric-simple-keywords-re "\\s-$"))
(ruby-electric-single-keyword-in-line-re
(concat "\\s-*" ruby-electric-keywords-re)))
(save-excursion
(backward-word)
(or (looking-at ruby-electric-expandable-do-re)
(and (looking-at ruby-electric-keywords-re)
(not (string= "do" (match-string 1)))
(progn
(beginning-of-line)
(looking-at ruby-electric-single-keyword-in-line-re))))))))


(defun ruby-electric-curlies(arg)
(interactive "P")
(self-insert-command (prefix-numeric-value arg))
(if (ruby-electric-is-last-command-char-expandable-punct-p)
(cond ((ruby-electric-code-at-point-p)
(insert " ")
(save-excursion
(if ruby-electric-newline-before-closing-bracket
(newline))
(insert "}")))
((ruby-electric-string-at-point-p)
(save-excursion
(backward-char 1)
(when (char-equal ?\# (preceding-char))
(forward-char 1)
(insert "}")))))))

(defun ruby-electric-matching-char(arg)
(interactive "P")
(self-insert-command (prefix-numeric-value arg))
(and (ruby-electric-is-last-command-char-expandable-punct-p)
(ruby-electric-code-at-point-p)
(save-excursion
(insert (cdr (assoc last-command-char
ruby-electric-matching-delimeter-alist))))))

(defun ruby-electric-bar(arg)
(interactive "P")
(self-insert-command (prefix-numeric-value arg))
(and (ruby-electric-is-last-command-char-expandable-punct-p)
(ruby-electric-code-at-point-p)
(and (save-excursion (re-search-backward ruby-electric-expandable-bar nil t))
(= (point) (match-end 0))) ;looking-back is missing on XEmacs
(save-excursion
(insert "|"))))


(provide 'ruby-electric)

0 comments on commit 3724861

Please sign in to comment.