Skip to content
Browse files

pony-get-app:

* If buffer-file-name is nil, try default-directory.
* No need for autoload cookie, because it's not interactive.
* No need to create a temporary buffer: use string-match.
* Support app names containing underscores.
* regexp-quote the project root for safety.
  • Loading branch information...
1 parent 2cbd7cd commit 711ed512fd7f12406b3c86e8652f9d536c80d08c @gareth-rees gareth-rees committed Mar 20, 2012
Showing with 7 additions and 10 deletions.
  1. +7 −10 pony-mode.el
View
17 pony-mode.el
@@ -287,16 +287,13 @@ variables; if not found, evaluate .ponyrc instead."
;; about the code near point
;;
-;;;###autoload
-(defun pony-get-app()
- "Get the name of the pony app currently being edited"
- (setq fname (buffer-file-name))
- (with-temp-buffer
- (insert fname)
- (goto-char (point-min))
- (if (looking-at (concat (pony-project-root) "\\([a-z]+\\).*"))
- (buffer-substring (match-beginning 1) (match-end 1))
- nil)))
+(defun pony-get-app ()
+ "Return the name of the current app, or nil if no app found."
+ (let* ((root (pony-project-root))
+ (re (concat "^" (regexp-quote root) "\\([A-Za-z_]+\\)/"))
+ (path (or buffer-file-name (expand-file-name default-directory))))
+ (when (string-match re path)
+ (match-string 1 path))))
;; Environment

0 comments on commit 711ed51

Please sign in to comment.
Something went wrong with that request. Please try again.