From 126db8c6f350e71e5814f93a8bc0a1bbde8320fd Mon Sep 17 00:00:00 2001 From: Andreas Gerler Date: Sun, 22 Dec 2024 13:19:25 +0100 Subject: [PATCH] update string-inflection Signed-off-by: Andreas Gerler --- .../string-inflection-pkg.el | 2 - .../string-inflection-autoloads.el | 59 +++-- .../string-inflection-pkg.el | 10 + .../string-inflection.el | 209 +++++++++--------- elpa/string-inflection-readme.txt | 58 ----- 5 files changed, 142 insertions(+), 196 deletions(-) delete mode 100644 elpa/string-inflection-20220910.1306/string-inflection-pkg.el rename elpa/{string-inflection-20220910.1306 => string-inflection-20240816.523}/string-inflection-autoloads.el (63%) create mode 100644 elpa/string-inflection-20240816.523/string-inflection-pkg.el rename elpa/{string-inflection-20220910.1306 => string-inflection-20240816.523}/string-inflection.el (65%) delete mode 100644 elpa/string-inflection-readme.txt diff --git a/elpa/string-inflection-20220910.1306/string-inflection-pkg.el b/elpa/string-inflection-20220910.1306/string-inflection-pkg.el deleted file mode 100644 index bc44cdaf..00000000 --- a/elpa/string-inflection-20220910.1306/string-inflection-pkg.el +++ /dev/null @@ -1,2 +0,0 @@ -;;; Generated package description from string-inflection.el -*- no-byte-compile: t -*- -(define-package "string-inflection" "20220910.1306" "underscore -> UPCASE -> CamelCase -> lowerCamelCase conversion of names" 'nil :commit "50ad54970b3cc79b6b83979bde9889ad9a9e1a9c" :authors '(("akicho8" . "akicho8@gmail.com")) :maintainers '(("akicho8" . "akicho8@gmail.com")) :maintainer '("akicho8" . "akicho8@gmail.com") :keywords '("elisp")) diff --git a/elpa/string-inflection-20220910.1306/string-inflection-autoloads.el b/elpa/string-inflection-20240816.523/string-inflection-autoloads.el similarity index 63% rename from elpa/string-inflection-20220910.1306/string-inflection-autoloads.el rename to elpa/string-inflection-20240816.523/string-inflection-autoloads.el index d17357a9..21ffe8b8 100644 --- a/elpa/string-inflection-20220910.1306/string-inflection-autoloads.el +++ b/elpa/string-inflection-20240816.523/string-inflection-autoloads.el @@ -1,59 +1,52 @@ -;;; string-inflection-autoloads.el --- automatically extracted autoloads -*- lexical-binding: t -*- -;; +;;; string-inflection-autoloads.el --- automatically extracted autoloads (do not edit) -*- lexical-binding: t -*- +;; Generated by the `loaddefs-generate' function. + +;; This file is part of GNU Emacs. + ;;; Code: -(add-to-list 'load-path (directory-file-name - (or (file-name-directory #$) (car load-path)))) +(add-to-list 'load-path (or (and load-file-name (directory-file-name (file-name-directory load-file-name))) (car load-path))) + -;;;### (autoloads nil "string-inflection" "string-inflection.el" -;;;;;; (0 0 0 0)) ;;; Generated autoloads from string-inflection.el (autoload 'string-inflection-ruby-style-cycle "string-inflection" "\ -foo_bar => FOO_BAR => FooBar => foo_bar" t nil) - +foo_bar => FOO_BAR => FooBar => foo_bar" t) (autoload 'string-inflection-elixir-style-cycle "string-inflection" "\ -foo_bar => FooBar => foo_bar" t nil) - +foo_bar => FooBar => foo_bar" t) (autoload 'string-inflection-python-style-cycle "string-inflection" "\ -foo_bar => FOO_BAR => FooBar => foo_bar" t nil) - +foo_bar => FOO_BAR => FooBar => foo_bar" t) (autoload 'string-inflection-java-style-cycle "string-inflection" "\ -fooBar => FOO_BAR => FooBar => fooBar" t nil) - +fooBar => FOO_BAR => FooBar => fooBar" t) (autoload 'string-inflection-all-cycle "string-inflection" "\ -foo_bar => FOO_BAR => FooBar => fooBar => foo-bar => Foo_Bar => foo_bar" t nil) - +foo_bar => FOO_BAR => FooBar => fooBar => foo-bar => Foo_Bar => foo_bar" t) (autoload 'string-inflection-toggle "string-inflection" "\ -toggle foo_bar <=> FooBar" t nil) - +toggle foo_bar <=> FooBar" t) (autoload 'string-inflection-camelcase "string-inflection" "\ -FooBar format" t nil) - +FooBar format" t) (autoload 'string-inflection-lower-camelcase "string-inflection" "\ -fooBar format" t nil) - +fooBar format" t) (autoload 'string-inflection-underscore "string-inflection" "\ -foo_bar format" t nil) - +foo_bar format" t) (autoload 'string-inflection-capital-underscore "string-inflection" "\ -Foo_Bar format" t nil) - +Foo_Bar format" t) (autoload 'string-inflection-upcase "string-inflection" "\ -FOO_BAR format" t nil) - +FOO_BAR format" t) (autoload 'string-inflection-kebab-case "string-inflection" "\ -foo-bar format" t nil) - +foo-bar format" t) (register-definition-prefixes "string-inflection" '("string-inflection-")) - -;;;*** +;;; End of scraped data + +(provide 'string-inflection-autoloads) + ;; Local Variables: ;; version-control: never ;; no-byte-compile: t ;; no-update-autoloads: t -;; coding: utf-8 +;; no-native-compile: t +;; coding: utf-8-emacs-unix ;; End: + ;;; string-inflection-autoloads.el ends here diff --git a/elpa/string-inflection-20240816.523/string-inflection-pkg.el b/elpa/string-inflection-20240816.523/string-inflection-pkg.el new file mode 100644 index 00000000..b9b66866 --- /dev/null +++ b/elpa/string-inflection-20240816.523/string-inflection-pkg.el @@ -0,0 +1,10 @@ +;; -*- no-byte-compile: t; lexical-binding: nil -*- +(define-package "string-inflection" "20240816.523" + "Underscore -> UPCASE -> CamelCase -> lowerCamelCase conversion of names." + () + :url "https://github.com/akicho8/string-inflection" + :commit "4cc92e1ecd3d165b55235b51ae65ac09a0364958" + :revdesc "4cc92e1ecd3d" + :keywords '("elisp") + :authors '(("akicho8" . "akicho8@gmail.com")) + :maintainers '(("akicho8" . "akicho8@gmail.com"))) diff --git a/elpa/string-inflection-20220910.1306/string-inflection.el b/elpa/string-inflection-20240816.523/string-inflection.el similarity index 65% rename from elpa/string-inflection-20220910.1306/string-inflection.el rename to elpa/string-inflection-20240816.523/string-inflection.el index 90c9dd26..c48a166f 100644 --- a/elpa/string-inflection-20220910.1306/string-inflection.el +++ b/elpa/string-inflection-20240816.523/string-inflection.el @@ -1,12 +1,11 @@ ;;; string-inflection.el --- underscore -> UPCASE -> CamelCase -> lowerCamelCase conversion of names -*- lexical-binding: t -*- -;; Copyright (C) 2004,2014,2016,2017,2018,2020,2021 Free Software Foundation, Inc. +;; Copyright (C) 2004,2014,2016,2017,2018,2020,2021,2022,2023,2024 Free Software Foundation, Inc. ;; Author: akicho8 ;; Keywords: elisp -;; Package-Version: 20220910.1306 -;; Package-Commit: 50ad54970b3cc79b6b83979bde9889ad9a9e1a9c -;; Version: 1.0.16 +;; Package-Version: 20240816.523 +;; Package-Revision: 4cc92e1ecd3d ;; This file is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by @@ -89,8 +88,16 @@ ;; '(lambda () ;; (local-set-key (kbd "C-c C-u") 'string-inflection-java-style-cycle))) ;; -;; You can also set `string-inflection-skip-backward-when-done' to `t' if -;; you don't like `string-inflect' moving your point to the end of the word. +;; You can configure where the cursor should end up after the inflection using the +;; `string-inflection-final-position' option. +;; +;; When a region is active during the inflect operation there are two effects: +;; +;; * If the region marks a part of a symbol the operation is only performed on that +;; part. +;; * If the region contains more than one symbols, the operation is performed on all +;; the symbols in the region. +;; * The region is preserved after the operation. ;;; Code: @@ -98,26 +105,13 @@ "Change the casing of words." :group 'convenience) -(defcustom string-inflection-skip-backward-when-done nil - "Controls the position of the cursor after an inflection. - -If nil remain at the end of the string after inflecting, else move backward to -the beginning." +(defcustom string-inflection-final-position 'remain + "Where to finish after the inflection. +This can be `remain' – remain at the initial position but not beyond the end of the inflected string –, +`beginning' – jump to the beginning of the inflection – or +`end' – jump to the end of the inflection." :group 'string-inflection - :type 'boolean) - -(defconst string-inflection-word-chars "a-zA-Z0-9_-") - -(defcustom string-inflection-erase-chars-when-region "./" - "When selected in the region, this character is included in the transformation -as part of the string. - -Exactly assume that the underscore exists. -For example, when you select `Foo/Bar', it is considered that `Foo_Bar' is -selected. If include `:', select `FOO::VERSION' to run -`M-x\ string-inflection-underscore' to `foo_version'." - :group 'string-inflection - :type 'string) + :type '(choice (const remain) (const beginning) (const end))) ;; -------------------------------------------------------------------------------- @@ -125,8 +119,7 @@ selected. If include `:', select `FOO::VERSION' to run (defun string-inflection-ruby-style-cycle () "foo_bar => FOO_BAR => FooBar => foo_bar" (interactive) - (string-inflection-insert - (string-inflection-ruby-style-cycle-function (string-inflection-get-current-word)))) + (string-inflection--single-or-region #'string-inflection-ruby-style-cycle-function)) (fset 'string-inflection-cycle 'string-inflection-ruby-style-cycle) @@ -134,130 +127,141 @@ selected. If include `:', select `FOO::VERSION' to run (defun string-inflection-elixir-style-cycle () "foo_bar => FooBar => foo_bar" (interactive) - (string-inflection-insert - (string-inflection-elixir-style-cycle-function (string-inflection-get-current-word)))) + (string-inflection--single-or-region #'string-inflection-elixir-style-cycle-function)) ;;;###autoload (defun string-inflection-python-style-cycle () "foo_bar => FOO_BAR => FooBar => foo_bar" (interactive) - (string-inflection-insert - (string-inflection-python-style-cycle-function (string-inflection-get-current-word)))) + (string-inflection--single-or-region #'string-inflection-python-style-cycle-function)) ;;;###autoload (defun string-inflection-java-style-cycle () "fooBar => FOO_BAR => FooBar => fooBar" (interactive) - (string-inflection-insert - (string-inflection-java-style-cycle-function (string-inflection-get-current-word)))) + (string-inflection--single-or-region #'string-inflection-java-style-cycle-function)) ;;;###autoload (defun string-inflection-all-cycle () "foo_bar => FOO_BAR => FooBar => fooBar => foo-bar => Foo_Bar => foo_bar" (interactive) - (string-inflection-insert - (string-inflection-all-cycle-function (string-inflection-get-current-word)))) + (string-inflection--single-or-region #'string-inflection-all-cycle-function)) ;;;###autoload (defun string-inflection-toggle () "toggle foo_bar <=> FooBar" (interactive) - (string-inflection-insert - (string-inflection-toggle-function (string-inflection-get-current-word)))) + (string-inflection--single-or-region #'string-inflection-toggle-function)) ;;;###autoload (defun string-inflection-camelcase () "FooBar format" (interactive) - (string-inflection-insert - (string-inflection-pascal-case-function (string-inflection-get-current-word)))) + (string-inflection--single-or-region #'string-inflection-pascal-case-function)) ;;;###autoload (defun string-inflection-lower-camelcase () "fooBar format" (interactive) - (string-inflection-insert - (string-inflection-camelcase-function (string-inflection-get-current-word)))) + (string-inflection--single-or-region #'string-inflection-camelcase-function)) ;;;###autoload (defun string-inflection-underscore () "foo_bar format" (interactive) - (string-inflection-insert - (string-inflection-underscore-function (string-inflection-get-current-word)))) + (string-inflection--single-or-region #'string-inflection-underscore-function)) ;;;###autoload (defun string-inflection-capital-underscore () "Foo_Bar format" (interactive) - (string-inflection-insert - (string-inflection-capital-underscore-function (string-inflection-get-current-word)))) + (string-inflection--single-or-region #'string-inflection-capital-underscore-function)) ;;;###autoload (defun string-inflection-upcase () "FOO_BAR format" (interactive) - (string-inflection-insert - (string-inflection-upcase-function (string-inflection-get-current-word)))) + (string-inflection--single-or-region #'string-inflection-upcase-function)) ;;;###autoload (defun string-inflection-kebab-case () "foo-bar format" (interactive) - (string-inflection-insert - (string-inflection-kebab-case-function (string-inflection-get-current-word)))) + (string-inflection--single-or-region #'string-inflection-kebab-case-function)) (fset 'string-inflection-lisp 'string-inflection-kebab-case) ;; -------------------------------------------------------------------------------- -(defun string-inflection-insert (s) - (insert s) - (when string-inflection-skip-backward-when-done (skip-chars-backward string-inflection-word-chars))) - -(defun string-inflection-non-word-chars () - (concat "^" string-inflection-word-chars)) +(defun string-inflection--count-symbols-between-start-and-end (start end) + "Count the symbols between START and END." + (let ((symbol-num 0)) + (goto-char start) + (save-excursion + (while (< (point) end) + (setq symbol-num (1+ symbol-num)) + (forward-symbol 1))) + symbol-num)) + +(defun string-inflection--single-or-region (inflect-func) + "Perform INFLECT-FUNC depending on if in region or single." + (if (use-region-p) + (string-inflection--region inflect-func) + (string-inflection--single inflect-func))) + +(defun string-inflection--single (inflect-func) + "Perform INFLECT-FUNC for a single occurrence." + (let ((orig-point (point))) + (insert (funcall inflect-func (string-inflection-get-current-word))) + (pcase string-inflection-final-position + ('remain (goto-char (min orig-point (cdr (bounds-of-thing-at-point 'symbol))))) + ('beginning (goto-char (car (bounds-of-thing-at-point 'symbol))))))) + +(defun string-inflection--region (inflect-func) + "Perform INFLECT-FUNC for all occurrences in the region." + (let ((orig-point (point)) + (start (region-beginning)) + (end (region-end))) + (dotimes (_ (string-inflection--count-symbols-between-start-and-end start end)) + (let ((orig-length (length (symbol-name (symbol-at-point))))) + (insert (funcall inflect-func (string-inflection-get-current-word-limited-by start end))) + (setq end (+ end (- (length (symbol-name (symbol-at-point))) orig-length))) + (forward-symbol 1) + (if-let* ((bounds (bounds-of-thing-at-point 'symbol))) + (goto-char (car bounds))))) + (let ((new-region + (pcase string-inflection-final-position + ('remain (if (/= orig-point start) (cons start end) (cons end start))) + ('beginning (cons end start)) + ('end (cons start end))))) + (set-mark (car new-region)) + (goto-char (cdr new-region))) + (activate-mark) + (setq deactivate-mark nil))) (defun string-inflection-get-current-word () "Gets the symbol near the cursor" (interactive) - (let* ((start (if (use-region-p) - (region-end) - (progn - (skip-chars-forward string-inflection-word-chars) - - ;; https://github.com/akicho8/string-inflection/issues/30 - ;; - ;; objectName->method --> "objectName-" NG - ;; --> "objectName" OK - (when (and (not (eobp)) (not (bobp))) - (when (string= (buffer-substring (1- (point)) (1+ (point))) "->") - (forward-char -1))) - - (point)))) - (end (if (use-region-p) - (region-beginning) - (progn - (skip-chars-backward string-inflection-word-chars) - (point)))) - (str (buffer-substring start end))) - (prog1 - (progn - (when (use-region-p) - ;; https://github.com/akicho8/string-inflection/issues/31 - ;; Multiple lines will be one line because [:space:] are included to line breaks - (setq str (replace-regexp-in-string (concat "[" string-inflection-erase-chars-when-region "]+") "_" str)) ; 'aa::bb.cc dd/ee' => 'aa_bb_cc dd_ee' - - ;; kebabing a region can insert an unexpected hyphen - ;; https://github.com/akicho8/string-inflection/issues/34 - (with-syntax-table (copy-syntax-table) - (modify-syntax-entry ?_ "w") - (setq str (replace-regexp-in-string "_+\\b" "" str)) ; '__aA__ __aA__' => '__aA __aA' - (setq str (replace-regexp-in-string "\\b_+" "" str)) ; '__aA __aA' => 'aA aA' - ) - ) - str) - (delete-region start end)))) + (if-let* ((bounds (bounds-of-thing-at-point 'symbol)) + (start (car bounds)) + (end (cdr bounds)) + (str (buffer-substring start end))) + (progn + (delete-region start end) + str) + "")) + +(defun string-inflection-get-current-word-limited-by (reg-start reg-end) + "Gets the symbol near the cursor limited by REG-START and REG-END." + (interactive) + (if-let* ((bounds (bounds-of-thing-at-point 'symbol)) + (start (max (car bounds) reg-start)) + (end (min (cdr bounds) reg-end)) + (str (buffer-substring start end))) + (progn + (delete-region start end) + str) + "")) ;; -------------------------------------------------------------------------------- @@ -283,8 +287,8 @@ selected. If include `:', select `FOO::VERSION' to run (defun string-inflection-underscore-function (str) "FooBar => foo_bar" (let ((case-fold-search nil)) - (setq str (replace-regexp-in-string "\\([a-z0-9]\\)\\([A-Z]\\)" "\\1_\\2" str)) - (setq str (replace-regexp-in-string "\\([A-Z]+\\)\\([A-Z][a-z]\\)" "\\1_\\2" str)) + (setq str (replace-regexp-in-string "\\([[:lower:][:digit:]]\\)\\([[:upper:]]\\)" "\\1_\\2" str)) + (setq str (replace-regexp-in-string "\\([[:upper:]]+\\)\\([[:upper:]][[:lower:]]\\)" "\\1_\\2" str)) (setq str (replace-regexp-in-string "-" "_" str)) ; FOO-BAR => FOO_BAR (setq str (replace-regexp-in-string "_+" "_" str)) (downcase str))) @@ -376,24 +380,24 @@ selected. If include `:', select `FOO::VERSION' to run (defun string-inflection-word-p (str) "if foo => t" (let ((case-fold-search nil)) - (string-match "\\`[a-z0-9]+\\'" str))) + (string-match "\\`[[:lower:][:digit:]]+\\'" str))) (defun string-inflection-underscore-p (str) "if foo_bar => t" (let ((case-fold-search nil)) - (string-match "\\`[a-z0-9_]+\\'" str))) + (string-match "\\`[[:lower:][:digit:]_]+\\'" str))) (defun string-inflection-upcase-p (str) "if FOO_BAR => t" (let ((case-fold-search nil)) - (string-match "\\`[A-Z0-9_]+\\'" str))) + (string-match "\\`[[:upper:][:digit:]_]+\\'" str))) (defun string-inflection-pascal-case-p (str) "if FooBar => t" (let ((case-fold-search nil)) (and - (string-match "[a-z]" str) - (string-match "\\`[A-Z][a-zA-Z0-9]+\\'" str)))) + (string-match "[[:lower:]]" str) + (string-match "\\`[[:upper:]][[:lower:][:upper:][:digit:]]+\\'" str)))) (fset 'string-inflection-upper-camelcase-p 'string-inflection-pascal-case-p) @@ -401,8 +405,8 @@ selected. If include `:', select `FOO::VERSION' to run "if fooBar => t" (let ((case-fold-search nil)) (and - (string-match "[A-Z]" str) - (string-match "\\`[a-z][a-zA-Z0-9]+\\'" str)))) + (string-match "[[:upper:]]" str) + (string-match "\\`[[:lower:]][[:lower:][:upper:][:digit:]]+\\'" str)))) (fset 'string-inflection-lower-camelcase-p 'string-inflection-camelcase-p) @@ -414,9 +418,8 @@ selected. If include `:', select `FOO::VERSION' to run "if Foo_Bar => t" (let ((case-fold-search nil)) (and - (string-match "[A-Z]" str) (string-match "_" str) - (string-match "\\`[A-Z][a-zA-Z0-9_]+\\'" str)))) + (string-match "\\`[[:upper:]][[:lower:][:upper:][:digit:]_]+\\'" str)))) (provide 'string-inflection) ;;; string-inflection.el ends here diff --git a/elpa/string-inflection-readme.txt b/elpa/string-inflection-readme.txt deleted file mode 100644 index 6daa1c92..00000000 --- a/elpa/string-inflection-readme.txt +++ /dev/null @@ -1,58 +0,0 @@ -Main functions are three - - 1. For Ruby -> string-inflection-ruby-style-cycle (foo_bar => FOO_BAR => FooBar => foo_bar) - 2. For Python -> string-inflection-python-style-cycle (foo_bar => FOO_BAR => FooBar => foo_bar) - 3. For Java -> string-inflection-java-style-cycle (fooBar => FOO_BAR => FooBar => fooBar) - 4. For All -> string-inflection-all-cycle (foo_bar => FOO_BAR => FooBar => fooBar => foo-bar => Foo_Bar => foo_bar) - - -Setting Example 1 - - (require 'string-inflection) - (global-unset-key (kbd "C-q")) - ;; C-q C-u is the key bindings similar to Vz Editor. - (global-set-key (kbd "C-q C-u") 'my-string-inflection-cycle-auto) - - (defun my-string-inflection-cycle-auto () - "switching by major-mode" - (interactive) - (cond - ;; for emacs-lisp-mode - ((eq major-mode 'emacs-lisp-mode) - (string-inflection-all-cycle)) - ;; for java - ((eq major-mode 'java-mode) - (string-inflection-java-style-cycle)) - ;; for python - ((eq major-mode 'python-mode) - (string-inflection-python-style-cycle)) - (t - ;; default - (string-inflection-ruby-style-cycle)))) - - -Setting Example 2 - - (require 'string-inflection) - - ;; default - (global-set-key (kbd "C-c C-u") 'string-inflection-all-cycle) - - ;; for ruby - (add-hook 'ruby-mode-hook - '(lambda () - (local-set-key (kbd "C-c C-u") 'string-inflection-ruby-style-cycle))) - - ;; for python - (add-hook 'python-mode-hook - '(lambda () - (local-set-key (kbd "C-c C-u") 'string-inflection-python-style-cycle))) - - ;; for java - (add-hook 'java-mode-hook - '(lambda () - (local-set-key (kbd "C-c C-u") 'string-inflection-java-style-cycle))) - -You may also consider setting `string-inflection-skip-backward-when-done' to -`t' if you don't like `string-inflect' moving your point to the end of the -word -- 2.47.3