0

I am writing Latex Style Files and want to improve the appearance of Camel Case Variables and Functions. What kind of elisp function can I write to enhance readability.

Have been directed to glasses.el. Rather than install another minor-mode to my configuration, I would like to take out the part that sets capital letters to a different colour.

Looking at the code I have identified glasses-face and glasses-make-overlay. But I need help to construct a function or two to enable and disable the colour functionality.

Have been working with the following function

(defun change-face-for-camel-case (face)
  "Change the face of capital letters in CamelCase words throughout the buffer.
FACE is the face to apply to the capital letters."
  (interactive "MFace for CamelCase letters: ")
  (let ((case-fold-search nil))
    (save-excursion
      (goto-char (point-min))
      (while (re-search-forward "\\b\\([A-Z][a-z0-9]*\\)\\([A-Z][a-z0-9]*\\)\\b" nil t)
        (add-text-properties (match-beginning 1) (match-end 1) `(face ,face))
        (add-text-properties (match-beginning 2) (match-end 2) `(face ,face)))
      (font-lock-fontify-buffer))))

;; Bind the function to a key for easy use, e.g., F5
(global-set-key (kbd "<f5>") (lambda () (interactive) (change-face-for-camel-case 'font-lock-variable-name-face)))
7
  • M-x glasses-mode
    – phils
    Commented Sep 18, 2023 at 11:49
  • 1
    I do not like working with glasses because I would not know what is real and what is imitation, particularly when making changes. For reading display purposes it seems good enough, but not for things beyond that.
    – Dilna
    Commented Sep 18, 2023 at 11:55
  • Did you look at its customize group?
    – phils
    Commented Sep 18, 2023 at 12:28
  • Did not look that detail. You are referring to the use of colours. Would prefer to make a small function for that rather than enabling yet another minor mode.
    – Dilna
    Commented Sep 18, 2023 at 12:57
  • 1
    You can enable glasses-mode, set glasses-separator to the empty string, and set glasses-face to the name of the face you want to use, for example 'underline. This won't require you to install anything external, as glasses is included with Emacs.
    – Pkkm
    Commented Sep 28, 2023 at 13:51

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.