[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master d06e9a3 143/433: (mmm-here-doc-get-mode): Extended to reco
From: |
Dmitry Gutov |
Subject: |
[elpa] master d06e9a3 143/433: (mmm-here-doc-get-mode): Extended to recognize names like TEXT_EOF. |
Date: |
Thu, 15 Mar 2018 19:43:52 -0400 (EDT) |
branch: master
commit d06e9a35f4a412473904a543a537010dade3e9b0
Author: mas <mas>
Commit: mas <mas>
(mmm-here-doc-get-mode): Extended to recognize names like TEXT_EOF.
---
mmm-sample.el | 60 +++++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 44 insertions(+), 16 deletions(-)
diff --git a/mmm-sample.el b/mmm-sample.el
index 198c6d1..eea1b26 100644
--- a/mmm-sample.el
+++ b/mmm-sample.el
@@ -3,7 +3,7 @@
;; Copyright (C) 2000 by Michael Abraham Shulman
;; Author: Michael Abraham Shulman <address@hidden>
-;; Version: $Id: mmm-sample.el,v 1.9 2000/07/29 17:27:23 mas Exp $
+;; Version: $Id: mmm-sample.el,v 1.10 2000/08/01 01:54:03 mas Exp $
;;{{{ GPL
@@ -73,25 +73,53 @@ otherwise `c++-mode'. Some people prefer `c++-mode'
regardless.")
;;{{{ Here-documents
;; Here we match the here-document syntax used by Perl and shell
-;; scripts. We assume that the delimiter of the here-document is the
-;; mode name with or without `-mode', such as <<HTML or <<HTML-MODE.
-;; Hyphens may be replaced with underscores to make <<HTML_MODE and
-;; the mode name is converted to lower case. Additional characters
-;; may be added after `MODE', such as <<HTML_MODE_EOF.
+;; scripts. We try to be automagic about recognizing what mode the
+;; here-document should be in; to make sure that it is recognized
+;; correctly, the name of the mode, perhaps minus `-mode', in upper
+;; case, and/or with hyphens converted to underscores, should be
+;; separated from the rest of the here-document name by hyphens or
+;; underscores.
+
+(defvar mmm-here-doc-mode-alist '()
+ "Alist associating here-document name regexps to submodes.
+Normally, this variable is unnecessary, as the `here-doc' submode
+class tries to automagically recognize the right submode. If you use
+here-document names that it doesn't recognize, however, then you can
+add elements to this alist. Each element is \(REGEXP . MODE) where
+REGEXP is a regular expression matched against the here-document name
+and MODE is a major mode function symbol.")
(defun mmm-here-doc-get-mode (string)
(string-match "[a-zA-Z_-]+" string)
(setq string (match-string 0 string))
- (let* ((case-fold-search t)
- (modestr (if (string-match "mode" string)
- (downcase (substring string 0 (match-end 0)))
- (concat (downcase string) "-mode"))))
- (while (string-match "_" modestr)
- (setq modestr (replace-match "-" nil nil modestr)))
- (setq modestr (intern modestr))
- (if (fboundp modestr)
- modestr
- (signal 'mmm-no-matching-submode nil))))
+ (or (mmm-ensure-fboundp
+ ;; First try the user override variable.
+ (some #'(lambda (pair)
+ (if (string-match (car pair) string) (cdr pair) nil))
+ mmm-here-doc-mode-alist))
+ (let ((words (split-string (downcase string) "[_-]+")))
+ (or (mmm-ensure-fboundp
+ ;; Try the whole name, stopping at "mode" if present.
+ (intern
+ (mapconcat #'identity
+ (nconc (ldiff words (member "mode" words))
+ (list "mode"))
+ "-")))
+ ;; Try each word with -mode tacked on
+ (some #'(lambda (word)
+ (mmm-ensure-fboundp
+ (intern (concat word "-mode"))))
+ words)
+ ;; Try each pair of words with -mode tacked on
+ (loop for (one two) on words
+ if (mmm-ensure-fboundp
+ (intern (concat one two "-mode")))
+ return it)
+ ;; I'm unaware of any modes whose names, minus `-mode',
+ ;; are more than two words long, and if the entire mode
+ ;; name (perhaps minus `-mode') doesn't occur in the
+ ;; here-document name, we can give up.
+ (signal 'mmm-no-matching-submode nil)))))
(mmm-add-classes
'((here-doc
- [elpa] master b0b7520 217/433: # Added comment about bug fix., (continued)
- [elpa] master b0b7520 217/433: # Added comment about bug fix., Dmitry Gutov, 2018/03/15
- [elpa] master 293e13a 198/433: (mmm-format-matches): Changed to allow accessing any subexp, not, Dmitry Gutov, 2018/03/15
- [elpa] master 2a00982 215/433: * mmm-mason.el (mmm-mason-end-line, mmm-mason-start-line): Use bolp, Dmitry Gutov, 2018/03/15
- [elpa] master 1ef198a 219/433: # Updated, Dmitry Gutov, 2018/03/15
- [elpa] master ef73242 214/433: Added `javascript-mode' to list of C-derived modes., Dmitry Gutov, 2018/03/15
- [elpa] master 23170fe 205/433: Added `mmm-primary-mode' variable so that `major-mode' can be saved., Dmitry Gutov, 2018/03/15
- [elpa] master 72ca55f 213/433: # Updated menus., Dmitry Gutov, 2018/03/15
- [elpa] master c95f9b0 157/433: Added file (contributed by Marcus Harnisch)., Dmitry Gutov, 2018/03/15
- [elpa] master c9c6c19 194/433: Added ePerl and JSP to autoload., Dmitry Gutov, 2018/03/15
- [elpa] master c659e19 141/433: Released 0.4.4, Dmitry Gutov, 2018/03/15
- [elpa] master d06e9a3 143/433: (mmm-here-doc-get-mode): Extended to recognize names like TEXT_EOF.,
Dmitry Gutov <=
- [elpa] master 28cda1d 160/433: # Added headers., Dmitry Gutov, 2018/03/15
- [elpa] master ad9724f 140/433: # Updated., Dmitry Gutov, 2018/03/15
- [elpa] master 36e10b1 167/433: (mmm-ify): Explicitly set defaults for keywords in &rest parameter., Dmitry Gutov, 2018/03/15
- [elpa] master 944e3b4 173/433: Set MASON_VERSION., Dmitry Gutov, 2018/03/15
- [elpa] master 588edf0 169/433: (mmm-set-file-name-for-modes): Changed to a list for finer control., Dmitry Gutov, 2018/03/15
- [elpa] master 5f96947 177/433: # Added comment about apostrophes, Dmitry Gutov, 2018/03/15
- [elpa] master a58c9bc 178/433: Added comment about adding files to the distribution., Dmitry Gutov, 2018/03/15
- [elpa] master e31cf25 170/433: (mmm-update-mode-info): Tested against `mmm-set-file-name-for-modes'., Dmitry Gutov, 2018/03/15
- [elpa] master 2defd28 188/433: (mmm-save-local-variables): Added `parse-sexp-ignore-comments', which, Dmitry Gutov, 2018/03/15
- [elpa] master e4084f8 186/433: Added set-background example for XEmacs., Dmitry Gutov, 2018/03/15