Function: haskell-guess-module-name-from-file-name
haskell-guess-module-name-from-file-name is a natively compiled
function defined in haskell-mode.el.
Signature
(haskell-guess-module-name-from-file-name FILE-NAME)
Documentation
Guess the module name from FILE-NAME.
Based on given FILE-NAME this function tries to find path components that look like module identifiers and composes full module path using this information. For example:
/Abc/Def/Xyz.lhs => Abc.Def.Xyz
/Ab-c/Def/Xyz.lhs => Def.Xyz
src/Abc/Def/Xyz.hs => Abc.Def.Xyz
c:\src\Abc\Def\Xyz.hs => Abc.Def.Xyz
nonmodule.txt => nil
This function usually will be used with buffer-file-name(var)/buffer-file-name(fun):
(haskell-guess-module-name-from-file-name (buffer-file-name))
Source Code
;; Defined in /nix/store/9lz2mhw95f9fqxr9mnq46k3f6qz3aq83-emacs-packages-deps/share/emacs/site-lisp/elpa/haskell-mode-20260904.1042/haskell-mode.el
(defun haskell-guess-module-name-from-file-name (file-name)
"Guess the module name from FILE-NAME.
Based on given FILE-NAME this function tries to find path
components that look like module identifiers and composes full
module path using this information. For example:
/Abc/Def/Xyz.lhs => Abc.Def.Xyz
/Ab-c/Def/Xyz.lhs => Def.Xyz
src/Abc/Def/Xyz.hs => Abc.Def.Xyz
c:\\src\\Abc\\Def\\Xyz.hs => Abc.Def.Xyz
nonmodule.txt => nil
This function usually will be used with `buffer-file-name':
(haskell-guess-module-name-from-file-name (buffer-file-name))"
(let* ((file-name-sans-ext (file-name-sans-extension file-name))
(components (cl-loop for part
in (reverse (split-string file-name-sans-ext "/"))
while (let ((case-fold-search nil))
(string-match (concat "^" haskell-lexeme-modid "$") part))
collect part)))
(when components
(mapconcat 'identity (reverse components) "."))))