masasam / emacs-easy-hugo

Emacs major mode for managing hugo
https://gohugo.io/tools/editors/#emacs
GNU General Public License v3.0
362 stars 26 forks source link

"\<\>": pattern not found error when invoking new-post #54

Closed balaji-dutt closed 4 years ago

balaji-dutt commented 4 years ago

Hello,

I'm relatively new to Emacs, so my knowledge on these types of issues is relatively limited. So I apologize if this is not really an easy-hugo issue at all.

I'm currently using the Spacemacs distribution of emacs and have installed easy-hugo as an additional package. When I launch easy-hugo mode and type n for a new blog-post, I get the following error:

user-error: "\<\>": pattern not found

However, I have not been able to trace this issue further due to a few problems:

Does anyone have any suggestions on how I can trace this issue further?

easy-hugo config

  ;; Configure easy-hugo
  (with-eval-after-load 'easy-hugo
    (setq easy-hugo-basedir "f:/Balaji/Development/notebook/"
          easy-hugo-server-flags "-D"
          easy-hugo-postdir "content/posts"
          easy-hugo-image-directory "static/img"
          easy-hugo-url "https://nb.balaji.blog"
          easy-hugo-preview-url "http://127.0.0.1:1313/"
          )
    ;; (add-hook 'easy-hugo-mode-hook 'my-private-layer/easy-hugo)
    )

System Info

masasam commented 4 years ago

Hi @balaji-dutt . Thank you for comment. Please write in detail your OS, your spacemacs settings, etc at first.

balaji-dutt commented 4 years ago

Hi @balaji-dutt . Please write in detail your OS, your spacemacs settings, etc at first.

Sure. Sorry about that - have updated the original issue with those details.

masasam commented 4 years ago

Please write in detail also easy-hugo setting.

balaji-dutt commented 4 years ago

Please write in detail also easy-hugo setting.

Updated - sorry, I promise I'm usually better at filing GitHub issues than this 😞

masasam commented 4 years ago

If you use easy-hugo with Spacemacs, you need to assign it to n with easy-hugo-mode-map. See https://github.com/cescoferraro/dotfiles/blob/master/src/emacs.d/configuration.org#hugo .

balaji-dutt commented 4 years ago

Hi @masasam I actually did have the easy-hugo-mode-map configured since you reference it in the README. I realize there was a potential function name collision, so I made the following changes - extract from my config:

  ;; Configure easy-hugo
  (with-eval-after-load 'easy-hugo
    (setq easy-hugo-basedir "f:/Balaji/Development/notebook/"
          easy-hugo-server-flags "-D"
          easy-hugo-postdir "content/posts"
          easy-hugo-image-directory "static/img"
          easy-hugo-url "https://nb.balaji.blog"
          easy-hugo-preview-url "http://127.0.0.1:1313/"
          )
    (add-hook 'easy-hugo-mode-hook 'my-private-layer/easy-hugo-config)
    )

Function definition for my-private-layer/easy-hugo-config

