0

I'm trying to display prettify-symbols-mode to display for certain characters. I would like for this minor mode to be enabled across all programming languages - thus prog-mode. When I navigate to a .ex file it is not giving me the expected outcome (ie. => should display as ⇒). Code is below:

(defun dotspacemacs/user-config ()


      (exec-path-from-shell-initialize)

      (setq powerline-default-separator 'arrow)

      (defun mix-format-on-save ()
        (when (eq major-mode 'elixir-mode)
          (elixir-format)))

      ;; display full buffer path in title window

      ;;(setq frame-title-format
      ;;      (list (format "%s %%S: %%j " (system-name))
      ;;            '(buffer-file-name "%f" (dired-directory dired-directory "%b"))))

      (global-prettify-symbols-mode 0)
      (setq prettify-symbols-unprettify-at-point t)

      (setq prettify-symbols-alist
            '(
              ("lambda" . 955) ; λ
              ("->" . 8594)    ; →
              ("<-" . 8592)
              ("=>" . 8658)    ; ⇒
              ("<=" . 8656)
              ("|>" . 10503)
              ))

      (add-hook 'prog-mode-hook 'prettify-symbols-mode)
    )
  • If `prettify-symbols-mode` is not being enabled, and this is only an issue for `.ex` files then undoubtedly the major mode used for `.ex` files does *not* derive from `prog-mode`. Just add `prettify-symbols-mode` to the mode hook for the major mode in question. – phils Feb 28 '19 at 19:39
  • You're right about that - works it .py files just fine. still though, when I set `(add-hook 'elixir-mode-hook 'prettify-symbols-mode)` or `(add-hook 'alchemist-mode-hook 'prettify-symbols-mode)` I still don't get the expected behavior. – colonelrascals Feb 28 '19 at 20:01
  • Oh, this is also (or entirely?) a duplicate of https://emacs.stackexchange.com/q/46529/454 -- you're not setting `prettify-symbols-alist` *in* a mode hook function. – phils Feb 28 '19 at 20:40
  • It very well may be. I'm new to elisp - do I need to bind it to a function? – colonelrascals Feb 28 '19 at 20:50

1 Answers1

0

Following on from the comments...

A third-party elixir-mode is being used for .ex files.

It's possible that elixir-mode does not derive from prog-mode, in which case you would need to enable prettify-symbols-mode in elixir-mode-hook; but the more apparent issue is that prettify-symbols-alist is not being set in the .ex buffer (refer to this related Q&A https://emacs.stackexchange.com/a/46531/454 ).

You should configure prettify-symbols-alist for the needs of elixir-mode in elixir-mode-hook. e.g.:

(defun my-elixir-mode-hook ()
  "Custom `elixir-mode' behaviours."
  (setq prettify-symbols-alist
        '(
          ("lambda" . 955) ; λ
          ("->" . 8594)    ; →
          ("<-" . 8592)
          ("=>" . 8658)    ; ⇒
          ("<=" . 8656)
          ("|>" . 10503)
          )))

(add-hook 'elixir-mode-hook 'my-elixir-mode-hook)

You can also add (prettify-symbols-mode 1) to that custom function if necessary.


The (setq prettify-symbols-alist ...) in your dotspacemacs/user-config function is not useful, and can be removed. (It is setting the value only for whichever buffer is current at the point in time that this function is evaluated during start-up.)

phils
  • 48,657
  • 3
  • 76
  • 115