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

Warning Couldn't find space #1197

Open
dericbytes opened this issue Apr 12, 2024 · 2 comments
Open

Warning Couldn't find space #1197

dericbytes opened this issue Apr 12, 2024 · 2 comments

Comments

@dericbytes
Copy link

dericbytes commented Apr 12, 2024

I get 'Warning Couldn't find space' when expanding yas snippets in org src blocks.

I opened an issue in 2019 #976 and it eased the problem. However it never solved it. At the time I tried it on a fresh system but could not reproduce it. I assumed it was due to my complex setup.

I have managed to replicate it on a clean build. I stripped away as much as I could.

GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version 1.18.0, Xaw3d scroll bars) of 2024-04-03
yasnippet 2024 - Version: 0.14.1

rm -rf ~/tmp/yas-test
mkdir !$
emacs --quick --init-directory=!$ !$/test.org
M-x package-install yasnippet
M-x yas-new-snippet
# key: di
# name: di
# --
 ($1)
  "$0"

save as emacs lisp snippet

C-c C-c
> emacs-lisp-mode
> RET
> y

Get emacs-lisp snippets to work in org-mode

M-x find-file snippets/org-mode/.yas-parents

add the text

emacs-lisp-mode

and save file.

In test.org add the code below, note there is an indent of a space before the #'s

 #+name: test
 #+begin_src emacs-lisp
      2
    di
  #+end_src
M-x yas-minor-mode
M-x yas-reload-all

place cursor after

di

and press TAB

⛔ Warning (yasnippet): Couldn’t find: "[[:space:]
]*\"[[:space:]
]*\\(\\)[[:space:]
]*\""

NOTE:

A collection of things had to be in place to generate this. Works when:

  • org source block has no indent i.e. remove space before ' #+'
  • the source block has no property i.e #+name
  • the expansion trigger is the only thing in the source block
  • the expansion trigger is after contents but still on the first line
  • there is only one snippet variable
  • all the snippet variables are on same line
  • the quotes around $0 are removed
  • the parenthesis around $1 are removed

It does not work when content is above the yas trigger.
i.e. 2 is above the 'di' yas trigger key

@nocontroltoedit
Copy link

Here is an ert test to recreate this error on

  • yasnippet-0.14.1.0.20250112.175154
  • GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.38, cairo version 1.16.0) of 2025-02-21
