emacs-china / Spacemacs-rocks

Happy Hacking Emacs & Spacemacs (Simplified Chinese)
http://book.emacs-china.org
2.11k stars 325 forks source link

Spacemacs Rocks 第二季: Day 2 #24

Open zilongshanren opened 8 years ago

zilongshanren commented 8 years ago

原贴地址: https://emacs-china.org/t/21-emacs/52

ghost commented 8 years ago

师傅!我可以帮你上传 YouTube 我账号中的地址在这里 https://youtu.be/aQRZxaU3pAI 可以让需要的朋友先看。视频中我链接了这个 Issue。第三日之后我会将内容软换成 org-mode 的版本。内容好多,我得慢慢学下。:D 有任何需要帮助(帮助上传,更新文字版,和你的计划等等)的时候都直接发邮件给我(有推送),我会第一时间回复的。地址是 lixinyang1026@gmail.com

zilongshanren commented 8 years ago

@li-xinyang 赞,以后youtube上传就交给你啦 :smile:

ghost commented 8 years ago

好的!我等下也会将第一日的视频下载下来后,然后制作成播放清单方便大家观看。现有视频的播放清单在这里 https://www.youtube.com/playlist?list=PL-61yFRAEMlXDnsm3VHfrAm4oT6vVylRG 等下我会将其更新到 README 中。

