Skip to content

Commit 23a1844

Browse files
committed
Simplify idris-ipkg-mode.el by using idris-find-ipkg-file
1 parent f7ea8cb commit 23a1844

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

idris-ipkg-mode.el

+26-30
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ arguments."
233233
(directory-files directory full match nosort)
234234
(error nil)))
235235

236+
(defun idris-find-ipkg-file ()
237+
"Return first found ipkg file in parent directory."
238+
(car-safe (idris-find-file-upwards "ipkg")))
239+
236240
(defvar idris-ipkg-build-buffer-name "*idris-build*")
237241

238242
(defun idris-ipkg--compilation-buffer-name-function (_mode)
@@ -263,34 +267,34 @@ arguments."
263267

264268
(defun idris-ipkg-build (ipkg-file)
265269
(interactive (list
266-
(if-let ((ipkg-default (idris-find-file-upwards "ipkg")))
270+
(if-let ((ipkg-default (idris-find-ipkg-file)))
267271
(read-file-name "Package file to build: "
268-
(file-name-directory (car ipkg-default))
269-
(car ipkg-default)
272+
(file-name-directory ipkg-default)
273+
ipkg-default
270274
t
271-
(file-name-nondirectory (car ipkg-default)))
275+
(file-name-nondirectory ipkg-default))
272276
(read-file-name "Package file to build: " nil nil nil t))))
273277
(idris-ipkg-command ipkg-file 'build))
274278

275279
(defun idris-ipkg-install (ipkg-file)
276280
(interactive (list
277-
(if-let ((ipkg-default (idris-find-file-upwards "ipkg")))
281+
(if-let ((ipkg-default (idris-find-ipkg-file)))
278282
(read-file-name "Package file to install: "
279-
(file-name-directory (car ipkg-default))
280-
(car ipkg-default)
283+
(file-name-directory ipkg-default)
284+
ipkg-default
281285
t
282-
(file-name-nondirectory (car ipkg-default)))
286+
(file-name-nondirectory ipkg-default))
283287
(read-file-name "Package file to install: " nil nil nil t))))
284288
(idris-ipkg-command ipkg-file 'install))
285289

286290
(defun idris-ipkg-clean (ipkg-file)
287291
(interactive (list
288-
(if-let ((ipkg-default (idris-find-file-upwards "ipkg")))
292+
(if-let ((ipkg-default (idris-find-ipkg-file)))
289293
(read-file-name "Package file to clean: "
290-
(file-name-directory (car ipkg-default))
291-
(car ipkg-default)
294+
(file-name-directory ipkg-default)
295+
ipkg-default
292296
t
293-
(file-name-nondirectory (car ipkg-default)))
297+
(file-name-nondirectory ipkg-default))
294298
(read-file-name "Package file to clean: " nil nil nil t))))
295299
(idris-ipkg-command ipkg-file 'clean))
296300

@@ -307,14 +311,10 @@ arguments."
307311
(file-name-directory basename))))
308312

309313
(defun idris-ipkg-find-src-dir (&optional ipkg-file)
310-
(if-let ((found (or (and ipkg-file (list ipkg-file))
311-
(idris-find-file-upwards "ipkg"))))
312-
(progn
313-
(setq ipkg-file (car found))
314-
;; Now ipkg-file contains the path to the package
315-
(with-temp-buffer
316-
(insert-file-contents ipkg-file)
317-
(idris-ipkg-buffer-src-dir ipkg-file)))))
314+
(if-let ((found (or ipkg-file (idris-find-ipkg-file))))
315+
(with-temp-buffer
316+
(insert-file-contents found)
317+
(idris-ipkg-buffer-src-dir found))))
318318

319319
(defun idris-ipkg-buffer-cmdline-opts ()
320320
(save-excursion
@@ -326,14 +326,10 @@ arguments."
326326
"")))
327327

328328
(defun idris-ipkg-find-cmdline-opts (&optional ipkg-file)
329-
(if-let ((found (or (and ipkg-file (list ipkg-file))
330-
(idris-find-file-upwards "ipkg"))))
331-
(progn
332-
(setq ipkg-file (car found))
333-
;; Now ipkg-file contains the path to the package
334-
(with-temp-buffer
335-
(insert-file-contents ipkg-file)
336-
(idris-ipkg-buffer-cmdline-opts)))))
329+
(if-let ((found (or ipkg-file (idris-find-ipkg-file))))
330+
(with-temp-buffer
331+
(insert-file-contents found)
332+
(idris-ipkg-buffer-cmdline-opts))))
337333

338334
(defun idris-ipkg-flags-for-current-buffer ()
339335
"Extract the command line options field from the current .ipkg buffer."
@@ -343,7 +339,7 @@ arguments."
343339

344340
(defun idris-ipkg-pkgs-for-current-buffer ()
345341
"Find the explicit list of packages for the current .ipkg buffer."
346-
(if-let ((file (idris-find-file-upwards "ipkg")))
342+
(if-let ((file (idris-find-ipkg-file)))
347343
(with-temp-buffer
348344
(let ((pkgs nil))
349345
(cl-flet
@@ -352,7 +348,7 @@ arguments."
352348
(let ((beg (match-beginning 0))
353349
(end (match-end 0)))
354350
(push (buffer-substring-no-properties beg end) pkgs))))
355-
(insert-file-contents (car file))
351+
(insert-file-contents file)
356352
(goto-char (point-min))
357353
(when (re-search-forward "^\\s-*pkgs\\s-*=\\s-*" nil t)
358354
(cl-loop initially (get-pkg)

0 commit comments

Comments
 (0)