haskell-indentation: identifier named `signature` breaks indentation for the rest of the declaration
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 78/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- emacs-lisp, haskell
- Ambito
- developer-experience, tooling
Direzione di ricerca
Start with haskell-indentation-peek-token and its callers, especially haskell-indentation-find-indentations, then inspect the haskell-indentation-module entry for how Backpack signatures are handled. Also review the keyword list in haskell-font-lock.el. Done means ordinary signature identifiers no longer break indentation or receive keyword highlighting in .hs files, while .hsig support remains intact.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
haskell-indentation-mode treats signature as a keyword everywhere, not only in Backpack signature files (.hsig). Any ordinary identifier named signature (a record field, a variable, a binding) aborts the indentation parse: haskell-indentation-find-indentations returns nil, and every line after it in the same top-level declaration gets no indentation candidates.
signature is a common field/variable name in code dealing with cryptography or e-signing, so this is easy to hit in a regular .hs file.
Minimal reproduction
In a .hs buffer with haskell-indentation-mode:
f = R
{ a = 1
, signature = 2
}
With point at the end of the last line, (haskell-indentation-find-indentations) returns nil, so RET/TAB on the next line doesn't indent.
Renaming the field to sig gives (0 2) as expected. The same happens for a variable:
f signature = do
g signature
→ nil (with sigx instead: (0 2 4)).
Cause
haskell-indentation-peek-token lexes signature as a keyword unconditionally:
(cond ((looking-at "\\(if\\|then\\|else\\|let\\|in\\|mdo\\|rec\\|do\\|proc\\|case\\|of\\|where\\|module\\|signature\\|deriving\\|import\\|data\\|type\\|newtype\\|class\\|instance\\)\\([^[:alnum:]'_]\\|$\\)")
(match-string-no-properties 1))
signature was presumably added alongside the ("signature" . haskell-indentation-module) entry in haskell-indentation-toplevel-list to support Backpack. But signature is only a keyword at the start of an .hsig file. Everywhere else it's an ordinary identifier, and it isn't reserved in Haskell 2010 or GHC.
Suggested fix
Only lex signature as a keyword in .hsig files, or only where a module header could appear. The workaround I'm using (advice on haskell-indentation-peek-token) does the former:
(defun haskell-indentation-signature-as-identifier (peek-token)
(if (and (looking-at "signature\\([^[:alnum:]'_]\\|$\\)")
(not (string-suffix-p ".hsig" (or buffer-file-name ""))))
'value
(funcall peek-token)))
(advice-add 'haskell-indentation-peek-token
:around #'haskell-indentation-signature-as-identifier)
With this, the examples above indent correctly, and so does a real-world module with previously broken indentation.
Related
haskell-font-lock.el also lists "signature" among the keywords, so signature identifiers are highlighted as keywords in .hs files. That's cosmetic, but it has the same root cause.
Environment
- haskell-mode 20260206.1050 (MELPA)
- GNU Emacs 30.2
- Lingua principale
- Emacs Lisp
- Stelle
- 1.4k
- Fork
- 357
- Merge medio
- 7h 50m
- PR unite (30g)
- 1
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di haskell/haskell-mode
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
haskell/haskell-mode#1889 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
haskell/haskell-mode#1522 ·
-
.hsc/CPP Can't find headers.Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
haskell/haskell-mode#1892 ·
-
Need help with haskell-modeAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
haskell/haskell-mode#1890 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
haskell/haskell-mode#1888 · 2 commenti ·
Tutte le issue di haskell/haskell-mode
Issue simili
-
area: middleware enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
rohitgollarahalli/mcpx#45 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
facebookresearch/atlas-lean#20218 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100