Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve PR #28 helm-yas-find-recursively issue #29

Merged
merged 4 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CI

on:
pull_request:
push:
paths-ignore:
- '**.md'

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
emacs_version:
- 28.2
- 29.1
- 'snapshot'
steps:
- uses: actions/checkout@v4
- uses: purcell/setup-emacs@master
with:
version: ${{ matrix.emacs_version }}
- name: Install cask
run: |
git clone https://github.com/cask/cask ~/.cask
echo "${HOME}/.cask/bin" >> $GITHUB_PATH
- name: Run tests
run: make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.elc
/.cask/
*~
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.PHONY : test clean

EMACS ?= emacs
CASK ?= cask

LOADPATH = -L .

ELPA_DIR = $(shell EMACS=$(EMACS) $(CASK) package-directory)

test: elpa
$(CASK) exec $(EMACS) -Q -batch $(LOADPATH) \
-l test/helm-yasnippet-test.el \
-f ert-run-tests-batch-and-exit

elpa: $(ELPA_DIR)
$(ELPA_DIR): Cask
$(CASK) install
touch $@

clean:
-rm -f *.elc
8 changes: 4 additions & 4 deletions helm-c-yasnippet.el
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ If SNIPPET-FILE does not contain directory, it is placed in default snippet dire
(let* ((major-mode-dir (symbol-name major-mode))
(yas-dir (file-name-as-directory (expand-file-name (or (car-safe yas-snippet-dirs) yas-snippet-dirs))))
(snippet-dir
(or (helm-yas-find-recursively (regexp-quote major-mode-dir) yas-dir 'snippet-file)
(or (helm-yas-find-recursively major-mode-dir yas-dir 'dir)
(let ((target-dir (file-name-as-directory (concat yas-dir major-mode-dir))))
(if (yes-or-no-p (format "%s doesn't exist. Would you like to create this directory?" target-dir))
(progn
Expand All @@ -155,7 +155,7 @@ If SNIPPET-FILE does not contain directory, it is placed in default snippet dire
(error "can't create file [%s] already exists" (file-name-nondirectory snippet-file)))
(helm-yas-create-new-snippet-file selected-text snippet-file)))

(defun helm-yas-find-recursively (regexp &optional directory predicate)
(defun helm-yas-find-recursively (name &optional directory predicate)
(let* ((directory (or directory default-directory))
(predfunc (cl-case predicate
(dir 'file-directory-p)
Expand All @@ -167,11 +167,11 @@ If SNIPPET-FILE does not contain directory, it is placed in default snippet dire
(cl-loop for file in files
unless found
do (if (and (funcall predfunc file)
(string-match regexp file))
(string= name (file-name-nondirectory file)))
(progn (setq found t)
(cl-return (file-name-as-directory file)))
(when (file-directory-p file)
(setq result (helm-yas-find-recursively regexp file predicate))))
(setq result (helm-yas-find-recursively name file predicate))))
finally (cl-return result))))


Expand Down
40 changes: 40 additions & 0 deletions test/helm-yasnippet-test.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
;;; helm-yasnippet-test.el --- test commands of helm-yasnippet -*- lexical-binding: t -*-

;; Copyright (C) 2023 by Shohei YOSHIDA

;; Author: Shohei YOSHIDA <syohex@gmail.com>

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.

;;; Commentary:

;;; Code:

(require 'ert)
(require 'helm-c-yasnippet)
(require 'cl-lib)

(ert-deftest regression-issue-28 ()
"Find major-mode directory with string not regexp.
Detail: https://github.com/emacs-jp/helm-c-yasnippet/pull/28"
(let ((tmpdir (concat temporary-file-directory "helm-yasnippet/")))
(delete-directory tmpdir t)
(cl-loop for dir in '("sh-mode" "fish-mode")
do
(make-directory (concat tmpdir dir) t))
(let ((dir (helm-yas-find-recursively "sh-mode" tmpdir 'dir)))
(should (string= dir (concat tmpdir "sh-mode/"))))
(delete-directory tmpdir t)))

;;; helm-yasnippet-test.el ends here