1

I would like files in the speedbar that are symlinks, to be highlighted, or at least marked with @ so that they are easily distinguishable.

  • I do something similar in a custom version of speedbar that is not presently publicly available. In my custom version, I modified speedbar-default-directory-list and used a file-symlink-p test .... In the stock version of speedbar, there is no built-in symlink test -- thus, a custom solution that modifies one or more aspects of that library would be required to answer this question. This is not something that can be easily done with advice ... – lawlist Jul 3 '19 at 22:21
  • @lawlist Thanks, as I suspected. So I'll take the plunge and write some more elisp. – Don Jul 4 '19 at 4:55
  • I went ahead and wrote-up a solution, but it requires adding a couple of faces and modifying speedbar-insert-files-at-point, which is called by speedbar-default-directory-list. Other than modifying a core function of speedbar.el, I see no other easy way to answer this question. – lawlist Jul 4 '19 at 5:13
1

As mentioned in my comment underneath the question above, there is no built-in support for identifying a symlink using the speedbar library. The following code adds that support -- differentiating between a symlink directory versus a filename. Evaluate the code below and then open a speedbar window, or refresh a window if it is already open.

(require 'speedbar)

(defface speedbar-symlink-directory-face
  '((((class color) (background light)) :foreground "red")
    (((class color) (background dark)) :foreground "green"))
  "Speedbar face for symlinked directory names."
  :group 'speedbar-faces)

(defface speedbar-symlink-filename-face
  '((((class color) (background light)) :foreground "purple")
    (((class color) (background dark)) :foreground "yellow"))
  "Speedbar face for symlinked filenames."
  :group 'speedbar-faces)

(defun speedbar-insert-files-at-point (files level)
  "Insert list of FILES starting at point, and indenting all files to LEVEL.
Tag expandable items with a +, otherwise a ?.  Don't highlight ? as we
don't know how to manage them.  The input parameter FILES is a cons
cell of the form (DIRLIST . FILELIST)."
  ;; Start inserting all the directories
  (let ((dirs (car files)))
    (while dirs
      (speedbar-make-tag-line 'angle
                              ?+
                              'speedbar-dired
                              (car dirs)
                              (car dirs)
                              'speedbar-dir-follow
                              nil
                              (if (file-symlink-p (car dirs))
                                'speedbar-symlink-directory-face
                                'speedbar-directory-face)
                              level)
      (setq dirs (cdr dirs))))
  (let ((lst (car (cdr files)))
        (case-fold-search t))
    (while lst
      (let* ((known (string-match speedbar-file-regexp (car lst)))
             (expchar (if known ?+ ??))
             (fn (if known 'speedbar-tag-file nil)))
        (when (or speedbar-show-unknown-files (/= expchar ??))
          (speedbar-make-tag-line 'bracket
                                  expchar
                                  fn
                                  (car lst)
                                  (car lst)
                                  'speedbar-find-file
                                  nil
                                  (if (file-symlink-p (car lst))
                                    'speedbar-symlink-filename-face
                                    'speedbar-file-face)
                                  level)))
      (setq lst (cdr lst)))))
| improve this answer | |
  • Mucho Gracias, I will add this to my well-fatted .emacs file – Don Jul 5 '19 at 16:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.