kuanyui / hexo.el

Use Hexo in Emacs elegantly
86 stars 14 forks source link

hexo-new error #14

Open semgilo opened 7 years ago

semgilo commented 7 years ago

hexo-new type url display error message: wrong-type-argument stringp nil

kuanyui commented 7 years ago

Thanks for your reporting, but your bug report is too simplified. M-x toggle-debug-on-error and try again, post the full error message.

And please write in English because not everyone understand it.

semgilo commented 7 years ago

thanks i type "test" when show url tips showing

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  file-name-nondirectory(nil)
  file-name-sans-extension(nil)
  (concat (file-name-sans-extension created-md-file-path) ".org")
  (let* ((stdout (shell-command-to-string (format "%s new '%s'" hexo-command (hexo--new-read-url-from-user)))) (created-md-file-path (progn (string-match "Created: \\(.+\\)$" stdout) (match-string 1 stdout))) (created-org-file-path (concat (file-name-sans-extension created-md-file-path) ".org"))) (cond ((eq hexo-new-format (quote org)) (rename-file created-md-file-path created-org-file-path) (find-file created-org-file-path) (goto-char 0) (replace-regexp "date:.*" (concat "#+DATE: " (format-time-string "<%Y-%m-%d %a %H:%M>"))) (goto-char 0) (replace-regexp "^ *tags: *" "#+TAGS: ") (goto-char 0) (flush-lines "---") (goto-char (point-max)) (insert "#+LAYOUT: \n#+CATEGORIES: \n") (goto-char 0) (replace-regexp "title: .+$" (format "#+TITLE: \"%s\"" (read-from-minibuffer "Article Title: " (car minibuffer-history))))) (t (find-file created-md-file-path) (goto-char 0) (replace-regexp "title: .+$" (format "title: \"%s\"" (read-from-minibuffer "Article Title: " (car minibuffer-history)))))) (save-buffer))
  hexo--new-interactively("/Users/semgilo/Documents/Github/hexo/node_modules/hexo/bin/hexo")
  (cond ((not (hexo-find-root-dir)) (message "You should run this command under a Hexo repo, or in a hexo-mode buffer")) ((null hexo-command) (message "Not found hexo command in your node_modules/ nor $PATH,")) (t (hexo--new-interactively hexo-command)))
  (let ((hexo-command (hexo-find-command))) (cond ((not (hexo-find-root-dir)) (message "You should run this command under a Hexo repo, or in a hexo-mode buffer")) ((null hexo-command) (message "Not found hexo command in your node_modules/ nor $PATH,")) (t (hexo--new-interactively hexo-command))))
  hexo-new()
  funcall-interactively(hexo-new)
  call-interactively(hexo-new nil nil)
  command-execute(hexo-new)
kuanyui commented 7 years ago

Hmm... It seems hexo new command was not executed correctly.

  1. Has hexo been installed in your system or ~/your/hexo/repo/dir/node_modules/ ?
  2. Can you give me your hexo version?
semgilo commented 7 years ago

I had installed it at ~/Documents/Github/hexo I can execute the command in Terminal ![Uploading Screen Shot 2017-04-02 at 8.17.41 AM.png…]()

hexo-cli: 1.0.2
os: Darwin 15.6.0 darwin x64
http_parser: 2.7.0
node: 7.7.4
v8: 5.5.372.42
uv: 1.11.0
zlib: 1.2.11
ares: 1.10.1-DEV
modules: 51
openssl: 1.0.2k
icu: 58.2
unicode: 9.0
cldr: 30.0.3
tz: 2016j
semgilo commented 7 years ago

I can use "R" to rename "D" to delete and other "RTN" to open

kuanyui commented 7 years ago

I still don't know what hexo version is you're using. This is mine, runs hexo 3.2.2.

$ ./node_modules/hexo/bin/hexo version                                                                                                                                                                         (04-02 09:34)
hexo: 3.2.2
hexo-cli: 1.0.2
os: Darwin 15.6.0 darwin x64
http_parser: 2.7.0
node: 7.5.0
v8: 5.4.500.48
uv: 1.10.2
zlib: 1.2.8
ares: 1.10.1-DEV
modules: 51
openssl: 1.0.2k
icu: 58.2
unicode: 9.0
cldr: 30.0.3
tz: 2016j
semgilo commented 7 years ago

sorry, Cut the less

hexo: 3.2.2
hexo-cli: 1.0.2
os: Darwin 15.6.0 darwin x64
http_parser: 2.7.0
node: 7.7.4
v8: 5.5.372.42
uv: 1.11.0
zlib: 1.2.11
ares: 1.10.1-DEV
modules: 51
openssl: 1.0.2k
icu: 58.2
unicode: 9.0
cldr: 30.0.3
tz: 2016j
kuanyui commented 7 years ago

