0
votes

When I am on matlab mode on Emacs (I use Aquamacs), RET adds a line below but doesn't jump to that line (i.e., it acts as C-o is supposed to). This behaviour doesn't happen in other modes were RET behaves as expected, i.e. adds a line below and moves the cursor to it.

When I press RET in matlab mode I get this message

wrong type argument "wholenump -1"

I have no idea where this is coming from. I have reinstalled all my matlab related files to .emacs, I have looked through .emacs, Preferences.el, customizations.el, and did and looked through all the options of the customise-apropos 'matlab'. I haven't found anything that would give me a clue. I don't know any lisp and can be considered a noob even though I have been using emacs for a few years. Can someone help me trace the problem?

I am using Aquatics 3.2 GNU Emacs 24.4.51.2. I was originally running a matlab-mode of unknown provenance from several years back, but while attempting to troubleshoot this problem, I upgraded to the latest version from https://github.com/pronobis/matlab-mode by running the update script. This did not solve the problem for me.

As discovered in this SO chat, something is setting fill-column to the value -1:

fill-column is a variable defined in `C source code'. 
Its value is -1 
Original value was 70 
Local in buffer funfzero.m; global value is the same.

Manually setting it back to 70 temporarily fixes the problem for me. But what is causing it to be set to a bogus value like that? How can I find out where this is being set?

Here is the debug output

Debugger entered--Lisp error: (wrong-type-argument wholenump -1)
  move-to-column(-1)
  (save-excursion (move-to-column fill-column) (if (not (bobp)) (forward-char -1)) (if (matlab-cursor-in-string (quote incomplete)) 4 3))
  (if matlab-fill-count-ellipsis-flag (save-excursion (move-to-column fill-column) (if (not (bobp)) (forward-char -1)) (if (matlab-cursor-in-string (quote incomplete)) 4 3)) 0)
  (- fill-column (if matlab-fill-count-ellipsis-flag (save-excursion (move-to-column fill-column) (if (not (bobp)) (forward-char -1)) (if (matlab-cursor-in-string (quote incomplete)) 4 3)) 0))
  (let ((fill-prefix fill-prefix) (fill-column (- fill-column (if matlab-fill-count-ellipsis-flag (save-excursion (move-to-column fill-column) (if (not ...) (forward-char -1)) (if (matlab-cursor-in-string ...) 4 3)) 0)))) (if (> (current-column) fill-column) (cond ((matlab-ltype-comm-ignore) nil) ((or (matlab-ltype-comm) (and (save-excursion (move-to-column fill-column) (matlab-cursor-in-comment)) (matlab-lattr-comm))) (matlab-set-comm-fill-prefix) (do-auto-fill) (matlab-reset-fill-prefix)) ((and (matlab-ltype-code) (not (matlab-lattr-cont)) matlab-fill-code) (let ((m (make-marker))) (move-marker m (point)) (set-marker-insertion-type m t) (if (not (matlab-find-convenient-line-break)) nil (if (not ...) (progn ... ... ...) (if matlab-fill-strings-flag ...))) (goto-char m))))))
  matlab-auto-fill()
  self-insert-command(1)
  newline()
  matlab-plain-ret()
  funcall(matlab-plain-ret)
  matlab-return()
  call-interactively(matlab-return nil nil)
  command-execute(matlab-return)
2

2 Answers

1
votes

While this may not get to the root of whatever is causing fill-column getting set to -1, a simple workaround would be to add a call to set-fill-column to the matlab-mode-hook:

(add-hook 'matlab-mode-hook
          (lambda ()
            (set-fill-column 70)))

By adding this to init.el, fill-column will be automatically set to 70 upon entering matlab-mode.

1
votes

has this always been this way?

From your debugger log, it looks like matlab-mode binds RET to its own matlab-return, for purposes that looks like auto-pretty-indent.

fill-column is set in that code. In the (let ...) line.

So, it looks like, it's a logical error of the code.

One easy fix is simply bind newline to RET, as in

(defun my-matlab-mode-stuff ()
  (local-set-key (kbd "RET") 'newline))
(add-hook 'matlab-mode-hook 'my-matlab-mode-stuff)

you might change the 'newline to 'matlab-plain-ret, as that seems to be its means to just insert return.