I write my projects in FreePascal and use opascal-mode
to write it. I'm having a problem that this mode thinks that '\'
is not a complete string, and hence all code after it is highlighted as a string.
How can I change the opascal-mode (or add a hook) in which it will not try to parse the backslash as an escape character? In FreePascal, strings do not support backslash as an escape char.
I'm using GNU Emacs 24.5.1 and this is a sample code that when run in opascal-mode, it highlights everything after the '\'
improperly:
// syntax_highlight.dpr
{$mode objfpc}{$H+}
program my_program;
uses Classes;
var newVal : char;
begin
newVal := '\'; // syntax highlight breaks here!
if newVal = '''' then begin
writeln('single quote');
end else if newVal = '\' then begin
writeln('backslash');
end;
end.
I've tried messing around with modify-syntax-entry
, but nothing I tried worked.
EDIT: this is the fixed config in ~/.emacs
after I've implemented @JeanPierre's fix
;; associate pascal files as opascal-mode
(add-to-list 'auto-mode-alist '("\\.pas$" . opascal-mode))
(let* ((pascal-files '(".pas" ".pp" ".inc" ".lpr" ".dpr"))
(pascal-regexp (concat (regexp-opt pascal-files t) "\\'")))
(add-to-list 'auto-mode-alist (cons pascal-regexp 'opascal-mode)))
;; don't escape backslashes in pascal
(add-hook 'opascal-mode-hook
(modify-syntax-entry ?\\ "."))