dgutov / mmm-mode

New official home for mmm-mode, fixed for Emacs >= 23
http://mmm-mode.sourceforge.net/
GNU General Public License v2.0
333 stars 31 forks source link

emacs-26.3 more mmm-vars.el for C mode #116

Open kuszmaul opened 4 years ago

kuszmaul commented 4 years ago

These variables seem necessary to get C mode to work inside mmm.

git diff
diff --git a/mmm-vars.el b/mmm-vars.el
index 00478eb..9d04636 100644
--- a/mmm-vars.el
+++ b/mmm-vars.el
@@ -184,6 +184,7 @@
     c-comment-prefix-regexp
     c-comment-start-regexp
     c-cpp-defined-fns
+    c-cpp-expr-functions-key
     c-current-comment-prefix
     c-decl-block-key
          c-decl-hangon-key
@@ -196,6 +197,7 @@
     c-expr-kwds
     c-file-offsets
     c-file-style
+    c-found-types
          c-not-primitive-type-keywords-regexp
     c-hanging-braces-alist
     c-hanging-colons-alist
@@ -223,8 +225,10 @@
     c-lambda-kwds
          c-literal-start-regexp
     c-macro-with-semi-re
+    c-make-top-level-key
          ;; c-make-top-level-key
          ;; c-make-top-level-kwds
+    c-noise-macro-with-parens-name-re
          c-nonlabel-token-key
          c-nonlabel-token-2-key
          c-nonsymbol-chars
@@ -258,6 +262,7 @@
     c-other-decl-block-kwds
     c-other-decl-kwds
     c-overloadable-operators-regexp
+    c-pack-key
          c-paragraph-separate
          c-paragraph-start
          c-paren-stmt-key
@@ -286,6 +291,7 @@
          c-syntactic-ws-start
          c-type-decl-prefix-key
          c-type-decl-suffix-key
+    c-type-decl-suffix-ws-ids-key
     c-type-prefix-key
          c-typeof-key
          c-prefix-spec-kwds-re
dgutov commented 4 years ago

Thanks!

Does it actually work for you with these changes?

With C mode as the primary mode or a submode?

kuszmaul commented 4 years ago

latex as the primary mode, C++ as the submode. It works, but I cannot claim that I tested it extensively.

I'm included to follow the advice I just saw elsewhere and just go to js-mode, however. It seems like the C engine is going to be a problem forever...

kuszmaul commented 4 years ago

Perhaps it would be good to include documentation to the effect, and also show how to use latex lstlisting.

(mmm-add-classes '((lstlisting-c++
                    :submode js-mode
                    :front "^\\\\begin{lstlisting}"
                    :back  "^\\\\end{lstlisting}"
                    :front-offset (end-of-line 1)
                    :back-offset (beginning-of-line -1))))
(mmm-add-mode-ext-class 'latex-mode nil 'lstlisting-c++)
dgutov commented 4 years ago

Is that like CWeb? See mmm-cweb.el and the comments at the bottom.

dgutov commented 4 years ago

latex as the primary mode, C++ as the submode. It works, but I cannot claim that I tested it extensively.

Thanks. That's good enough for me. If it breaks later (again), it breaks, but why not make this small effort, especially since you have already come up with the list.

kuszmaul commented 4 years ago

Is that like CWeb? See mmm-cweb.el and the comments at the bottom.

I'm not sure. The lstlisting environment is one of the two main ways that people write code in latex. (The other way is minted, which is about the same. You write things like

-*- mode: latex -*

The defintion of the $n$th fibonacci number is
 \[ \mbox{fib}(n) = \left{ \begin{array}{ll}
     n & \mbox{if $n \leq 2$,}
     \mbox{fib}(n-1) + \mbox{fib}(n-2) &\mbox{otherwise.}
 \end{array} \right. \]
which you can implement in C as
\begin{lstlisting}
int fib(int n) {
  if (n <= 2) return n;
  else return fib(n-1)+fib(n-2);
}
\end{lstlisting}

No guarantees that that code will compile. I just wrote it.

dgutov commented 4 years ago

Perhaps it would be good to include documentation to the effect, and also show how to use latex lstlisting

Not sure what's a good place for that, though. mmm-sample.el?