completion-ignored-extensions

I’ve been using the rather spiffy Lusty Explorer for some time for my buffer and file finding. However it (I thought) had a rather annoying bug where I could never tab directly into some of the repositories I was hacking on. Eventually I figured out that the problem was down to the way I name them.

My naming scheme for any repository is generally to add the version control extension to the directory. This is more for my benefit than emacs as it’s quite capable of working this out for itself in any given repo. However it turns out that Lusty was being a good emacs citizen and using the variable completion-ignored-extensions which included the pattern “.git/” and duly hiding my repo directories from completion. In fact there are a number of patterns in there which should probably be more specific. I wrote this to fix the problem:

(setq completion-ignored-extensions
      (mapcar '(lambda (ext)
                 (if (string-equal "/" (substring ext -1 nil))
                     (concat "^" ext)
                   ext)) completion-ignored-extensions))

It still seems a little ugly to me so given the last time I berated elisp’s style gained so many useful suggestions I’d welcome improvements.

7 Comments

  1. I’m not sure ‘completion-ignored-extensions’ works that way. From what I can see, the contents are passed to ‘regexp-opt’, which quotes any regexp metacharacters along the way, so when you have ‘^.git/’ in ‘completion-ignored-extensions’, you end up literally matching any directory named ‘^.git’.

    ICBW though. Is this working for you?

    • It certainly seems to be working in so far as I can now tab complete into project.git but not into .git/. Are you looking at the general handling of completion-ignored-extensions or just lusty’s?

  2. Wow, that is weird. I was looking at general handling earlier; I just checked lusty’s and it seems to work the same way.[1][2] I tried same the ‘regexp-opt’ line here and it does put a backslash before the caret, meaning it no longer serves as an anchor for the start of the string… so how come it matches ‘.git/’ for you? If it did treat the strings in ‘completion-ignored-extensions’ as regexps, it would then match ‘agit’, ‘oclass’, ‘imap’, etc. too (since ‘.’ matches any character), but I’m guessing it doesn’t do that.

    All in all, I am rather confused.

    [1]: https://github.com/sjbach/lusty-emacs/blob/master/lusty-explorer.el#L159
    [2]: https://github.com/sjbach/lusty-emacs/blob/master/lusty-explorer.el#L226

    • Many apologies, you are quite correct that it isn’t hiding the .git directory. I was in the wrong emacs session when I was testing that out :-/

    • I’m using color-theme-gnome2 with (background-color . “DarkSlateGrey”) and (foreground-color . “wheat”). I then use the following for posting code snippets on web-pages:

      (if (locate-library "htmlize")
          (progn
            (load-library "htmlize")
            (setq htmlize-output-type 'inline-css)
      
            ; From http://ruslanspivak.com/2007/08/18/htmlize-your-erlang-code-buffer/
            (defun my-htmlize-region (beg end)
              "Htmlize region and put into <pre> tag style that is left in <body> tag
      plus add font-size: 8pt"
              (interactive "r")
              (let* ((buffer-faces (htmlize-faces-in-buffer))
                     (face-map (htmlize-make-face-map (adjoin 'default buffer-faces)))
                     (pre-tag (format
                               "<pre style=\"%s font-size: 8pt\">"
                               (mapconcat #'identity (htmlize-css-specs
                                                      (gethash 'default face-map)) " ")))
                     (htmlized-reg (htmlize-region-for-paste beg end)))
                (switch-to-buffer-other-window "*htmlized output*")
                                              ; clear buffer
                (kill-region (point-min) (point-max))
                                              ; set mode to have syntax highlighting
                (nxml-mode)
                (save-excursion
                  (insert htmlized-reg))
                (while (re-search-forward "<pre>" nil t)
                  (replace-match pre-tag nil nil))
                (goto-char (point-min))))
      
            (global-set-key [(f6)] (lambda (beg end)
                               (interactive "r") (my-htmlize-region beg end)))))
      
      • Might be cleaner to use `require’ there, along the lines of:

        (require ‘htmlize nil t)

        (when (featurep ‘htmlize)
        (setq htmlize-output-type ‘inline-css)

        ; From http://ruslanspivak.com/2007/08/18/htmlize-your-erlang-code-buffer/
        (defun my-htmlize-region (beg end)
        “Htmlize region and put into <pre> tag style that is left in <body> tag
        plus add font-size: 8pt”
        (interactive “r”)
        (let* ((buffer-faces (htmlize-faces-in-buffer))
        (face-map (htmlize-make-face-map (adjoin ‘default buffer-faces)))
        (pre-tag (format
        “<pre style=\”%s font-size: 8pt\”>”
        (mapconcat #’identity (htmlize-css-specs
        (gethash ‘default face-map)) ” “)))
        (htmlized-reg (htmlize-region-for-paste beg end)))
        (switch-to-buffer-other-window “*htmlized output*”)
        ; clear buffer
        (kill-region (point-min) (point-max))
        ; set mode to have syntax highlighting
        (nxml-mode)
        (save-excursion
        (insert htmlized-reg))
        (while (re-search-forward “<pre>” nil t)
        (replace-match pre-tag nil nil))
        (goto-char (point-min)))))

        (Here’s hoping ‘pre’ elements and HTML escapes are allowed.)

        Why specify the CSS inline rather than styling ‘pre’ elements in your site’s CSS files?

Comments are closed.