33; ; Copyright © 2007, 2008 Stefan Monnier
44; ; 2016 Arthur Fayzrakhmanov
55; ; 2025 August Johansson
6-
6+ ; ; URL: https://github.com/webdevred/cabal-mode
7+ ; ; Package-Version: 0.0.1
8+ ; ; Package-Requires: ((emacs "24.4"))
79; ; Author: Stefan Monnier <monnier@iro.umontreal.ca>
8-
910; ; This file is not part of GNU Emacs.
1011
1112; ; This file is free software; you can redistribute it and/or modify
2526
2627; ;; Commentary:
2728
28- ; ; Todo:
29+ ; ;; Todo:
2930
3031; ; - distinguish continued lines from indented lines.
3132; ; - indent-line-function.
5960If given DISABLED argument sets variable value to nil, otherwise to t."
6061 (setq cabal-mode-interactive-prompt-state (not disabled)))
6162
62- (defcustom haskell-hasktags-path " hasktags"
63- " Path to `hasktags' executable."
64- :group 'haskell
65- :type 'string )
66-
67- (defcustom haskell-hasktags-arguments '(" -e" " -x" )
68- " Additional arguments for `hasktags' executable.
69- By default these are:
70-
71- -e - generate ETAGS file
72- -x - generate additional information in CTAGS file."
73- :group 'haskell
74- :type '(list string))
75-
7663(defconst cabal-general-fields
7764 ; ; Extracted with (cabal-extract-fields-from-doc "general-fields")
7865 '(" name" " version" " cabal-version" " license" " license-file" " copyright"
@@ -187,8 +174,7 @@ it from list if one of the following conditions are hold:
187174 (setq-local comment-end " " )
188175 (setq-local comment-end-skip " [ \t ]*\\ (\\ s>\\ |\n \\ )" )
189176 (setq-local indent-line-function 'cabal-indent-line )
190- (setq indent-tabs-mode nil )
191- )
177+ (setq indent-tabs-mode nil ))
192178
193179(make-obsolete 'cabal-get-setting
194180 'cabal--get-field
@@ -351,10 +337,9 @@ OTHER-WINDOW use `find-file-other-window'."
351337 " help"
352338 " run" ))
353339
354- (defgroup haskell- cabal nil
340+ (defgroup cabal nil
355341 " Haskell cabal files."
356- :group 'haskell
357- )
342+ :group 'haskell )
358343
359344(defconst cabal-section-header-regexp " ^[[:alnum:]]" )
360345(defconst cabal-subsection-header-regexp " ^[ \t ]*[[:alnum:]]\\ w*:" )
@@ -397,8 +382,7 @@ Possible results are \\='section-header \\='subsection-header \\='section-data
397382(defun cabal-beginning-of-section ()
398383 " Go to the beginning of the section."
399384 (interactive )
400- (goto-char (cabal-section-beginning))
401- )
385+ (goto-char (cabal-section-beginning)))
402386
403387(defun cabal-section-end ()
404388 " Find the end of the current section."
@@ -471,23 +455,32 @@ Possible results are \\='section-header \\='subsection-header \\='section-data
471455 (current-column ))
472456 :data-indent-column (save-excursion (goto-char (match-end 0 ))
473457 (when (looking-at " \n +\\ (\\ w*\\ )" ) (goto-char (match-beginning 1 )))
474- (current-column )
475- )))))
458+ (current-column ))))))
476459
477460
478461(defun cabal-section-name (section )
462+ " Return the name of SECTION.
463+ Fetches the value associated with the :name key from the SECTION plist."
479464 (plist-get section :name ))
480465
481466(defun cabal-section-value (section )
467+ " Return the value of SECTION.
468+ Fetches the value associated with the :value key from the SECTION plist."
482469 (plist-get section :value ))
483470
484471(defun cabal-section-start (section )
472+ " Return the buffer position where SECTION begins.
473+ Fetches the value associated with the :beginning key from the SECTION plist."
485474 (plist-get section :beginning ))
486475
487476(defun cabal-section-data-start-column (section )
477+ " Return the column where the data part of SECTION start.
478+ Fetches the value associated with the :data-start-column key from the SECTION plist."
488479 (plist-get section :data-start-column ))
489480
490481(defun cabal-section-data-indent-column (section )
482+ " Return the indentation column used for data in SECTION.
483+ Fetches the value associated with the :data-indent-column key from the SECTION plist."
491484 (plist-get section :data-indent-column ))
492485
493486(defun cabal-map-component-type (component-type )
@@ -531,11 +524,10 @@ PROCESS-TYPE determines the format of the returned target."
531524 (reverse matches))))))
532525
533526(defmacro cabal-with-subsection (subsection replace &rest funs )
534- " Copy subsection data into a temporary buffer, save indentation
535- and execute FORMS.
527+ " Copy SUBSECTION data into a temporary buffer, save indentation and execute FUNS.
536528
537529If REPLACE is non-nil the subsection data is replaced with the
538- resulting buffer-content"
530+ resulting buffer-content. "
539531 (let ((section (make-symbol " section" ))
540532 (beg (make-symbol " beg" ))
541533 (end (make-symbol " end" ))
@@ -565,8 +557,8 @@ resulting buffer-content"
565557 (goto-char , beg )
566558 (insert , section-data ))))))))
567559
568- (defmacro cabal-each-line (&rest fun )
569- " Execute FORMS on each line"
560+ (defmacro cabal-each-line (&rest forms )
561+ " Execute FORMS on each line. "
570562 `(save-excursion
571563 (while (< (point ) (point-max ))
572564 ,@fun
@@ -616,8 +608,8 @@ resulting buffer-content"
616608
617609
618610(defmacro cabal-save-indentation (&rest funs )
619- " Strip indentation from each line, execute FORMS and reinstate indentation
620- so that the indentation of the FIRST LINE matches"
611+ " Strip indentation from each line, execute FUNS and reinstate indentation
612+ so that the indentation of the FIRST LINE matches. "
621613 (let ((old-l1-indent (make-symbol " new-l1-indent" ))
622614 (new-l1-indent (make-symbol " old-l1-indent" )))
623615 `(let ( (, old-l1-indent (save-excursion
@@ -753,6 +745,12 @@ Respect the comma style."
753745 (cabal-remove-mark)))
754746
755747(defun cabal-sort-lines-depends-compare (key1 key2 )
748+ " Compare two dependency keys, KEY1 and KEY2, for sorting.
749+ Return t if KEY1 should come before KEY2.
750+
751+ Each key is a cons cell (START . END) representing a region in the buffer.
752+ The function extracts the corresponding text strings and sorts them
753+ lexicographically, but ensures that the package \" base\" always comes first."
756754 (let* ((key1str (buffer-substring (car key1) (cdr key1)))
757755 (key2str (buffer-substring (car key2) (cdr key2)))
758756 (base-regex " ^[ \t ]*base\\ ($\\ |[^[:alnum:]-]\\ )" ))
@@ -775,11 +773,10 @@ Respect the comma style."
775773 (sort-subr nil 'forward-line 'end-of-line
776774 'cabal-sort-lines-key-fun
777775 'end-of-line
778- compare-lines
779- ))))))
776+ compare-lines))))))
780777
781778(defun cabal-subsection-beginning ()
782- " find the beginning of the current subsection."
779+ " Find the beginning of the current subsection."
783780 (save-excursion
784781 (while (and (not (bobp ))
785782 (not (cabal-header-p)))
@@ -788,12 +785,12 @@ Respect the comma style."
788785 (point )))
789786
790787(defun cabal-beginning-of-subsection ()
791- " go to the beginning of the current subsection."
788+ " Go to the beginning of the current subsection."
792789 (interactive )
793790 (goto-char (cabal-subsection-beginning)))
794791
795792(defun cabal-next-subsection ()
796- " go to the next subsection."
793+ " Go to the next subsection."
797794 (interactive )
798795 (if (cabal-header-p) (forward-line ))
799796 (while (and (not (eobp ))
@@ -802,18 +799,17 @@ Respect the comma style."
802799 (cabal-forward-to-line-entry))
803800
804801(defun cabal-previous-subsection ()
805- " go to the previous subsection, "
802+ " Go to the previous subsection. "
806803 (interactive )
807804 (if (cabal-header-p) (forward-line -1 ))
808805 (while (and (not (bobp ))
809806 (not (cabal-header-p)))
810807 (forward-line -1 ))
811- (cabal-forward-to-line-entry)
812- )
808+ (cabal-forward-to-line-entry))
813809
814810
815811(defun cabal-find-subsection-by (section pred )
816- " Find subsection with name NAME "
812+ " Find SECTION where PRED is t. "
817813 (save-excursion
818814 (when section (goto-char (cabal-section-start section)))
819815 (let* ((end (if section (cabal-section-end) (point-max )))
@@ -827,7 +823,7 @@ Respect the comma style."
827823 found)))
828824
829825(defun cabal-find-subsection (section name )
830- " Find subsection with name NAME"
826+ " Find SECTION with name NAME. "
831827 (let ((downcase-name (downcase name)))
832828 (cabal-find-subsection-by
833829 section
@@ -845,7 +841,7 @@ Respect the comma style."
845841 (cabal-goto-subsection " exposed-modules" ))
846842
847843(defun cabal-subsection-entry-list (section name )
848- " Get the data of a subsection as a list"
844+ " Get the data of a SECTION named NAME as a list. "
849845 (let ((subsection (cabal-find-subsection section name)))
850846 (when subsection
851847 (cabal-with-subsection
@@ -865,7 +861,7 @@ Respect the comma style."
865861
866862
867863(defun cabal-mark ()
868- " Mark the current position with the text property cabal-marker"
864+ " Mark the current position with the text property cabal-marker. "
869865 (cabal-remove-mark)
870866 (put-text-property (line-beginning-position ) (line-end-position )
871867 'cabal-marker 'marked-line )
@@ -874,14 +870,13 @@ Respect the comma style."
874870
875871
876872(defun cabal-goto-mark ()
877- " Go to marked line"
873+ " Go to marked line. "
878874 (let ((marked-pos (text-property-any (point-min ) (point-max )
879875 'cabal-marker
880876 'marked ))
881877 (marked-line (text-property-any (point-min ) (point-max )
882878 'cabal-marker
883- 'marked-line ) )
884- )
879+ 'marked-line ) ))
885880 (cond (marked-pos (goto-char marked-pos))
886881 (marked-line (goto-char marked-line)))))
887882
@@ -912,19 +907,18 @@ resulting buffer-content. Unmark line at the end."
912907 (concat (replace-regexp-in-string " [.]" " /" module ) " .hs" ))
913908
914909(defconst cabal-module-sections '(" exposed-modules" " other-modules" )
915- " List of sections that contain module names"
916- )
910+ " List of sections that contain module names." )
917911
918912(defconst cabal-file-sections
919913 '(" main-is" " c-sources" " data-files" " extra-source-files"
920914 " extra-doc-files" " extra-tmp-files" )
921- " List of subsections that contain filenames"
922- )
915+ " List of subsections that contain filenames." )
923916
924917(defconst cabal-source-bearing-sections
925918 '(" library" " executable" " test-suite" " benchmark" ))
926919
927920(defun cabal-source-section-p (section )
921+ " Wheter given SECTION is a source section, so not a common section."
928922 (not (not (member (downcase (cabal-section-name section))
929923 cabal-source-bearing-sections))))
930924
@@ -936,9 +930,7 @@ dot (.) in the module name with a forward slash (/) and appending \".hs\"
936930
937931Example: Foo.Bar.Quux ==> Foo/Bar/Quux.hs
938932
939- Source names from main-is and c-sources sections are left untouched
940-
941- "
933+ Source names from main-is and c-sources sections are left untouched."
942934 (let ((entry (cabal-get-line-content))
943935 (subsection (downcase (cabal-section-name
944936 (cabal-subsection)))))
@@ -947,9 +939,8 @@ Source names from main-is and c-sources sections are left untouched
947939 ((member subsection cabal-file-sections) entry))))
948940
949941(defun cabal-join-paths (&rest args )
950- " Crude hack to replace f-join"
951- (mapconcat 'identity args " /" )
952- )
942+ " Crude hack to replace f-join."
943+ (mapconcat 'identity args " /" ))
953944
954945(defun cabal-find-or-create-source-file ()
955946 " Open the source file this line refers to."
@@ -986,6 +977,9 @@ Source names from main-is and c-sources sections are left untouched
986977
987978
988979(defun cabal-find-section-type (type &optional wrap )
980+ " Find a section section-type TYPE.
981+
982+ Restart WRAP is t."
989983 (save-excursion
990984 (cabal-next-section)
991985 (while
@@ -1041,14 +1035,14 @@ Source names from main-is and c-sources sections are left untouched
10411035 (cabal-section-data-start-column (cabal-subsection))))))
10421036
10431037(defun cabal-forward-to-line-entry ()
1044- " go forward to the beginning of the line entry (but never move backwards)"
1038+ " Go forward to the beginning of the line entry (but never move backwards). "
10451039 (let ((col (cabal-line-entry-column)))
10461040 (when (and col (< (current-column ) col))
10471041 (beginning-of-line )
10481042 (forward-char col))))
10491043
10501044(defun cabal-indent-line ()
1051- " Indent current line according to subsection"
1045+ " Indent current line according to subsection. "
10521046 (interactive )
10531047 (cl-case (cabal-classify-line)
10541048 (section-data
@@ -1076,7 +1070,7 @@ Source names from main-is and c-sources sections are left untouched
10761070 (nreverse results))))
10771071
10781072(defun cabal-section-add-build-dependency (dependency &optional sort sec )
1079- " Add a build dependency to the build-depends section"
1073+ " Add a build DEPENDENCY to the build-depends section. "
10801074 (let* ((section (or sec (cabal-section)))
10811075 (subsection (and section
10821076 (cabal-find-subsection section " build-depends" ))))
0 commit comments