Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set Indent Function of Submode #45

Open
Abdillah opened this issue Feb 1, 2015 · 5 comments
Open

Set Indent Function of Submode #45

Abdillah opened this issue Feb 1, 2015 · 5 comments

Comments

@Abdillah
Copy link

Abdillah commented Feb 1, 2015

How exactly I can set indentation function of sub-mode?

I have tried to

  • Adjust it in :creation-hook of class. But it affecting the whole buffer.
(defun js-embed-autoload ()
 "Embedded Javascript upstart configuration"
 (setq-local indent-line-function 'js-embed-indent-line))

;;{{{ JavaScript in HTML

;; We use two classes here, both for code in a <script> tag, one wrapped in
;; CDATA, another not. And another class to group them together.
;;
;; Usage: (mmm-add-mode-ext-class 'html-mode nil 'html-js)
(mmm-add-group
 'html-js
 '((js-script-cdata
    :submode js-mode
    :face mmm-code-submode-face
    :front "<script[^>]*>[ \t\n]*\\(//\\)?<!\\[CDATA\\[[ \t]*\n?"
    :back "[ \t]*\\(//\\)?]]>[ \t\n]*</script>"
    :creation-hook js-embed-autoload)
   (js-script
    :submode js-mode
    :face mmm-code-submode-face
    :front "<script[^>]*>[ \t]*\n?"
    :back "[ \t]*</script>"
    :insert ((?j js-tag nil @ "<script type=\"text/javascript\">\n"
                 @ "" _ "" @ "\n</script>" @))
    :creation-hook js-embed-autoload)))
  • Adjust by setting up mode hook, but it doesn't called in mode changed.
(defun js-embed-set-indent-function ()
 "Embedded Javascript upstart configuration"
 (setq-local indent-line-function 'js-embed-indent-line))

(defun js-embed-autoload ()
 "Embedded Javascript upstart configuration"
 (add-hook 'js-mode-hook 'js-embed-set-indent-function))

;;{{{ JavaScript in HTML, same as Above }}}

Any idea?

@dgutov
Copy link
Owner

dgutov commented Feb 1, 2015

You set mmm-indent-line-function in the primary major mode. See mmm-erb.el for an example. That function can look up in which submode point is and delegate appropriately.

As another option, you can create a new major mode deriving from js-mode to use in subregions. That mode's indent-line-function will be the one to change.

@Abdillah
Copy link
Author

Abdillah commented Feb 4, 2015

Great, It works..!
I choose to add new mode : js-embed-mode. Something like this,

(define-derived-mode js-embed-mode js-mode "JSed"
  "Javascript embedded mode as `js-mode' extension to be used in mmm-mode (or any mulimode package, if possible). Currently only adjust indentation."
  (set (make-local-variable 'mmm-indent-line-function) 'js-embed-indent-line)
  (set (make-local-variable 'standard-indent) 'js-embed-indent-after-tag))

Thanks.

@Abdillah Abdillah closed this as completed Feb 4, 2015
@dgutov
Copy link
Owner

dgutov commented Feb 4, 2015

In that case, I don't think you need to set mmm-indent-line-function.

@Abdillah
Copy link
Author

Abdillah commented Feb 5, 2015

Hmm, why? (Is it is because js-mode is not primary mode)
Then, what should I set?

I figuring out that using mode derived from js-mode in mmm-mode now failed. I will experiment with it more, and so I reopen this..

@Abdillah Abdillah reopened this Feb 5, 2015
@dgutov
Copy link
Owner

dgutov commented Jun 10, 2015

Hmm, why? (Is it is because js-mode is not primary mode)

Yes.

Then, what should I set?

indent-line-function, I suppose.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants