Skip to content

sje30/emacs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 

Repository files navigation

Notes about Emacs

dired – Create a dired buffer of files listed on stdin.

Often I find I would like to create a list of files using some unix command and have a dired buffer containing those files. This short script does that. It creates a temporary file .my-dired.el which is not deleted by default for debugging purposes.

#!/usr/bin/perl
# this file generated from <<filename()>>
use Cwd qw(getcwd);

$elfile = ".my-dired.el";
    
## (dired-other-window '("my dired" "~" "txt" "~/txt/add.tex" ".emacs" "foreign.pdf"))
open(OUT, '>', $elfile) or die $!;

$buffer = "my-dired";  
$dir = getcwd();


## Can use `dired' or `dired-other-window'.

print OUT "(dired '(\"$buffer\" \"$dir\"\n";

while(<>) {
    chomp;
    print OUT "\"$_\"\n";
}

print OUT "))\n";

close(OUT);

system("emacsclient -n -e '(load-file \"$elfile\")'");

##unlink($elfile);


Example: find all the PDFs and open in dired.

fd -x pdf | dired

Example: show all files that are currently registered

git ls-files –exclude-standard –other | dired

references

magit/magit#4054

Alternative C-x 3 and C-x 2

The default behaviour for C-x 2 (split-window-below) is to divide a window into two, showing the same buffer in each window. I would prefer the two windows to show the most recent two buffers. Alex Branham had solved this problem before https://gitlab.com/jabranham/emacs/blob/master/init.el#L2537

I simply added the extra configuration to switch-to-prev-buffer-skip so that if you use C-x 2 or C-x 3 n times, then you see the n+1 recent buffers. Thank you Alex.

;; Split the windows sensibly.
;; https://gitlab.com/jabranham/emacs/blob/master/init.el#L2537
(defun my/split-below-last-buffer (prefix)
    "Split the window above/below and display the previous buffer.
If prefix arg is provided, show current buffer twice."
    (interactive "p")
    (split-window-below)
    (other-window 1 nil)
    (if (= prefix 1)
        (switch-to-next-buffer)))

(defun my/split-right-last-buffer (prefix)
  "Split the window left/right and display the previous buffer
If prefix arg is provided, show current buffer twice."
  (interactive "p")
  (split-window-right)
  (other-window 1 nil)
  (if (= prefix 1) (switch-to-next-buffer)))

(global-set-key (kbd "C-x 2")  'my/split-below-last-buffer)
(global-set-key (kbd "C-x 3")  'my/split-right-last-buffer)
(setq switch-to-prev-buffer-skip 'this)

Screenshot:

splitting-windows.gif

using pdf-tools via xdg-open

I use mu4e to read email, which opens pdf attachments using xdg-open. So, to get mu4e to open pdfs attachments using pdf-tools, I needed to configure xdg-open accordingly. This required two steps, below. I also use the following setting in mu4e:

(setq mu4e-view-use-gnus t)

Create a pdf-tools.desktop

This file lives in ~/.local/share/applications/pdf-tools.desktop

[Desktop Entry]
Encoding=UTF-8
Version=0.1
Type=Application
NoDisplay=true
Exec=emacsclient %u
Name=pdf-tools
Comment=Use Emacs to open pdf files

Tell xdg-mine to use pdf-tools.desktop to read pdfs

xdg-mime default pdf-tools.desktop application/pdf

This updates the list in ~/.config/mimeapps.list

You should then find that xdg-open file.pdf opens the file in Emacs, and (at least for me), pdf-attachments from mu4e also open in Emacs.

mu4e-view-save-all-attachments

mu4e-view-save-all-attachments.el is a script for mu4e 1.6.x onwards to save all attachments from the article buffer.

noweb

Taken from https://www.reddit.com/r/orgmode/comments/kmpfpf/adding_tangle_results_to_tangle_file/

(buffer-file-name)

About

my notes about emacs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published