Permalink
Browse files

Update find-language to also check the file extension against auto-mo…

…de-alist
  • Loading branch information...
1 parent 50151c6 commit 30d5123b3b9993a42477a318c08468c3153efd76 @wfarr committed Apr 24, 2009
Showing with 17 additions and 8 deletions.
  1. +17 −8 add-import.el
View
@@ -11,14 +11,23 @@
)
(defun find-language ()
- ;; check major mode
- (cond (major-mode
- (let ((current-mode (symbol-name major-mode)))
- (string-match "^\\([[:alpha:]-]+\\)\\-mode" current-mode)
- (match-string 1 current-mode))))
-;;TODO
-;; check file extension
-;; check shebang
+ (cond
+ ;; check major mode
+ ((not (string= major-mode "fundamental-mode"))
+ (let ((current-mode (symbol-name major-mode)))
+ (string-match "^\\([[:alpha:]-]+\\)\\-mode" current-mode)
+ (match-string 1 current-mode)))
+ ;; check extension
+ ((or (and (buffer-file-name)
+ (string-match "\.\\([:alpha:]+\\)$" (buffer-file-name)))
+ (string-match "\.\\([:alpha:]+\\)$" (buffer-name)))
+ (let ((bufname (or (buffer-file-name) (buffer-name))))
+ (dolist (pair auto-mode-alist)
+ (if (string-match (car pair) bufname)
+ (let ((current-mode (symbol-name (cdr pair))))
+ (string-match "^\\([[:alpha:]-]+\\)\\-mode" current-mode)
+ (return (match-string 1 current-mode))))))))
+ ;; check shebang
)
(defun bounds-of-module-at-point ()

0 comments on commit 30d5123

Please sign in to comment.