string-inflection icon indicating copy to clipboard operation
string-inflection copied to clipboard

Proposed simplification

Open Ergus opened this issue 5 years ago • 1 comments

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.

Ergus avatar Jun 07 '20 06:06 Ergus

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

akicho8 avatar Jun 07 '20 07:06 akicho8