ghost commented 8 years ago
(when (>= emacs-major-version 24)
    (require 'package)
    (package-initialize)
    (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)
    )

;; TODO: DO NOT KNOW WHAT IS 'cl
;; (require 'cl)

;; Add Packages
(defvar xinyang/packages '(
                company
                monokai-theme
                hungry-delete
                swiper
                counsel
                smartparens
                js2-mode
                nodejs-repl
                exec-path-from-shell
                )  "Default packages")

(setq package-selected-packages xinyang/packages)

(defun xinyang/packages-installed-p ()
    (loop for pkg in xinyang/packages
          when (not (package-installed-p pkg)) do (return nil)
          finally (return t)))

(unless (xinyang/packages-installed-p)
    (message "%s" "Refreshing package database...")
    (package-refresh-contents)
    (dolist (pkg xinyang/packages)
      (when (not (package-installed-p pkg))
        (package-install pkg))))

;; let emacs could find the execuable
(when (memq window-system '(mac ns))
  (exec-path-from-shell-initialize))

;; Better Default
;; ==================================================================
;; Disable Backup File
(setq make-backup-files nil)
;; Regular Replace Selection Behavior
(delete-selection-mode 1)
;; Auto Parenthesis Matching
(add-hook 'emacs-lisp-mode-hook 'show-paren-mode)
;; Enable Recent Files
(require 'recentf)
(recentf-mode 1)            
(setq recentf-max-menu-items 25)

;; Appearance Related Setting
;; ===================================================================
;; Hide Startup screen
(setq inhibit-splash-screen 1)
;; Default Full-screen Mode
(setq initial-frame-alist (quote ((fullscreen . maximized))))
;; Hide menu bar
(tool-bar-mode -1)
;; Hide scroll bar
(scroll-bar-mode -1)
;; Highlight Current Line
(global-hl-line-mode 1)
;; Show line number
(global-linum-mode 1)
;; Change cursor style
(setq-default cursor-type 'bar)

;; Package Related Setting
;; ===================================================================

;; Company Mode
;; -------------------------------------------------------------------
;; Enable global company mode
(global-company-mode t)

;; Help Functions
;; ===================================================================
;; Open Config Files (init.el)
(defun open-init-file()
  (interactive)
  (find-file "~/.emacs.d/init.el"))

;; Key Binding
;; ===================================================================
;; Quick Open Config File (init.el)
(global-set-key (kbd "C-c C-c") 'open-init-file

;; Open Recent Files List
(global-set-key (kbd "C-x C-r") 'recentf-open-files)

;; TODO: THE BINDINGS ARE NOT WORKING
;; Better Find Definition for Vairbale, Function and Key Binding
(global-set-key (kbd "C-h C-v") 'find-variable)
(global-set-key (kbd "C-h C-f") 'find-function)
(global-set-key (kbd "C-h C-k") 'find-function-on-key)

;; Org-mode Related Setting
;; ===================================================================

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(package-selected-packages (quote (company))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

卡在了安装插件的步骤了 一直显示 Symbol's function definition is void: loop 检查多遍 使用和你一样的配置(拷贝粘贴)也是同样的错误

第二日的文字版已更新完毕 但是还有些内容没有完全领悟 待我确认无误时就会 RP

https://github.com/li-xinyang/TL_EmacsRocks

zilongshanren commented 8 years ago

@li-xinyang 要使用loop 必须(require 'cl) 哦, cl是emacs lisp里面的common lisp扩展。

zilongshanren commented 8 years ago

@li-xinyang 另外,如果使用counsel来增强M-x,那么smex是可以不用安装的。

zilongshanren commented 8 years ago

@li-xinyang

;; TODO: THE BINDINGS ARE NOT WORKING
;; Better Find Definition for Vairbale, Function and Key Binding
(global-set-key (kbd "C-h C-v") 'find-variable)
(global-set-key (kbd "C-h C-f") 'find-function)
(global-set-key (kbd "C-h C-k") 'find-function-on-key)

为什么在你那边按键绑定无效呢? 直接M-x 可以调用对应的函数吗?

zilongshanren commented 8 years ago

@li-xinyang 看到你如此认真看视频,相信等这个系列结束,你一定能够掌握Emacs :smile:

ghost commented 8 years ago

绑定可以使用 M-x 也可以找到函数 我的意思是 C-h f find-function 可以找到对应的文档 但是使用 C-h C-f 就显示 Can't find library /usr/share/emacs/25.1.50/lisp/emacs-lisp/find-func.el

Google 了但是还没找到答案

师傅!我一定会掌握它的!

zilongshanren commented 8 years ago

@li-xinyang 另外 c-x b在激活ivy-mode以后,当我们设置(setq ivy-use-virtual-buffers t) 是可以显示recent files的,不用使用C-x C-r来打开recent file了。

你可以换一个函数,并不是所有的函数都能用find-function找到定义。你可以试试一些packages里面的函数,比如C-h C-f global-company-mode。 系统内置的函数,变量和改键有时候找不到,但是下载的packages里面的都可以找到。

kirchhoff commented 8 years ago

赞一个教程,我也在认真的学习,虽然用了emacs有一段时间,但是还没有很深的体会,顺便问一下我在C-x d进行dired目录的时候,使用+创建目录,如果我想创建一个我目前还不存在的目录(比如您在视频中提到的org目录),如何强制创建而不顾emacs的推荐呢?因为每次emacs总是会提示候选目录名称(这些名称都是存在了的目录)。非常感谢!

ghost commented 8 years ago

OS X 下使用早上配置好的 init.el 文件,出现奇怪的问题一直提示下面的错误,

Warning (initialization): An error occurred while loading ‘/Users/X/.emacs.d/init.el’:

error: Package ‘hungry-delete-’ is unavailable

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the ‘--debug-init’ option to view a complete error backtrace.

所有的 package 在下载过程中都会在末尾加上 -hungry-delete 变为 hungry-delete-。 我删除了所有的配置中的 hungry-delete 依然会有这个错误,删除了注释错误也同样存在,会不是是 Encoding 的原因?或者是我在安装的函数中多输入了字符 - ? 下面是现在的插件部分的配置与上午的时候基本相同。

在 Ubuntu 14.0.4 下并无这种问题,配置文件早上也是在 Emacs 中做的编辑,但是后来又在 Atom 和 GitHub 页面编辑器中做过修改。

(defvar xinyang/packages '(
               ;; --- Auto-completion ---
               company
               ;; --- Better Editor ---
               hungry-delete
               swiper
               counsel
               smartparens
               ;; --- Major Mode ---
               js2-mode
               ;; --- Minor Mode ---
               nodejs-repl
               exec-path-from-shell
               ;; --- Themes ---
               ;; monokai-theme
               solarized-theme
               ) "Default packages")

(setq package-selected-packages xinyang/packages)
(defun xinyang/packages-installed-p ()
    (loop for pkg in xinyang/packages
          when (not (package-installed-p pkg)) do (return nil)
          finally (return t)))
(unless (xinyang/packages-installed-p)
    (message "%s" "Refreshing package database...")
    (package-refresh-contents)
    (dolist (pkg xinyang/packages)
      (when (not (package-installed-p pkg))
        (package-install pkg))))
;; Find Executable Path on OS X
(when (memq window-system '(mac ns))
  (exec-path-from-shell-initialize))
niuniuzh commented 8 years ago

@li-xinyang 我也遇到这样的错误,后面加了一个 -,您解决了么?

zilongshanren commented 8 years ago

@missnote @li-xinyang 能否把你们各种的配置地址发一下,我看看是啥问题。

zilongshanren commented 8 years ago

@li-xinyang @missnote 你们使用的源是哪个?

image

我这边没有问题哦。

ghost commented 8 years ago

师傅,什么是配置地址? 这个吗?

$ tree -L 2
tree.
├── auto-save-list
├── elpa
│   ├── archives
│   ├── company-0.8.12
│   ├── company-readme.txt
│   └── swiper-0.7.0
├── init.el
└── init.el~

5 directories, 3 files

好像看到问题了

cat(when (>= emacs-major-version 24)
    (require 'package)
    (package-initialize)
    (add-to-list 'package-archives '("melpa" . "http://melpRETa.org/packages/") t)
    )

我找到错误了,我不知道什么时候在 URI 里面加了一个 RET 。@missnote 如果你是抄文字版的配置可能 URL 也有问题。我将立刻修改这个错误。

解决方法将开头的五行替换掉

(when (>= emacs-major-version 24)
    (require 'package)
    (package-initialize)
    (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)
    )

非常抱歉,我编辑的疏忽造成了你的困扰。

成功安装后的 ~/.emacs.d 目录

$ tree ~/.emacs.d -L 2
tree/Users/X/.emacs.d
├── auto-save-list
├── elpa
│   ├── archives
│   ├── company-0.8.12
│   ├── company-readme.txt
│   ├── counsel-20160326.915
│   ├── dash-20160306.1222
│   ├── exec-path-from-shell-20160112.2246
│   ├── hungry-delete-20151203.1314
│   ├── js2-mode-20160326.1758
│   ├── nodejs-repl-20151229.603
│   ├── smartparens-20160324.1541
│   ├── solarized-theme-20160311.1447
│   └── swiper-0.7.0
└── init.el

13 directories, 2 files
zilongshanren commented 8 years ago

@li-xinyang https://github.com/zilongshanren/Spacemacs-rocks/blob/master/episode2/day2/init.el

zilongshanren commented 8 years ago

@kirchhoff 安装了ivy之后,貌似Emacs不再提示已经存在的目录了呀?你试一下?

niuniuzh commented 8 years ago

@zilongshanren 好像是没有下载下来,不知道是不是网络问题,.emacs.d\elpa\文件下没有。配置都是一样的。

niuniuzh commented 8 years ago

@zilongshanren 有时候报验证签名失败,.emacs.d\elpa\文件下没有js2-mode-20150909.tar.sig

Warning (initialization): An error occurred while loading ‘c:/Users/admin/AppData/Roaming/.emacs.d/init.el’:

Failed to verify signature: js2-mode-20150909.tar.sig

To ensure normal operation, you should investigate and remove the cause of the error in your initialization file. Start Emacs with the ‘--debug-init’ option to view a complete error backtrace

kirchhoff commented 8 years ago

@zilongshanren 你好,比如我在home目录下想创建spacemacs目录,就会出现如下的候选项

2016-03-29 11 22 43

唔,我该如何确定我只想创建spacemacs目录呢?非常感谢您的帮助!

LonglyCode commented 8 years ago

@kirchhoff 应该是使用ivy自动补全的问题,问题链接在此https://github.com/abo-abo/swiper/issues/183,解决方法就是在你上图的状态下直接按 C-M-j 就立即生成你输入的内容。

zilongshanren commented 8 years ago

@kirchhoff 我的办法是在想要创建的目录后面加一个 / 就解决了。

zilongshanren commented 8 years ago

@missnote 我感觉你需要梯子。。。 我这边用了梯子,安装从没出过问题哦。

kirchhoff commented 8 years ago

@LonglyCode 你的回答圆满的解决了我的问题,非常感谢!

kirchhoff commented 8 years ago

@zilongshanren 不行呢,候选项还是会留下.emacs.d_spacemacs/ ,LonglyCode方法很好

zilongshanren commented 8 years ago

@kirchhoff 果然,感谢 @LonglyCode

niuniuzh commented 8 years ago

@zilongshanren 看来我的梯子不行。。。。。买了shaodw也不行。。。。

zilongshanren commented 8 years ago

@missnote shadow还需要配合proxifier

niuniuzh commented 8 years ago

@zilongshanren thank you!终于能下载了,早看git就好了,还在找其他的。。。非常感谢,完美!

Yueyec commented 8 years ago

@missnote 我也出现这问题,用了proxychains也不行,我也用的shadow这问题确实是梯子不行导致的吗?

ghost commented 8 years ago

@Yueyec http://elpa.emacs-china.org/ 换这个

有问题去社区 emacs-china.org 这里以后只提项目相关的问题。

xuchunyang commented 8 years ago

@zilongshanren 有时候报验证签名失败,.emacs.d\elpa\文件下没有js2-mode-20150909.tar.sig

要是我没搞错的话,melpa 本来就没有签名,只有 Gnu Elpa 有签名。Emacs 默认设置应该是检查签名,但根本没有签名的话也可以安装。

Tom-Goong commented 8 years ago

(add-to-list my/packages 'monokai-theme)

添加这句话,启动报错,

debug-init启动后,错误如下: Debugger entered--Lisp error: (wrong-type-argument symbolp (company hungry-delete swiper counsel smartparens js2-mode nodejs-repl exec-path-from-shell monokai-theme)) add-to-list((company hungry-delete swiper counsel smartparens js2-mode nodejs-repl exec-path-from-shell monokai-theme) monokai-theme) eval-buffer(#<buffer load> nil "c:/Users/admin/AppData/Roaming/.emacs.d/init.el" nil t) ; Reading at buffer position 1096 load-with-code-conversion("c:/Users/admin/AppData/Roaming/.emacs.d/init.el" "c:/Users/admin/AppData/Roaming/.emacs.d/init.el" t t) load("c:/Users/admin/AppData/Roaming/.emacs.d/init" t t)

[0 "\205\266

注销掉这句就可以运行,请问为什么呀。新手

xuchunyang commented 8 years ago

因为参数的类型不符,函数 add-to-list 的第一个参数应该是一个值为 list 的变量(也就是一个 symbol),而你传给它的是一个 list,不是 symbol。你应该 quote my/packages 以避免它被执行,就像你对第二个参数做的那样。

niuniuzh commented 8 years ago

@Yueyec 应该是网络问题,有时候也下载完了,但是会报错,多下载几次,没有报错就ok了,其余的我也是不懂!o(^▽^)o

Tom-Goong commented 8 years ago

@xuchunyang 多谢,这样修改就对了。。但是教程中,是像我我那样添加的

anxsec commented 8 years ago

@missnote @li-xinyang 对于error: Package ‘hungry-delete-’ is unavailable的问题,参见这个链接

alan717 commented 6 years ago

请问我添加

(setq package-selected-packages my/packages)
(defun my/package-installed-p ()
  (loop for pkg in my/packages
        when (not (package-installed-p pkg)) do (return nil)
        finally (return t)))
(unless (my/packages-installed-p)
  (message "%s" "Refreshing package database...")
  (package-refresh-contents)
  (dolist (pkg my/packages)
    (when (not (package-installed-p pkg))
      (package-install pkg))))

出来这个警告

Symbol's function definition is void: my/packages-installed-p

To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file.  Start Emacs with
the ‘--debug-init’ option to view a complete error backtrace.

然后加--debug-init 参数出来这个结果.


Debugger entered--Lisp error: (void-function my/packages-installed-p)
  (my/packages-installed-p)
  (if (my/packages-installed-p) nil (message "%s" "Refreshing package database...") (package-refresh-contents) (let ((--dolist-tail-- my/packages) pkg) (while --dolist-tail-- (setq pkg (car --dolist-tail--)) (if (not (package-installed-p pkg)) (progn (package-install pkg))) (setq --dolist-tail-- (cdr --dolist-tail--)))))
  eval-buffer(#<buffer  *load*> nil "/home/poi/.emacs.d/init.el" nil t)  ; Reading at buffer position 3390
  load-with-code-conversion("/home/poi/.emacs.d/init.el" "/home/poi/.emacs.d/init.el" t t)
  load("/home/poi/.emacs.d/init" t t)
  #[0 "\205\266
xuchunyang commented 6 years ago

出来这个警告

这是个错误(Error),不是警告(Warning)

Symbol's function definition is void: my/packages-installed-p

它的意思是你没有定义这个函数,你上面定义的是 my/package-installed-p,不是 my/packages-installed-p