rm -rf ~/tmp/yas-test
mkdir !$
emacs --quick --init-directory=!$ 
(require 'package)
(add-to-list 'package-archives '("gnu-devel" . "https://elpa.gnu.org/devel/") t)
(package-initialize)
(package-refresh-contents)

(package-install 'yasnippet)
(use-package yasnippet)

(defun warning-buffer-contents-no-properties ()
  "Return contents of *Warnings* buffer, without properties"
  (when-let* ((buf (get-buffer "*Warnings*")))
    (with-current-buffer buf
      (buffer-substring-no-properties (point-min) (point-max)))))

(defun my-create-yasnippet-snippets ()
  "Create a snippet called `could-not-find-space'.
      Add it to the group `emacs-lisp-mode'
      Allow `org-mode' to inherit `emacs-lisp-mode' snippets"
  (let* ((snippet-key "could-not-find-space")
    (snippet-content (concat
      " ($1)\n"
      "  \"$0\""))
    (snippet-def (list
          snippet-key
          snippet-content
          nil
          nil
          nil
          nil
          nil))
    (snippet-defs (list snippet-def))
    (mode 'emacs-lisp-mode))
   
    (yas-define-snippets mode
    snippet-defs)
    (yas--define-parents 'org-mode
    '(emacs-lisp-mode))))

(ert-deftest could-not-find-space ()
  "yas-expand should not throw the warning - Couldn't find [[:space:]]"
  (my-create-yasnippet-snippets)

  (ignore-error
      (kill-buffer "*Warnings"))
 
  (let ((org-mode-buffer-contents
    (concat
     "#+name: test \n"
     "#+begin_src emacs-lisp\n"
     "     2\n"
     "   could-not-find-space| \n"
     "#+end_src")))

   
    (with-temp-buffer
      (org-mode)  
      (setq org-edit-src-content-indentation 1)
      (yas-minor-mode 1)
      (insert org-mode-buffer-contents)
      (goto-char (point-min))
      (search-forward "|")
      (delete-char -1)
      (call-interactively 'yas-expand)
      (buffer-substring-no-properties (point-min) (point-max))))
 
  (should (equal (warning-buffer-contents-no-properties)
    nil)))


(ert t)

In GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
3.24.38, cairo version 1.16.0) of 2025-02-21 built on slug
Repository revision: 4411d0de1d5cbf308440982084ad7e15a18efaf2
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101007
System Description: LMDE 6 (faye)

Configured using:
'configure --with-mailutils --with-modules --with-imagemagick
--prefix=/home/no-control/local/installs
--bindir=/home/no-control/local/bin --with-native-compilation
--with-tree-sitter'

Configured features:
CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ IMAGEMAGICK
JPEG LCMS2 LIBSELINUX LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER
PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS
TREE_SITTER WEBP X11 XDBE XIM XINERAMA XINPUT2 XPM XRANDR GTK3 ZLIB

Important settings:
value of $LANG: en_GB.UTF-8
value of $XMODIFIERS: @im=ibus
locale-coding-system: utf-8-unix

Major mode: ERT-Results

Minor modes in effect:
tooltip-mode: t
global-eldoc-mode: t
show-paren-mode: t
electric-indent-mode: t
mouse-wheel-mode: t
tool-bar-mode: t
menu-bar-mode: t
file-name-shadow-mode: t
global-font-lock-mode: t
font-lock-mode: t
blink-cursor-mode: t
minibuffer-regexp-mode: t
buffer-read-only: t
line-number-mode: t
indent-tabs-mode: t
transient-mark-mode: t
auto-composition-mode: t
auto-encryption-mode: t
auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug oc-basic ol-eww eww vtable mule-util
url-queue mm-url ol-rmail ol-mhe ol-irc ol-info ol-gnus nnselect
gnus-art mm-uu mml2015 mm-view mml-smime smime dig gnus-sum shr
pixel-fill kinsoku url-file svg dom gnus-group gnus-undo gnus-start
gnus-dbus dbus xml gnus-cloud nnimap nnmail mail-source utf7 nnoo
parse-time gnus-spec gnus-int gnus-range gnus-win gnus nnheader range
ol-docview doc-view filenotify jka-compr image-mode exif ol-bibtex
bibtex iso8601 ol-bbdb ol-w3m ol-doi org-link-doi use-package-core
ox-odt rng-loc rng-uri rng-parse rng-match rng-dt rng-util rng-pttrn
nxml-parse nxml-ns nxml-enc xmltok nxml-util ox-latex ox-icalendar
org-agenda ox-html table ox-ascii ox-publish ox org-attach org-element
org-persist org-id org-refile org-element-ast inline avl-tree generator
org ob ob-tangle ob-ref ob-lob ob-table ob-exp org-macro org-src
sh-script smie treesit executable ob-comint org-pcomplete pcomplete
org-list org-footnote org-faces org-entities noutline outline
org-version ob-emacs-lisp ob-core ob-eval org-cycle org-table ol
org-fold org-fold-core org-keys oc org-loaddefs thingatpt cal-menu
calendar cal-loaddefs org-compat org-macs format-spec ert-x ert ewoc
warnings edebug debug backtrace find-func color yasnippet pcase cl-extra
help-mode yasnippet-autoloads easy-mmode loaddefs-gen lisp-mnt
radix-tree tar-mode arc-mode archive-mode cus-edit pp cus-start cus-load
wid-edit mm-archive message sendmail yank-media dired dired-loaddefs
rfc822 mml mml-sec epa derived gnus-util time-date mailabbrev gmm-utils
mailheader mm-decode mm-bodies mm-encode mail-utils gnutls
network-stream url-cache url-http url-auth mail-parse rfc2231 rfc2047
rfc2045 mm-util ietf-drums mail-prsvr url-gw nsm puny compile
text-property-search comint ansi-osc ansi-color ring comp-run
comp-common rx epg rfc6068 epg-config finder-inf package browse-url xdg
url url-proxy url-privacy url-expand url-methods url-history url-cookie
generate-lisp-file url-domsuf url-util mailcap url-handlers url-parse
auth-source cl-seq eieio eieio-core cl-macs icons password-cache json
subr-x map byte-opt gv bytecomp byte-compile url-vars cl-loaddefs cl-lib
rmc iso-transl tooltip cconv eldoc paren electric uniquify ediff-hook
vc-hooks lisp-float-type elisp-mode mwheel term/x-win x-win
term/common-win x-dnd touch-screen tool-bar dnd fontset image regexp-opt
fringe tabulated-list replace newcomment text-mode lisp-mode prog-mode
register page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer nadvice seq simple cl-generic indonesian philippine
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclodb
files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable backquote
threads dbusbind inotify lcms2 dynamic-setting system-font-setting
font-render-setting cairo gtk x-toolkit xinput2 x multi-tty move-toolbar
make-network-process tty-child-frames native-compile emacs)

Memory information:
((conses 16 411783 32541) (symbols 48 30614 0)
(strings 32 124515 6677) (string-bytes 1 3456886) (vectors 16 61641)
(vector-slots 8 591036 21567) (floats 8 455 85) (intervals 56 787 0)
(buffers 992 15))

@nocontroltoedit
Copy link

The problem might be the function yas--goto-saved-location

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants