Subject: Re: bug#32766: Wrong syntax colors with backslash in a string (F90 mode)

From: Lars Ingebrigtsen <[email-masked]>
Date: Tue, 02 Feb 2021 16:25:27 +0100

Angelo Graziosi <[email-masked]> writes:

>   program foo
>     integer, parameter :: FOO = ichar('\')
>     integer, parameter :: BAR = 10
>   end program foo

This behaviour is still present in Emacs 28.

f90-mode.el has the following:

    ;; I think that the f95 standard leaves the behavior of \
    ;; unspecified, but that f2k will require it to be non-special.
    ;; Use `f90-backslash-not-special' to change.

and indeed:

(defun f90-backslash-not-special (&optional all)
  "Make the backslash character (\\) be non-special in the current buffer.
With optional argument ALL, change the default for all present
and future F90 buffers.  F90 mode normally treats backslash as an
escape character."
  (or (derived-mode-p 'f90-mode)
      (user-error "This function should only be used in F90 buffers"))
  (when (equal (char-syntax ?\\ ) ?\\ )
    (or all (set-syntax-table (copy-syntax-table (syntax-table))))
    (modify-syntax-entry ?\\ ".")))

Executing this will make the snippet be fontified as the bug reporter
expects.

But I don't really know F90 any more -- would it make sense to flip the
defaults now and make \ non-special?  If that happened 21 years ago i
F2K, then perhaps it's time?

Adding Glenn to the CCs, since this was the commit that introduced the
-not-special functions:

commit 784d007b5033cb555482c9a50fbdaf5a10fa8ffa
Author:     Glenn Morris <[email-masked]>
AuthorDate: Thu Nov 25 00:46:42 2004 +0000

    (f90-smart-end, f90-previous-statement, f90-beginning-of-block): Doc fix.
    (f90-calculate-indent): Handle un-named PROGRAM blocks.
    (f90-end-of-block): Doc fix.  Make check of outermost block
    conditional on value of `f90-smart-end'.
    (f90-block-match): Hack to deal with un-named PROGRAM blocks.
    Handle case where END-BLOCK is nil.
    (f90-match-end): Handle un-named PROGRAM blocks.
    (f90-backslash-not-special): New function.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no