What is returned after you run (in terminal) hexo new "hello-word"?

semgilo commented 7 years ago

INFO Created: ~/Documents/Github/www.lanhuzi.com/source/_posts/hello-word.md

kuanyui commented 7 years ago

Sounds quite unreasonable... From the *Backtrace* message you've provided, the problem should be hexo.el doesn't really find & execute hexo new command. Can you see any newly created files after you M-x hexo-new and get error message?

semgilo commented 7 years ago

None be created, just output "wrong type argument strings nil"

kuanyui commented 7 years ago

Ok, ultimate debug method: create a file ~/Documents/Github/www.lanhuzi.com/source/.posts/test then paste:

(message (shell-command-to-string (format "%s new '%s'"
                                          (hexo-find-command)
                                          "testttttt")))

Then M-x eval-buffer, see what returned

semgilo commented 7 years ago

~/Documents/Github/www.lanhuzi.com/source/.posts/test the ".post" or "_post"?

kuanyui commented 7 years ago

sorry, _post. Whatever, as long as the file is under your hexo-blog-repository-directory

semgilo commented 7 years ago
Debugger entered--Lisp error: (void-variable post)
  eval-buffer()  ; Reading at buffer position 8
  funcall-interactively(eval-buffer)
  call-interactively(eval-buffer record nil)
  command-execute(eval-buffer record)
  execute-extended-command(nil "eval-buffer" "eval-buffer")
  funcall-interactively(execute-extended-command nil "eval-buffer" "eval-buffer")
  call-interactively(execute-extended-command nil nil)
  command-execute(execute-extended-command)
kuanyui commented 7 years ago

Oh my... Don't paste other thing into the file. The file can contain only:

(message (shell-command-to-string (format "%s new '%s'"
                                          (hexo-find-command)
                                          "testttttt")))

Then M-x eval-buffer in this file's buffer.

semgilo commented 7 years ago
screen shot 2017-04-02 at 11 35 17 am
semgilo commented 7 years ago
screen shot 2017-04-02 at 11 37 26 am
kuanyui commented 7 years ago

I mean M-x eval-buffer in this file's buffer, instead of *Hexo* buffer.

semgilo commented 7 years ago

sorry, i am newer for emacs

screen shot 2017-04-02 at 11 48 59 am
kuanyui commented 7 years ago

How about (message (hexo-find-command)) ?

semgilo commented 7 years ago

eval-buffer (message (format "%s new '%s'" (hexo-find-command) "testttttt"))

screen shot 2017-04-02 at 1 30 27 pm
kuanyui commented 7 years ago

I guess I know where the problem is. hexo.el execute hexo command, which is actually the file YOUR_HEXO_REPO/node_modules/hexo/bin/hexo, whose the content is:

#!/usr/bin/env node

'use strict';

require('hexo-cli')();

Now you can know why your Emacs returned env: node: No such file or directory ,and in fact, hasn't really executed hexo at all.

In Unix-like system, this is ok; but in Windows, I don't know what's the behavior and how to execute it. If you can tell me how to execute it under Windows then I may can fix this problem.

semgilo commented 7 years ago

but i use mac, i don't know windows how to execute it

kuanyui commented 7 years ago

Oops, sorry, I mixed you up with another bug (happened only in Windows) which I just fixed in tldr.el today.... Hmmm, you use Mac, I cannot understand why you still encounter this problem...

kuanyui commented 7 years ago

Can you execute YOUR_HEXO_REPO/node_modules/hexo/bin/hexo correctly in Emacs? (e.g. M-! /PATH/TO/YOUR/HEXO/REPO/node_modules/hexo/bin/hexo)

semgilo commented 7 years ago

i can execute command in Terminal but it can't be found in emacs shell command , it seems diff env, I echo $PATH both in Terminal and shell command. so i "setenv PATH" and modify permissions, and try again, it work ok now

semgilo commented 7 years ago

now, I can new file,but it is markdown format, I had created .dir-locals.el in my blog root dir

kuanyui commented 7 years ago

Have you made variable hexo-new-format safe?

semgilo commented 7 years ago

how to do it ?

Develle commented 7 years ago

For Mac install package exec-path-from-shell

Make Emacs use the $PATH set up by the user's shell

semgilo commented 7 years ago

@Develle thanks

kuanyui commented 6 years ago

Is this issue still existing?

semgilo commented 6 years ago

hexo-new-format can't be changed by user, now i modify hexo-new-format equal org default