~brown121407/ml

f.scm: Add replace-extension. v1 APPLIED

Xinglu Chen: 4
 Add replace-extension.
 Add replace-extension.
 None
 None

 4 files changed, 68 insertions(+), 3 deletions(-)
Also, what naming convention should we use?  f.el seems to prefer
shorter names like "f-no-ext" rather than "f-no-extension".  I guess we
don't need the "f-" prefix since users can import the module with their
preferred prefix anyway.



          
          
          
        
      

      
      
      
      

      
      
        
          






Sorry for the terrible formatting, I'm on my phone.

2 Mar 2021 22:56:54 Xinglu Chen <public@yoctocell.xyz>:
Next
Hello again,

Xinglu Chen writes:
Next
I ended up not using `extension` in the definition of
`replace-extension` so it gets a separate commit.

Hidden files should now work as expected and `extension` will
return an empty string if there is no extension to be found.

Xinglu Chen (2):
  Add replace-extension.
  Add extension.

 f.scm | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)


base-commit: da553c5fcb9c3865a5e3a7506a02bb9314bb572
Oops, `no-ext` should have been `file-no-extension`, I was playing
around in the REPL earlier so `no-ext` must have been some function I
renamed.  My bad.

Defining `file-no-extension` using `replace-extension` would then have
caused an infinite loop.
Next
3 Mar 2021 14:39:54 Xinglu Chen <public@yoctocell.xyz>:
Next
Thank you! Applied.
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~brown121407/ml/patches/20734/mbox | git am -3
Learn more about email & git

[PATCH f.scm] Add replace-extension. Export this patch

* f.scm (replace-extension): New procedure.
---
 f.scm | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/f.scm b/f.scm
index f699d91..dcdbed8 100644
--- a/f.scm
+++ b/f.scm
@@ -17,6 +17,7 @@
  #:use-module ((ice-9 binary-ports) #:prefix i9:)
  #:use-module ((ice-9 textual-ports) #:prefix i9:)
  #:use-module (srfi srfi-1)
  #:use-module (ice-9 regex)
  #:use-module ((f ports) #:prefix p:)
  #:use-module ((f re-exports) #:prefix re:)
  #:export (read-bytes
@@ -31,7 +32,8 @@
            mkdir
            delete
            traverse
            copy)
            copy
            replace-extension)
  #:re-export (chown
               chmod
               (rename-file . move)
@@ -169,3 +171,11 @@ appending a #t at the end."))))))
                (throw 'f.scm "Can't copy: directory not empty. Try with making the call recursive
by appending a #t at the end."))))
      (copy-file src dest)))

(define (replace-extension file ext)
  "Replace file extension in FILE with EXT.
EXT can include or exclude the beginning \".\"."
  (let ((ext (if (string-match "^\\..+" ext)
                 ext
                 (string-append "." ext))))
    (regexp-substitute #f (string-match "(.*)\\.[a-zA-Z0-9]+" file) 1 ext)))

base-commit: da553c5fcb9c3865a5e3a7506a02bb9314bb572d
-- 
2.30.0
Hi,

Xinglu Chen writes:

[PATCH v2] Add replace-extension. Export this patch

* f.scm (replace-extension): New procedure.
(file-extension): Likewise.
(file-no-extension): Likewise.
---
Changes since v1:
- Make `replace-extension` more liberal instead of giving exceptions.
- Add `file-extension` and `file-no-extension` which are useful on
  their own.

 f.scm | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/f.scm b/f.scm
index f699d91..9e845d1 100644
--- a/f.scm
+++ b/f.scm
@@ -17,6 +17,7 @@
  #:use-module ((ice-9 binary-ports) #:prefix i9:)
  #:use-module ((ice-9 textual-ports) #:prefix i9:)
  #:use-module (srfi srfi-1)
  #:use-module (ice-9 regex)
  #:use-module ((f ports) #:prefix p:)
  #:use-module ((f re-exports) #:prefix re:)
  #:export (read-bytes
@@ -31,7 +32,10 @@
            mkdir
            delete
            traverse
            copy)
            copy
            file-extension
            file-no-extension
            replace-extension)
  #:re-export (chown
               chmod
               (rename-file . move)
@@ -169,3 +173,26 @@ appending a #t at the end."))))))
                (throw 'f.scm "Can't copy: directory not empty. Try with making the call recursive
by appending a #t at the end."))))
      (copy-file src dest)))

