%define _noVersionedDependencies	1
%define prereq_ge()  %(LC_ALL="C" rpm -q --queryformat 'Requires(pre):%%{NAME} >= %%{VERSION}' %1| grep -v "is not")
%define emacsen_pkgdir /usr/lib/emacsen-common/packages
%define	origname js2-mode
%define origver  20141118

Summary:      An improved JavaScript mode for GNU Emacs
Name:         %{origname}
Version:      %{origver}
Release:      1%{?_dist_release}

Source0:      https://github.com/mooz/%{name}/archive/%{version}.tar.gz
Source1:      %{origname}-install.sh
Source2:      %{origname}-remove.sh
Source3:      vine-default-%{origname}.el
Source4:      %{origname}-init.el

License:      GPLv3+
Group:        Applications/Editors/Emacs
URL:          http://code.google.com/p/js2-mode/
BuildRoot:    %{_tmppath}/%{name}-%{version}-root
BuildArch:    noarch

Requires(pre): emacsen
%prereq_ge    emacsen-common

Distribution: Vine Linux
Vendor:       Project Vine
Packager:     iwaim

%description
An improved JavaScript mode for GNU Emacs.

Features:

    * variable (adjustable) indentation
    * accurate syntax highlighting
    * highlighting of syntactic errors and many semantic errors
    * strict-mode warning reporting (such as duplicate var declaration)
    * smart line-wrapping in comments and strings
    * typing helpers (e.g. matching quotes/brackets)
    * code-folding (collapse element as {...})
    * supports JavaScript 1.5, 1.6 (including E4X), 1.7 and 1.8
    * customizable colors, or use font-lock defaults
    * many customization options 

Note - this mode is for GNU Emacs, version 22 and higher. It does not support XEmacs.

%prep
%setup -q

%build

%install
[ "%{buildroot}" != "/" ] && rm -rf %{buildroot}
[ "%{buildroot}" != "/" ] && mkdir -p %{buildroot}

mkdir -p %{buildroot}%{_datadir}/emacs/site-lisp/%{origname}/packages
mkdir -p %{buildroot}%{emacsen_pkgdir}/install
mkdir -p %{buildroot}%{emacsen_pkgdir}/remove

#
# install el files
#

cp -p js2*.el %{buildroot}%{_datadir}/emacs/site-lisp/%{origname}/
cp -p %{SOURCE3} %{SOURCE4} %{buildroot}%{_datadir}/emacs/site-lisp/%{origname}


#
# install script (bytecompile el and install elc , remove)
#

%_installemacsenscript %{origname} %{SOURCE1}

%_removeemacsenscript  %{origname} %{SOURCE2}


%clean
[ "%{buildroot}" != "/" ] && rm -rf %{buildroot}

%post
#
# bytecompile and install
#
if [ "$1" = 2 ]; then

%_emacsenPackageRemove %{origname}

fi

%_addemacsenlist %{origname}

%_emacsenPackageInstall %{origname}


%preun
if [ "$1" = 0 ]; then

%_emacsenPackageRemove %{origname}

%_removeemacsenlist %{origname}

fi


%files
%defattr(-,root,root)
%doc LICENSE README.md
%{_datadir}/emacs/site-lisp/%{origname}
%{emacsen_pkgdir}/install/%{origname}
%{emacsen_pkgdir}/remove/%{origname}

%changelog
* Fri Apr 17 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> 20141118-1
- new upstream release
- updated Source1

* Wed Mar 10 2010 IWAI, Masaharu <iwai@alib.jp> 20090723b-2
- correct output message on js2-mode-install.sh (SOURCE1)

* Sat Jan 16 2010 IWAI, Masaharu <iwai@alib.jp> 20090723b-1
- first release for Vine Linux

