我正在使用Bash on Ubuntu on Windows程序来使用Emacs编写C++代码。 目前,我可以使用键盘快捷键编写所有内容,但是,我想用鼠标选择文本或使用鼠标设置标记,而不总是必须使用键盘。
为了获得X Window系统,我已经执行了sudo apt-get install xserver -xorg
,但Emacs仍在终端编辑器中运行。
我不知道要使用哪些其他命令或者如何启动X Window。
我正在使用Bash on Ubuntu on Windows程序来使用Emacs编写C++代码。 目前,我可以使用键盘快捷键编写所有内容,但是,我想用鼠标选择文本或使用鼠标设置标记,而不总是必须使用键盘。
为了获得X Window系统,我已经执行了sudo apt-get install xserver -xorg
,但Emacs仍在终端编辑器中运行。
我不知道要使用哪些其他命令或者如何启动X Window。
Windows bash不支持X Server。但是,使用Windows X Server端口(如MobaXTerm、XMing或vcXsrv)与Windows bash一起使用可以解决问题。有些事情可以直接使用(gvim可以,)emacs需要更多的努力。
以下是我如何使其工作的方法:
安装MobaXterm。很可能你也可以用XMing使其工作,但我只测试过MobaXterm。更新:已经测试了vcXsrv和XMing(付费版本)。基本上都可以,但我可能会坚持使用MobaXTerm。
安装emacs 25.1快照。原因:Ubuntu 14.04带有emacs 24.3,它无法与Windows bash和MobaXTerm X server配合使用(不知道为什么,而且它太旧了)。
使用以下命令安装快照:
sudo add-apt-repository ppa:ubuntu-elisp/ppa
sudo apt-get update
sudo apt-get install emacs-snapshot
sudo update-alternatives --config emacs
选择emacs-snapshot
确保设置DISPLAY
export DISPLAY=localhost:0.0
运行MobaXTerm(您不需要做任何事情,只需启动它 - 当需要时它会启动X服务器。)
在bash中运行emacs并享受它。
仍然存在一个问题,并且在我测试的所有三个软件包中都持续存在(MobaXTerm、XMing和vcXsrv)。Emacs会坚持初始框架大小,并且在窗口大小调整时不会调整其框架大小。菜单栏也有同样的问题 - 当菜单栏被禁用时,emacs不会回收其空间,而是保留为灰色矩形。这个问题似乎是emacs在Windows bash上特有的 - gvim和其他GUI程序似乎工作正常。此外,使用Windows上的任何X服务器在Linux上运行emacs 25.1也可以正常工作。我尝试使用不同的GUI设置(GTK 2.0等)构建emacs,但是Windows bash上的emacs制作卡住了。如果我找到解决方法,我会发布更新。
更新09/24/2017 根据Jarett在你的init.el
中添加以下内容应该可以解决框架调整大小的问题:
(setq frame-resize-pixelwise t)
我不再使用安装了bash的Windows系统,因此无法进行测试。
emacs -g 200x50
。不幸的是,这对于 emacsclient
不起作用。 - Yuri Steinschreiberexport
命令放入您的.bashrc
文件中。重点部分非常棘手,我已经尝试过了,要点是 - 几乎不可能做到。 - Yuri Steinschreiber(setq frame-resize-pixelwise t)
非常好用。我正在WSL2上运行带有Ubuntu的VcXsrv,这个问题让我抓狂了。谢谢你。还要感谢Jarett,他似乎不再使用该程序了。 - theherkmkdir ~/build-emacs24
cd ~/build-emacs24
wget https://ftp.gnu.org/gnu/emacs/emacs-24.5.tar.xz
sudo apt-get install libxaw7-dev libncurses5-dev
tar xvf emacs-24.5.tar.xz
cd emacs-24.5
./configure --without-dbus --without-gconf --without-gsettings --with-x-toolkit=athena
现在,我们已经准备好构建Emacs了。但在此之前,我们需要稍微调整一下内核,否则构建很快就会失败。(如果您感兴趣,可以在emacs源代码的"etc/PROBLEMS"中找到详细解释,这里不再赘述。)这只是在构建阶段需要做的。一旦您安装了新的Emacs,就不需要再次进行此操作。
sudo sh -c "echo 0 > /proc/sys/kernel/randomize_va_space"
现在让我们进入漫长的构建过程,您可能会在构建过程中遇到整个系统变慢的情况,您可以减少构建中使用的线程数(这里我使用“4”表示2核4线程的英特尔CPU,请勿使用大于支持线程数(cat / proc / cpuinfo)的数字,否则速度会变得更慢。)
time nice make -j 4
sudo make install
/usr/local/bin/emacs &
(defvar fix-frame-white-border-last-check 0)
(defun current-sec ()
(let ((currtime (current-time)))
(logior (lsh (car currtime) 16) (cadr currtime))))
(defun fix-frame-white-border-uow (&optional frame)
(when (> (- (current-sec) fix-frame-white-border-last-check) 2)
(setf frame (or frame (selected-frame)))
(let ((width (frame-width frame))
(height (frame-height frame)))
(set-frame-size frame (1- width) height)
(set-frame-size frame width height))
(setq fix-frame-white-border-last-check (current-sec))))
(advice-add 'menu-bar-open :after #'fix-frame-white-border-uow)
(add-hook 'menu-bar-update-hook #'fix-frame-white-border-uow)
/proc/sys/kernel/randomize_va_space
恢复到其原始值。 - Antti Haapala -- Слава Україні/proc/sys/kernel/randomize_va_space
将恢复到其原始值。下次运行bash时,您可以看到它已恢复为“2”。 - Luke Leefclist
显示的字体,这使得Emacs对我来说非常丑陋。 - hal3默认的Emacs可以与Xming和其他选项一起使用。问题在于默认替代品指向emacs24-nox命令。您需要安装'emacs24',它会删除emacs24-nox。
$ sudo update-alternatives --query emacs
Name: emacs
Link: /usr/bin/emacs
....
Status: auto
Best: /usr/bin/emacs24-nox
Value: /usr/bin/emacs24-nox
$ sudo apt install emacs24
$ sudo update-alternatives --query emacs
Name: emacs
Link: /usr/bin/emacs
...
Status: auto
Best: /usr/bin/emacs24-x
Value: /usr/bin/emacs24-x
export DISPLAY=localhost:0.0