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
    Sep 18 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
    Sep 18 at 11:55
  • Did you look at its customize group?
    – phils
    Sep 18 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
    Sep 18 at 12:57
  • Welcome! If you don't like glasses-mode, you'll need to be more specific about what help you need. In particular, please post functions that you have created but need help finishing. Otherwise, this question risks turning into a "please code this thing for me"-style post, which does not generally go down well here.
    – Dan
    Sep 18 at 20:32

0

Your Answer

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

Browse other questions tagged or ask your own question.