akicho8 / string-inflection

underscore -> UPCASE -> CamelCase conversion of names
249 stars 23 forks source link

Proposed simplification #29

Open Ergus opened 4 years ago

Ergus commented 4 years ago

Hi: I have seen the code and I wanted to simplify it a little bit the user customization. If you find it is useful you are free to modify it and use in the package's code:

(defcustom tests '(string-inflection-word-p
          string-inflection-underscore-p
          string-inflection-upcase-p
          string-inflection-pascal-case-p
          string-inflection-camelcase-p
          string-inflection-kebab-case-p
          ))
(defcustom funcs [
         string-inflection-upcase-function
         string-inflection-upcase-function
         string-inflection-pascal-case-function
         string-inflection-camelcase-function
         string-inflection-kebab-case-function
         string-inflection-capital-underscore-function
         string-inflection-underscore-function
         ])

(defun string-inflection-all-cycle-function (var)
  (interactive)
  (let ((temp tests)
    (it 0))
    (while temp
      (if (funcall (car temp) var)
      (progn
        (funcall (aref funcs it) var)
        (setq temp nil))
    (setq it (1+ it))
    (setq temp (cdr temp))
    (unless temp
      (funcall (aref funcs it) var))))))

This code has 2 main advantages: 1) It is simpler to add/modify the functions in the cycle or their order 2) It is trivial to modify this code to implement a reverse order function.

akicho8 commented 4 years ago

I will tell the improvements, Thank you. 😃

Certainly simple. However, because the people of the succession of the current state of cond condition code is easy to read, I thought it may remain for now.

After, if you want to customize, it recommends assemble yourself to take advantage of the primitive function