pacmatic icon indicating copy to clipboard operation
pacmatic copied to clipboard

Use emacs ediff instead of vim -d

Open jbranso opened this issue 9 years ago • 5 comments

Hello!

This is a feature request!

I'm trying to use emacs' ediff merge tool instead of vim's. I've found this code snippet and put it in my .bashrc:

Ediff can now be called via the command line!

function ediff() { if [ "X${2}" = "X" ]; then echo "USAGE: ediff <FILE 1> <FILE 2>" else # The --eval flag takes lisp code and evaluates it with EMACS # the -nw means use emacs non-graphically or in the terminal emacs -nw --eval "(ediff-files "$1" "$2")" fi }

make pacmatic use ediff as its program to fix pacsaves and pacnews.

export pacdiff_program="ediff"

End of .bashrc

Now when I run pacmatic, I get: Usage: pacmatic -options [packages] Pacmatic is a pacman wrapper that takes care of menial but critial tasks. These include Checking the archlinux.org news Summarizing the arch-general mailing list Reminding if it has been a while since the last sync Reporting pacnew files Editing pacnew files

The following environment variables can be set warn_time="86400" # (seconds) rss_feed="https://www.archlinux.org/feeds/news/" log_file="/var/log/arch-news.log" pacdiff_program="ediff" pacman_program="pacman" mail_list="https://lists.archlinux.org/pipermail/arch-general/2015-February.txt.gz" pacman_log="/var/log/pacman.log"

To use Pacmatic's functionality in a script, source with . /usr/bin/pacmatic --as-lib

So, emacs' ediff can be used from the command line, but unfortunately it doesn't work with pacmatic. When I type y or Y when I want to edit .pac* files, pacmatic ends. If I knew more about bash scripting I might propose a solution, but I'm not sure how to implement this feature. Am I missing something? Is there a way to use emacs' ediff instead of vim -d?

Thanks!

jbranso avatar Feb 18 '15 01:02 jbranso

This is not a Pacmatic issue or even a feature request. The bit you are missing is how the shell works.

The short and sweet answer is to

echo -e '#!/bin/sh\nemacs -nw --eval "(ediff-files \"$1\" \"$2\")"' > /usr/bin/ediff
chmod +x /usr/bin/ediff

as root and then do the pacdiff_program="ediff"

keenerd avatar Feb 18 '15 02:02 keenerd

Thanks for the help! I've done what you recommenced, but I still have issues. I still cannot use ediff instead of vim -d. Here's the output of ls -l ediff, cat ediff, and pacmatic.

$ cat /usr/bin/ediff
#!/bin/sh
emacs -nw --eval "(ediff-files \"$1\" \"$2\")"

$ ls -l /usr/bin/ediff
-rwxr-xr-x   1 root           root           57 2015-02-18 10:34 /usr/bin/ediff

$ pacmatic
Usage: pacmatic -options [packages]

Pacmatic is a pacman wrapper that takes care of menial but critial tasks.

These include
    Checking the archlinux.org news
    Summarizing the arch-general mailing list
    Reminding if it has been a while since the last sync
    Reporting pacnew files
    Editing pacnew files

The following environment variables can be set
    warn_time="86400"  # (seconds)
    rss_feed="https://www.archlinux.org/feeds/news/"
    log_file="/var/log/arch-news.log"
    pacdiff_program="ediff"
    pacman_program="pacman"
    mail_list="https://lists.archlinux.org/pipermail/arch-general/2015-February.txt.gz"
    pacman_log="/var/log/pacman.log"

To use Pacmatic's functionality in a script, source with
    . /usr/bin/pacmatic --as-lib 

Now when I run pacmatic...

$ sudo pacmatic -Syu
[sudo] password for joshua: 
Recent ML chatter: 
:: Synchronizing package databases...
 core is up to date
 extra is up to date
 community is up to date
 multilib is up to date
 pipelight is up to date
:: Starting full system upgrade...
 there is nothing to do

1 pacnew files found (0 added).  Update files now? (Y/n)  y
$

The emacs ediff program does not open. Pacmatic ends. BUT if I do this in my home directory,

$ emacs -nw --eval "(ediff-files \"README\" \"RMAIL\")"

Emacs' ediff opens just fine in the terminal. Do you have any ideas of what I did wrong?

jbranso avatar Feb 18 '15 15:02 jbranso

the output from pacmatic looks eerily familiar.. from this thread here: https://bbs.archlinux.org/viewtopic.php?id=193477

try $ find /etc/ \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \) 2> /dev/null | wc -l and $ find /etc/ \( -name \*.pacnew -o -name \*.pacorig -o -name \*.pacsave \)

in my case, there was a pacsave file that wouldnt open. There seems to be an issue if the file is anything but a pacnew. Possibly this is the issue, not ediff.

pm0u avatar Feb 21 '15 03:02 pm0u

When I run the first command my output is:

3

When I run the second command my output is:

/etc/gshadow.pacnew
/etc/yaourtrc.pacsave
/etc/group.pacnew

When pacmatic runs, it still uses vim -d. Even though running $ pacmatic outputs

pacdiff_program="ediff"

When I run

sudo ediff /etc/gshadow /etc/gshadow.pacnew 

Emacs opens the two files in ediff. So I still can't use ediff. I'm not sure what the problem is.

jbranso avatar Feb 26 '15 16:02 jbranso

I don't know why this bug is left open for so long.

the pacdiff script is called by pacmatic without any arguments, so ediff is not a candiate for its replacement. You don't need to replace pacdiff, but just have it use your ediff script rather than "vim -d" to edit each change. This is done by setting the DIFFPROG environment variable:

export DIFFPROG=ediff

This also allows just calling pacdiff to resolve .pacsave and .pacnew files even when not using pacmatic.

Note that if you are using sudo, you need to make sure the DIFFPROG is set in your root environment, which depends on you sudo setup. I reset my environment, so a /etc/sudoers line like:

Defaults env_keep += DIFFPROG

might be needed to use any DIFFPROG environent variable set for your normal login account.

barryfm avatar Apr 25 '16 15:04 barryfm