Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use emacs ediff instead of vim -d #25

Open
jbranso opened this issue Feb 18, 2015 · 5 comments
Open

Use emacs ediff instead of vim -d #25

jbranso opened this issue Feb 18, 2015 · 5 comments

Comments

@jbranso
Copy link

jbranso commented Feb 18, 2015

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!

@keenerd
Copy link
Owner

keenerd commented Feb 18, 2015

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"

@jbranso
Copy link
Author

jbranso commented Feb 18, 2015

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?

@pm0u
Copy link

pm0u commented Feb 21, 2015

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.

@jbranso
Copy link
Author

jbranso commented Feb 26, 2015

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.

@barryfm
Copy link

barryfm commented Apr 25, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants