Skip to content

Instantly share code, notes, and snippets.

@twlz0ne
Created April 7, 2018 09:45
Show Gist options
  • Save twlz0ne/87820e05c721151d979b82d137194c25 to your computer and use it in GitHub Desktop.
Save twlz0ne/87820e05c721151d979b82d137194c25 to your computer and use it in GitHub Desktop.
Test the filtering of helm ff boring files #emacs
;;; Date: 2017-12-28_23.12.21
;;; Usage:
;; $ /path/to/emacs -nw -Q -l /path/to/test-helm-ff-boring-files-filtering.el
;; or
;; $ /path/to/emacs --batch -l /path/to/test-helm-ff-boring-files-filtering.el
(toggle-debug-on-error)
(global-set-key (kbd "C-h") 'delete-backward-char)
(global-set-key (kbd "M-h") 'backward-kill-word)
(global-set-key (kbd "<f1>") 'help-command)
(define-key isearch-mode-map "\C-h" 'isearch-delete-char)
;; Don't ask
(setq url-show-status nil)
(setq network-security-level 'low)
;; ------------------------------------------------------------------
(setq user-emacs-directory (format "~/.emacs.d/%s/%s/" (file-name-base load-file-name) emacs-version))
(setq package-user-dir (concat user-emacs-directory "elpa/"))
(unless (load "~/.emacs.d/elpa.el" t)
(setq package-archives
'(("gnu" . "https://elpa.gnu.org/packages/")
("melpa" . "https://melpa.org/packages/"))))
(package-initialize)
(defun require-packages (&rest packages)
(dolist (pkg packages)
(unless (package-installed-p pkg)
(package-refresh-contents)
(package-install pkg))
(require pkg)))
;; (require-packages
;; 'helm
;; )
;; ------------------------------------------------------------------
(setq el-get-dir (concat user-emacs-directory "el-get/"))
(add-to-list 'load-path (concat el-get-dir "el-get"))
(setq el-get-git-shallow-clone t)
(setq el-get-byte-compile nil)
(setq el-get-bundle-byte-compile nil)
(setq el-get-install-skip-emacswiki-recipes t)
(unless (require 'el-get nil 'noerror)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/dimitri/el-get/master/el-get-install.el")
(goto-char (point-max))
(eval-print-last-sexp)))
(remove-hook 'el-get-post-install-hooks 'el-get-post-install-notification)
(el-get-bundle async (require 'async))
(el-get-bundle popup (require 'popup))
(el-get-bundle helm (require 'helm))
;; ------------------------------------------------------------------
(defvar tmpdir)
(defvar tmpfiles)
(add-hook 'after-init-hook
(lambda ()
(require 'helm-config)
(helm-mode 1)
(setq helm-debug t)
(setq helm-ff-skip-boring-files t)
(customize-set-variable 'helm-boring-file-regexp-list
'("#$"
"^#.*"
"\\`#.*"))
(message "---------- Start test ----------")
(message "helm-boring-file-regexp-list: %S" helm-boring-file-regexp-list)
(unless (featurep 'el-get)
(message "helm-ff--boring-regexp: %S" helm-ff--boring-regexp))
(global-set-key (kbd "C-x C-f") 'helm-find-files)
(setq tmpfiles '("#foo" "foo#" "#foo#" "#bar" "bar#" "#bar#"))
(setq tmpdir (make-temp-file "test-helm-ff-boring-files-filtering--" 'tmpdir "/"))
;; Verify regex
(message "---------- Verify regex ----------")
(dolist (file tmpfiles)
(let ((actual (when (helm-ff-boring-file-p file) t)))
(message "(helm-ff-boring-file-p %S) => %s (expect t) %s"
file actual (if actual "✔" "✗"))))
;; Create files
(shell-command-to-string
(concat "cd " tmpdir
"&& touch " (mapconcat (lambda (file)
(concat "'" file "'"))
tmpfiles " ")))
(helm-find-files-1 tmpdir)))
(defun after/helm-update (&optional preselect source candidates)
(let ((helm-ff-buffer "*helm find files*"))
(message "---------- Verify buffer `%s' ----------" helm-ff-buffer)
(with-current-buffer helm-ff-buffer
(message "- Expect:\n")
(message (concat "1 Find files\n"
"2 " tmpdir ".\n"
"3 "tmpdir "..\n"))
(message "- Actual:\n")
(let ((i 0))
(mapcar (lambda (line)
(unless (equal "" line)
(setq i (1+ i))
(message "%d %s" i line)))
(split-string (buffer-substring-no-properties (point-min) (point-max)) "\n")))
(if noninteractive
(keyboard-quit)
(advice-remove 'helm-update 'after/helm-update)))))
(advice-add 'helm-update :after 'after/helm-update)
(run-hooks 'after-init-hook)
;;; test-helm-ff-boring-files-filtering.el ends here
@twlz0ne
Copy link
Author

twlz0ne commented Apr 7, 2018

└⋊> emacs-nightly --batch -l ~/.scratch/emacs/test-helm-ff-boring-files-filtering.el
Debug on Error enabled globally
Loading ~/.emacs.d/elpa.el (source)...
---------- Start test ----------
helm-boring-file-regexp-list: ("#$" "^#.*" "\\`#.*")
---------- Verify regex ----------
(helm-ff-boring-file-p "#foo") => t (expect t) ✔
(helm-ff-boring-file-p "foo#") => t (expect t) ✔
(helm-ff-boring-file-p "#foo#") => t (expect t) ✔
(helm-ff-boring-file-p "#bar") => t (expect t) ✔
(helm-ff-boring-file-p "bar#") => t (expect t) ✔
(helm-ff-boring-file-p "#bar#") => t (expect t) ✔
---------- Verify buffer ‘*helm find files*’ ----------
- Expect:

1 Find files
2 /var/folders/vq/k0y6n92j6r5dk_hx_jrl62jh0000gn/T/test-helm-ff-boring-files-filtering--tcn3YT/.
3 /var/folders/vq/k0y6n92j6r5dk_hx_jrl62jh0000gn/T/test-helm-ff-boring-files-filtering--tcn3YT/..

- Actual:

1 Find Files
2 /var/folders/vq/k0y6n92j6r5dk_hx_jrl62jh0000gn/T/test-helm-ff-boring-files-filtering--tcn3YT/.
3 /var/folders/vq/k0y6n92j6r5dk_hx_jrl62jh0000gn/T/test-helm-ff-boring-files-filtering--tcn3YT/..
4 #bar
5 #foo
  • macOS 10.11.6
  • Emacs 27.0.50
  • helm master branch (commit: f3f3b40e) 2018-04-06

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment