Skip to content

Commit

Permalink
refine if-version%, = to char-equal
Browse files Browse the repository at this point in the history
  • Loading branch information
junjiemars committed Feb 10, 2025
1 parent 7443e33 commit b758506
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
6 changes: 3 additions & 3 deletions config/fn.el
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,15 @@ If optional UNIQUELY is non-nil then push uniquely."
(let ((i 0) (l (length str)))
(catch 'br
(while (< i l)
(and (= chr (aref str i)) (throw 'br i))
(and (char-equal chr (aref str i)) (throw 'br i))
(setq i (1+ i))))))

(defun strrchr (str chr)
"Return the index of the located CHR of STR from right side."
(let* ((l (length str)) (i (1- l)))
(catch 'br
(while (>= i 0)
(and (= chr (aref str i)) (throw 'br i))
(and (char-equal chr (aref str i)) (throw 'br i))
(setq i (1- i))))))

(defun string-trim> (s &optional rr)
Expand Down Expand Up @@ -487,7 +487,7 @@ Return the name of FILE when successed otherwise nil."
(defun directory-name-p (name)
"Return t if NAME ends with a directory separator character."
(let ((len (length name)))
(and (> len 0) (= ?/ (aref name (1- len)))))))
(and (> len 0) (char-equal ?/ (aref name (1- len)))))))

(defun posix-path (path)
"Transpose PATH to posix path."
Expand Down
15 changes: 8 additions & 7 deletions init.el
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,15 @@
"If (CMP VERSION \\=`+emacs-version+\\=') yield non-nil, do THEN,
else do ELSE..."
(declare (indent 3))
`(if% (,cmp ,version +emacs-version+)
,then
,@else))
(if (funcall `,cmp `,version +emacs-version+)
`,then
`(progn% ,@else)))

(defmacro when-version% (cmp version &rest body)
"When (CMP VERSION \\=`+emacs-version+\\=') yield non-nil, do BODY."
(declare (indent 2))
`(if-version% ,cmp ,version (progn% ,@body)))
(when (funcall `,cmp `,version +emacs-version+)
`(progn% ,@body)))

(defmacro v-name ()
"Return the versioned name."
Expand All @@ -97,8 +98,8 @@ else do ELSE..."
(catch 'br
(while (>= i 0)
(let ((c (aref -fnse-f1- i)))
(cond ((= ?/ c) (throw 'br l))
((= ?. c) (throw 'br i))
(cond ((char-equal ?/ c) (throw 'br l))
((char-equal ?. c) (throw 'br i))
(t (setq i (1- i))))))))))))

(defmacro mkdir* (file)
Expand All @@ -107,7 +108,7 @@ else do ELSE..."
(dir -md-f1-) (i (1- (length dir))) (ds nil))
(catch 'br
(while (> i 0)
(when (= ?/ (aref dir i))
(when (char-equal ?/ (aref dir i))
(let ((s (substring-no-properties dir 0 (1+ i))))
(if (file-exists-p s)
(throw 'br t)
Expand Down

0 comments on commit b758506

Please sign in to comment.