(define (file-extension file)
  "Return extension for FILE."
  (let ((ext (string-match ".*\\.(.*)" file)))
    (cond
     ((string-null? file) #f)
     (ext (regexp-substitute #f ext 1))
     (else file))))

(define (file-no-extension file)
  "Return FILE path without extension."
  (let ((without-ext (string-match "(.*)\\..*" file)))
    (if without-ext
        (regexp-substitute #f without-ext 1)
        file)))

(define (replace-extension file ext)
  "Replace file extension in FILE with EXT.
EXT can include or exclude the beginning \".\"."
  (let ((ext (if (file-extension ext)
                 (string-append "." (file-extension ext))
                 ext)))
    (string-append (no-ext file) ext)))
base-commit: da553c5fcb9c3865a5e3a7506a02bb9314bb572d
-- 
2.30.0
Hello again,

Xinglu Chen writes:
I ended up not using `extension` in the definition of
`replace-extension` so it gets a separate commit.

Hidden files should now work as expected and `extension` will
return an empty string if there is no extension to be found.

Xinglu Chen (2):
  Add replace-extension.
  Add extension.

 f.scm | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)


base-commit: da553c5fcb9c3865a5e3a7506a02bb9314bb572

[f.scm PATCH v3 1/2] Add replace-extension. Export this patch

* f.scm (no-extension): New procedure.
(replace-extension): Likewise.
---
 f.scm | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/f.scm b/f.scm
index f699d91..ffac4df 100644
--- a/f.scm
+++ b/f.scm
@@ -17,6 +17,7 @@
  #:use-module ((ice-9 binary-ports) #:prefix i9:)
  #:use-module ((ice-9 textual-ports) #:prefix i9:)
  #:use-module (srfi srfi-1)
  #:use-module (ice-9 regex)
  #:use-module ((f ports) #:prefix p:)
  #:use-module ((f re-exports) #:prefix re:)
  #:export (read-bytes
@@ -31,7 +32,9 @@
            mkdir
            delete
            traverse
            copy)
            copy
            no-extension
            replace-extension)
  #:re-export (chown
               chmod
               (rename-file . move)
@@ -169,3 +172,19 @@ appending a #t at the end."))))))
                (throw 'f.scm "Can't copy: directory not empty. Try with making the call recursive
by appending a #t at the end."))))
      (copy-file src dest)))

(define (no-extension file)
  "Return FILE path without extension."
  (let ((without-ext (string-match "(.+)\\..*" (basename file))))
    (if without-ext
        (regexp-substitute #f without-ext 1)
        file)))

(define (replace-extension file ext)
  "Replace file extension in FILE with EXT.
EXT can include or exclude the beginning \".\"."
  (let ((ext (cond
              ((string-null? ext) "")
              ((string-match "^\\..+" ext) ext)
              (else (string-append "." ext)))))
    (string-append (no-extension file) ext)))
-- 
2.30.0

[f.scm PATCH v3 2/2] Add extension. Export this patch

* f.scm (extension): New procedure.
---
 f.scm | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/f.scm b/f.scm
index ffac4df..2f9cb83 100644
--- a/f.scm
+++ b/f.scm
@@ -33,6 +33,7 @@
            delete
            traverse
            copy
            extension
            no-extension
            replace-extension)
  #:re-export (chown
@@ -173,6 +174,14 @@ appending a #t at the end."))))))
by appending a #t at the end."))))
      (copy-file src dest)))

(define (extension file)
  "Return extension for FILE."
  (let ((ext (string-match ".+\\.(.*)" (basename file))))
    (cond
     ((string-null? file) #f)
     (ext (regexp-substitute #f ext 1))
     (else ""))))

(define (no-extension file)
  "Return FILE path without extension."
  (let ((without-ext (string-match "(.+)\\..*" (basename file))))
-- 
2.30.0
Thank you! Applied.