(defun my-private-layer/easy-hugo-config ()
  (interactive)
  (evil-define-key
    (list 'normal 'insert 'visual 'motion)
    easy-hugo-mode-map
    "n" 'easy-hugo-newpost
    "D" 'easy-hugo-article
    "p" 'easy-hugo-preview
    "P" 'easy-hugo-publish
    "o" 'easy-hugo-open
    "d" 'easy-hugo-delete
    "e" 'easy-hugo-open
    "c" 'easy-hugo-open-config
    "f" 'easy-hugo-open
    "N" 'easy-hugo-no-help
    "v" 'easy-hugo-view
    "r" 'easy-hugo-refresh
    "g" 'easy-hugo-refresh
    "s" 'easy-hugo-sort-time
    "S" 'easy-hugo-sort-char
    "G" 'easy-hugo-github-deploy
    "A" 'easy-hugo-amazon-s3-deploy
    "C" 'easy-hugo-google-cloud-storage-deploy
    "q" 'evil-delete-buffer
    (kbd "TAB") 'easy-hugo-open
    (kbd "RET") 'easy-hugo-preview)
  (define-key global-map (kbd "C-c C-e") 'easy/hugo))

However even after the above changes, I still get the same error message when selecting n in easy-hugo mode.

masasam commented 4 years ago

I think with-eval-after-load is not good. Try without with-eval-after-load.

balaji-dutt commented 4 years ago

I think with-eval-after-load is not good. Try without with-eval-after-load.

I thought the recommended practice is to use with-eval-after-load since this prevents errors when package cannot be found?

In any case I made some changes, but still seeing the same error message 😞

(defun my-private-layer/init-easy-hugo ()
  "Initialization of easy-hugo"
  (use-package easy-hugo
    :ensure t
    :config
   (setq easy-hugo-basedir "f:/Balaji/Development/notebook/"
          easy-hugo-server-flags "-D"
          easy-hugo-postdir "content/posts"
          easy-hugo-image-directory "static/img"
          easy-hugo-url "https://nb.balaji.blog"
          easy-hugo-preview-url "http://127.0.0.1:1313/"
          )
    (add-hook 'easy-hugo-mode-hook 'my-private-layer/easy-hugo-config)
    (lambda ()
      (setq flyspell-mode 1))
    )
  )
masasam commented 4 years ago

Try :init instead of :config.

balaji-dutt commented 4 years ago

Try :init instead of :config.

Can I just say thank you so much for the quick responses! 👍

But sadly changing to :init does not seem to help.

masasam commented 4 years ago

Try the following.

(defun my-private-layer/easy-hugo-config () (interactive) (evil-define-key (list 'normal 'insert 'visual 'motion) easy-hugo-mode-map "n" 'easy-hugo-newpost "D" 'easy-hugo-article "p" 'easy-hugo-preview "P" 'easy-hugo-publish "o" 'easy-hugo-open "d" 'easy-hugo-delete "e" 'easy-hugo-open "c" 'easy-hugo-open-config "f" 'easy-hugo-open "N" 'easy-hugo-no-help "v" 'easy-hugo-view "r" 'easy-hugo-refresh "g" 'easy-hugo-refresh "s" 'easy-hugo-sort-time "S" 'easy-hugo-sort-char "G" 'easy-hugo-github-deploy "A" 'easy-hugo-amazon-s3-deploy "C" 'easy-hugo-google-cloud-storage-deploy "q" 'evil-delete-buffer (kbd "TAB") 'easy-hugo-open (kbd "RET") 'easy-hugo-preview) (define-key global-map (kbd "C-c C-e") 'easy/hugo))

(use-package easy-hugo :ensure t :config ←or :init (setq easy-hugo-basedir "f:/Balaji/Development/notebook/" easy-hugo-server-flags "-D" easy-hugo-postdir "content/posts" easy-hugo-image-directory "static/img" easy-hugo-url "https://nb.balaji.blog" easy-hugo-preview-url "http://127.0.0.1:1313/" ) ) (add-hook 'easy-hugo-mode-hook 'my-private-layer/easy-hugo-config)

balaji-dutt commented 4 years ago

Hi @masasam I'm not sure if you specifically meant to remove the (defun my-private-layer/init-easy-hugo () ) part. However, if I remove that part, Spacemacs breaks on loading so I had to put it back.

No change in the error message after changing the sequence.

masasam commented 4 years ago

I think this is a problem with evil-define-key not working in your enviroment. I can't reproduce this issue because I don't use spacemacs, use-package and windows.

balaji-dutt commented 4 years ago

Hm I see. I have been able to use evil-define-key in other parts of my init.el so I'm not sure what's the issue. This is not a major loss since w still works, it's just that the n is the default in easy-hugo-help and I'm still learning easy-hugo so can't disable that altogether.

masasam commented 4 years ago

Have you try https://github.com/humanfactors/spacemacs-easy-hugo ?

balaji-dutt commented 4 years ago

@masasam Thanks for pointing me to that package. Rather that installing the layer directly, I realized he was using a different function to set the keys namely spacemacs/set-leader-keys-for-major-mode so I used that in my config as well.

I would still get an error if I directly invoked n in easy-hugo mode but typing SPC m n (which is what set-leader-keys does) works fine. You might want to point other Spacemacs users to this layer rather than the current link in the README.

masasam commented 4 years ago

@balaji-dutt I've added spacemacs-easy-hugo to the README. Thanks for your cooperation.