105105 " List of Cabal buffers." )
106106
107107(defun haskell-cabal-buffers-clean (&optional buffer )
108+ " Refresh list of known cabal buffers.
109+
110+ Check each buffer in variable `haskell-cabal-buffers' and remove
111+ it from list if one of the following conditions are hold:
112+ + buffer is killed;
113+ + buffer's mode is not derived from `haskell-cabal-mode' ;
114+ + buffer is a BUFFER (if given)."
108115 (let ((bufs ()))
109116 (dolist (buf haskell-cabal-buffers)
110- (if (and (buffer-live-p buf) (not (eq buf buffer))
117+ (if (and (buffer-live-p buf)
118+ (not (eq buf buffer))
111119 (with-current-buffer buf (derived-mode-p 'haskell-cabal-mode )))
112120 (push buf bufs)))
113121 (setq haskell-cabal-buffers bufs)))
114122
115123(defun haskell-cabal-unregister-buffer ()
124+ " Exclude current buffer from global list of known cabal buffers."
116125 (haskell-cabal-buffers-clean (current-buffer )))
117126
118127;;;### autoload
150159 (setq indent-tabs-mode nil )
151160 )
152161
153- (defun haskell-cabal-get-setting (name )
162+ (defun haskell-cabal--get-field (name )
163+ " Try to read value of field with NAME from current buffer."
154164 (save-excursion
155165 (let ((case-fold-search t ))
156166 (goto-char (point-min ))
174184 val)))))
175185
176186;;;### autoload
177- (defun haskell-cabal-guess-setting (name )
178- " Guess the specified setting of this project.
187+ (defun haskell-cabal-get-field (name )
188+ " Read the value of field with NAME from project's cabal file .
179189If there is no valid .cabal file to get the setting from (or
180190there is no corresponding setting with that name in the .cabal
181191file), then this function returns nil."
@@ -185,7 +195,7 @@ file), then this function returns nil."
185195 (when (and cabal-file (file-readable-p cabal-file))
186196 (with-temp-buffer
187197 (insert-file-contents cabal-file)
188- (haskell-cabal-get-setting name))))))
198+ (haskell-cabal-- get-field name))))))
189199
190200;;;### autoload
191201(defun haskell-cabal-get-dir (&optional use-defaults )
@@ -442,23 +452,24 @@ OTHER-WINDOW use `find-file-other-window'."
442452 (let ((cabal-file (haskell-cabal-find-file)))
443453 (when (and cabal-file (file-readable-p cabal-file))
444454 (with-temp-buffer
445- (insert-file-contents cabal-file)
446- (haskell-cabal-mode )
447- (goto-char (point-min ))
448- (let ((matches)
449- (projectName (haskell-cabal-get-setting " name" )))
450- (haskell-cabal-next-section)
451- (while (not (eobp ))
452- (if (haskell-cabal-source-section-p (haskell-cabal-section))
453- (let ((val (car (split-string
454- (haskell-cabal-section-value (haskell-cabal-section))))))
455- (if (or (string= val " " )
456- (string= val " {" )
457- (not val))
458- (push projectName matches)
459- (push val matches))))
460- (haskell-cabal-next-section))
461- (reverse matches))))))
455+ (insert-file-contents cabal-file)
456+ (haskell-cabal-mode )
457+ (goto-char (point-min ))
458+ (let ((matches)
459+ (projectName (haskell-cabal--get-field " name" )))
460+ (haskell-cabal-next-section)
461+ (while (not (eobp ))
462+ (if (haskell-cabal-source-section-p (haskell-cabal-section))
463+ (let ((val (car (split-string
464+ (haskell-cabal-section-value
465+ (haskell-cabal-section))))))
466+ (if (or (string= val " " )
467+ (string= val " {" )
468+ (not val))
469+ (push projectName matches)
470+ (push val matches))))
471+ (haskell-cabal-next-section))
472+ (reverse matches))))))
462473
463474(defmacro haskell-cabal-with-subsection (subsection replace &rest funs )
464475 " Copy subsection data into a temporary buffer, save indentation
@@ -1036,7 +1047,7 @@ source-section."
10361047 (concat package
10371048 (if version (concat " >= " version) " " ))))))
10381049 (haskell-cabal-add-build-dependency entry sort silent)
1039- (when (or silent (y-or-n-p " Save cabal file?" ))
1050+ (when (or silent (y-or-n-p " Save cabal file? " ))
10401051 (save-buffer ))))
10411052 ; ; unwind
10421053 (haskell-mode-toggle-interactive-prompt-state t )))
0 commit comments