emacs कैमकैक्स से एमएएमएक्स में परिवर्तित करना




elisp camelcasing (4)

क्या ऊँट-सीज़ेड शब्द को अंडरस्कोर में कनवर्ट करने के लिए एक emacs फ़ंक्शन है? कुछ इस तरह:

longVariableName

Mx to-underscore

long_variable_name


(progn (replace-regexp "\\([A-Z]\\)" "_\\1" nil (region-beginning) (region-end))
       (downcase-region (region-beginning) (region-end)))

स्ट्रिंग-इन्फ़ोन्शन पैकेज का उपयोग करें, MELPA पर उपलब्ध है, या https://github.com/akicho8/string-inflection पर

उपयोगी कीबोर्ड शॉर्टकट, जो https://www.emacswiki.org/emacs/CamelCase से कॉपी किए गए हैं:

;; Cycle between snake case, camel case, etc.
(require 'string-inflection)
(global-set-key (kbd "C-c i") 'string-inflection-cycle)
(global-set-key (kbd "C-c C") 'string-inflection-camelcase)        ;; Force to CamelCase
(global-set-key (kbd "C-c L") 'string-inflection-lower-camelcase)  ;; Force to lowerCamelCase
(global-set-key (kbd "C-c J") 'string-inflection-java-style-cycle) ;; Cycle through Java styles

मैं कैमेलकेस और अंडरस्कोर के बीच टॉगल करने के लिए निम्न का उपयोग करता हूं:

(defun toggle-camelcase-underscores ()
  "Toggle between camelcase and underscore notation for the symbol at point."
  (interactive)
  (save-excursion
    (let* ((bounds (bounds-of-thing-at-point 'symbol))
           (start (car bounds))
           (end (cdr bounds))
           (currently-using-underscores-p (progn (goto-char start)
                                                 (re-search-forward "_" end t))))
      (if currently-using-underscores-p
          (progn
            (upcase-initials-region start end)
            (replace-string "_" "" nil start end)
            (downcase-region start (1+ start)))
        (replace-regexp "\\([A-Z]\\)" "_\\1" nil (1+ start) end)
        (downcase-region start (cdr (bounds-of-thing-at-point 'symbol)))))))

मैं इसका उपयोग जब सी # कोड को PHP में परिवर्तित कर रहा हूँ

(defun un-camelcase-word-at-point ()
  "un-camelcase the word at point, replacing uppercase chars with
the lowercase version preceded by an underscore.

The first char, if capitalized (eg, PascalCase) is just
downcased, no preceding underscore.
"
  (interactive)
  (save-excursion
    (let ((bounds (bounds-of-thing-at-point 'word)))
      (replace-regexp "\\([A-Z]\\)" "_\\1" nil
                      (1+ (car bounds)) (cdr bounds))
      (downcase-region (car bounds) (cdr bounds)))))

और फिर मेरे php-mode fn में:

(local-set-key "\M-\C-C"  'un-camelcase-word-at-point)




camelcasing