Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9121081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:46:45+00:00 2026-06-17T05:46:45+00:00

We use an internal scripting language (let’s call it pkc ), which allows for

  • 0

We use an internal scripting language (let’s call it pkc), which allows for embedding C++ code. The C++ code segments are delimited by {{{ and }}} markers.

I create an emacs mode for this language, using Generic Mode and mmm-mode.

Here is what I got (stripped down non-essential parts for posting here):

(require 'generic-x)

(setq pkc-imenu-generic-expression
      '(("macros" "^[ \t]*macro[ \n\t]+\\([a-zA-Z0-9_]+\\)" 1)
        ("functions" "function[ \n\t]+\\([a-zA-Z0-9_]+\\)" 1)
        ))

(require 'cc-mode)      ;; for c++-mode
(require 'mmm-auto)
(setq mmm-global-mode 'maybe)

(define-generic-mode
  'pkc-mode                                  ;; name of the mode to create
  '("//" ("/*" . "*/"))                      ;; comments are same C++ comments
  '( ... )                                   ;; some keywords
  '("\\.pkc$")                               ;; files for which to activate this mode

  ;; other functions to call
  '((lambda ()
      (mmm-mode 1)
      (setq mmm-submode-decoration-level 2)
      (setq imenu-generic-expression pkc-imenu-generic-expression)
      (which-function-mode 1)

      (c-initialize-cc-mode t)
      (c-init-language-vars-for 'c++-mode)
      (c-common-init 'c++-mode)
      (c-update-modeline)

      (message "pkc-mode[mmm] is on")))

  "A mode for pkc source files"                  ;; doc string for this mode
  )

(mmm-add-classes
 '((embedded-c++
    :submode c++-mode
    :face mmm-default-submode-face
    :front "{{{"
    :front-offset -1
    :back "}}}"
    :back-offset 1)))

(mmm-add-mode-ext-class 'pkc-mode nil 'embedded-c++)

When I load the source file with embedded C++ code segments, they are highlighted somewhat less than what would have been if C++ mode was the major mode (that’s not my problem, however). When the cursor in C++ code, the modeline changes to pkc/l[C++/l] (as expected).

The problem is, whenever I press TAB to indent a line, I get the error Wrong type argument: stringp, nil. When I turned on debugger, this is the stack trace I see:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  c-syntactic-skip-backward(nil nil t)
  c-looking-at-decl-block(nil t)
  c-guess-basic-syntax()
  c-indent-line()
  #[nil \302>\203)\212\303 \210\304\305x\210\303 \210\306 )i\306 X\203\"\307    !\202'\212\307  !))\20 \207" [indent-line-function column (indent-relative indent-relative-maybe) beginning-of-line "\n     " nil current-indentation indent-line-to] 2 1908700 nil]()
  c-indent-command(nil)
  c-indent-line-or-region(nil nil)
  call-interactively(c-indent-line-or-region nil nil)

Looking at the definition of c-looking-at-decl-block and particularly the call to `c-syntactic-skip-backward, I find:

    (c-syntactic-skip-backward c-block-prefix-charset limit t)

Examining the first argument c-block-prefix-charset reveals that its value is nil. Doing the same from a plain C++ buffer shows a non-nil value. So, I suspect that C++-mode requires some initialization that’s not being properly done.

So, my questions are:

  1. What am I missing in the C++-mode initialization section in my implementation?
  2. Am I using the right approach (combining generic-x and mmm-mode)? Is there a better approach?

I also see another error (File mode specification error) when I load the file, but I suspect the problem is the same or something similar.

Thanks for your time.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:46:46+00:00Added an answer on June 17, 2026 at 5:46 am

    (Rewritten after the discussion in the comments, for any later visitors).

    The setup in the question is basically fine, but to work with current c++-mode you need to use an updated version of mmm-mode. It’s available at the GitHub project page and also at Melpa.

    The relevant patches (one, two, three) added new entries to the value of mmm-save-local-variables, which mmm-mode uses to decide which local variables to save or restore when leaving or entering a submode region.

    From what I understand, a future update to cc-mode can add more such vars, so the list may need to be updated from time to time.

    Extra tip: to have better indentation in the subregions, you may want to wrap the submode’s indent-line-function with some code that will narrow the buffer before calling it (example here). Depending on the indentation function (and whether it calls widen), it may or may not help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is storing secret keys (internal use passwords and such) on iPhone source code and
I've written a new Visual Studio language service for my software studio's internal scripting
I work with a library which defines its internal division operator for a scripting
I'm adding Powershell support to an app as an internal automation/scripting language. One of
so... Is this a safe way to use internal links on your site.. By
We use an internal library(developed by some other team) built with VC6 compiler. This
I use CDT Internal Builder and MS Visual C++ Toolchain in my project in
We are making a Jabber client for our internal use in our company and
Background We need to develop a specialised CMS (internal use only) to support a
I've been tasked with developing an application for internal use in our company, the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.