View PDF in Emacs

Be default PDF files are opened by Docviewer in Ubuntu distributes. Yet, there is a more convenient PDF tool, aptly named pdf-tools that works well with Emacs. The installation of pdf-tools is straight forward. Below is what I did.

sudo apt install libpng-dev zlib1g-dev
sudo apt install libpoppler-glib-dev
sudo apt install libpoppler-private-dev

After that, go to Emacs and use the package-install to install

package-install pdf-tools

Finally, add the following line to the .emacs file. And make sure that if you are displaying line numbers in emacs, make sure it is disabled in pdf-view-mode. Here what I used is to just enable line number display in prog-mode.

(add-hook 'prog-mode-hook 'linum-on)


Switch Frame Quickly in Emacs

Switching between multiple frames in Emacs is a pain when you have more than two frames open. I just noticed that the ace-window package offers the function for fast frame switching. All you need to do is to put the following configuration to the .emacs file and use the “M-o” key combination then pickup the frame number in red, and you will switch to that frame.

(global-set-key (kbd "M-o") 'ace-window)

Open Virtual Box File through SSH with Emacs

The Emacs Dire mode works for remote files through SSH and FTP. Detailed documentation about how to open remote files from Emacs can be found here. With a proper setting, one can use Emacs to work directly to open files in Virtual Box without having to set the target directory as a shared resource between the host and client. In a previous post, I showed how to add the private key used by Vagrant to access Virtual Box and find out the port number for SSH connection, in this post, you will see how it will benefit you as an Emacs user.


Once you are in Emacs, use the command “Ctrl x + Ctrl f” to open file just like you would with a local file, then you use the command above to open the remote directory “/vagrant” in a Emacs frame. Of course, this command requires that you have already added the private key to your host SSH key settings and 2222 is the correct port number.


Emacs File Explorer Solution

I just came across the Treemacs package that I wish I knew earlier. Treemacs is an Emacs package that provides a tree layout file explorer for Emacs. With Treemacs, one can easily navigate through a big project tree all in Emacs.

Installation is simple through ELPA. I have the following lines in my .emacs configuration:

(setq package-archives '(("gnu" . "") ))
(when (>= emacs-major-version 24)
  (require 'package)
  (add-to-list 'package-archives '("melpa" . "") t)    

In Emacs, run “M-x package-refresh-contents”, then “package-install treemacs.” After installation, run “M-x treemacs” brings up the tree view.