0

The parallel toolbox for MATLAB has a command, spmd (https://se.mathworks.com/help/parallel-computing/spmd.html), that octave-mode does not recognize. Note: I know how to make octave-mode recognize it as a keyword.

The problem is that MATLAB expects spmd to have a matching end, which confuses octave-mode that sees an "extra" end. In addition, the statements in between should be indented. E.g. like this:

parpool(3)
spmd
  q = magic(labindex + 2);
end

How can I make octave-mode treat spmd as per above?

The lisp snippet below makes octave-mode highlight spmd as if it was a keyword:

(font-lock-add-keywords 'octave-mode
                        '(("\\<spmd\\>". font-lock-keyword-face)))

Update: Clarified intention of workaround snippet above.

Update 2: Using Stefan's workaround partially solves the issue. The end is now matched to spmd, although indentation is to large for some reason. See below for an example of the result, where the statements

      while false
        1;             # The expected amount of indentation
      end

      spmd
          1;           # Twice the expected amount of indentation
      end
0

The font-lock-add-keywords doesn't really make "octave-mode treat spmd as a keyword", it just highlights it as such.

I suggest you M-x report-emacs-bug and request support for this new syntax.

In the mean time, you can hack your way around with something like:

(add-hook 'octave-mode-hook #'my-octave-grammar-extend)
(defun my-octave-grammar-extend ()
  (unless (assoc "spmd" smie-grammar)
    (push (cons "spmd" (cdr (assoc "while" smie-grammar)))
          smie-grammar)))

which should at least make spmd match with end (and vice-versa) and hopefully make indentation less confused.

| improve this answer | |
  • Sorry for being unclear regarding why I mentioned font-lock-add-keywords. I had only added that part as a partial workaround to get highlighting of spmd. – chr Jul 17 '19 at 8:13
  • I tried the workaround above, and it does make octave-mode match the spdm with it's 'end', which is a significant improvement. However, it does result in twice as much indentation compared to a 'while ... end'. I'll update my question with an example of what the result looks like for anyone who wishes to use this workaround. – chr Jul 17 '19 at 8:23
  • Did you report the problem upstream? – Stefan Jul 17 '19 at 12:07
  • Yes, it's done. – chr Jul 17 '19 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.