kaushalmodi / eless Goto Github PK
View Code? Open in Web Editor NEWA Better 'less' - A bash script that loads emacs with minimal view-mode config - Created with Org mode
Home Page: https://eless.scripter.co
License: MIT License
A Better 'less' - A bash script that loads emacs with minimal view-mode config - Created with Org mode
Home Page: https://eless.scripter.co
License: MIT License
Have a single eless.org and generate the script and documentation from that.
It'd be nice if eless
could be set to always use console or alway use GUI, I found the seemingly random choice of one or the other confusing.
Step 1 probably would be to make M-x eless-build
workable from emacs -Q
.
Inspiration: https://github.com/magit/magit/blob/master/Makefile
(This top portion is edited by @kaushalmodi)
Due to the way man
handles the man page caching and streaming on macOS systems, PAGER=eless man ls
does not work there.
But PAGER=less man ls | eless
works! See #27 (comment) for details.
(The original post now follows below.)
Mentioned this issue in #18.
rob ~/b/eless master ± echo $PAGER
eless
rob ~/b/eless master ± man ls | eless -D
Eless Version c447784 (commit hash of current master~1)
https://github.com/kaushalmodi/eless/tree/master
DEBUG: --> Input from pipe/file
DEBUG: Output to terminal -->
DEBUG: var : -D
DEBUG: Raw Args : -D
DEBUG: Emacs Args : -nw
DEBUG: Pipe Contents (up to 10 lines) : This script is not supposed to send output to a pipe
DEBUG: Temp File : /var/folders/24/18pqhyd57wv1c4cn4r7zswt40000gn/T/emacs-stdin-rob.NyrJ0jY
DEBUG: first_line_piped_data = This script is not supposed to send output to a pipe
DEBUG: No man page or info manual detected
DEBUG: Eless Command : emacs_Q_view_mode /var/folders/24/18pqhyd57wv1c4cn4r7zswt40000gn/T/emacs-stdin-rob.NyrJ0jY -nw --eval '(progn
(set-visited-file-name nil)
(rename-buffer "*Stdin*" :unique))'
DEBUG: Args passed to emacs_Q_view_mode : /var/folders/24/18pqhyd57wv1c4cn4r7zswt40000gn/T/emacs-stdin-rob.NyrJ0jY -nw --eval (progn
(set-visited-file-name nil)
(rename-buffer "*Stdin*" :unique))
This script is not supposed to send output to a pipe
displayed in eless
.
rob ~/b/eless master ±
I cannot find any installation instructions in the documentation for eless
. I eventually just cloned the repository and linked the eless
script into my PATH
(although the Info page is still not installed), but I'd rather this were spelled out so I didn't have to think about it. Or if there were a Homebrew formula for eless
, that would solve the problem as well.
Currently the whole buffer is parsed to check if diff-mode needs to be enabled.
Limiting that check to the first 10 lines should be enough.
From #21 (comment) by @sshaw:
Currently I get an Invalid regex: "Invalid regular expression" error. But, this is with system emacs 22 (OS X 10.9.5). Not clear what the source is.
I have a more recent version of OS X (well, "macOS") that I will try with later today.
Just a thought perhaps eless
can output the current buffer, when its output is pipe, this way it can part of a larger pipeline.
The use case I am thinking of is using eless, as an interactive replacement for likes of sed
or awk
allowing user to transform the text before it goes to next thing in the pipeline.
Now that eless development has moved to eless.org
, I need to put down steps on how to contribute.
eless.org
.org-babel-tangle
to output eless
from that, and not to edit eless
manually.eless
still passes on https://www.shellcheck.net/.If view-mode is enabled, user could have used functions like keep-lines
. The purpose is usually to filter out lines when reviewing log files.
So at the time if quitting, if view-mode is in enabled state, but the buffer is modified, ignore that and don't prompt the user to save anything.
On the other hand, if the view-mode is off and the buffer is modified, prompt to save as usual.
From #18 (comment):
sed -r
and the regex optionI
are GNU specific as well. And in this case you can achieve the same thing with Bash variable expansion:
some_var=${some_var/bash_builtins/builtins}
Given that this is a shell command, I would not rely on users:
In my case OS X ships with Emacs 22, which does not support these functions (I think only versions greater that 24.4 do?).
I think eval-after-load
and string-match
would suffice.
Also, I usually download Emacs from here. In this case there is no binary called emacs
. It's called Emacs
.
I had issues RE #18. When investigating I noticed that the cleanup assumes the script will reach the end. Even without #18 this isn't always the case, i.e., signals. You should so this instead:
trap 'cleanup' 'EXIT'
cleanup() {
# do cleanup stuff
}
# other code here...
Though I'd also stuff that into the temp directory.
Note that I would have sent a PR, but the instructions for building lead me to believe that this simple PR could turn into a time-consuming endeavor. I see #16 😉
OS: MacOS 10.12.6
Shell: fish 2.5.0/bash 4.4.0(1)-release
rob ~/b/eless master ± ls
CONTRIBUTING.org README.org doc eless.org
LICENSE.md build eless
rob ~/b/eless master ± emacs --version
GNU Emacs 25.3.1
Copyright (C) 2017 Free Software Foundation, Inc.
GNU Emacs comes with ABSOLUTELY NO WARRANTY.
You may redistribute copies of GNU Emacs
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING.
rob ~/b/eless master ± echo 'test' | ./eless -D
Eless Version f2eee31 (commit hash of current master~1)
https://github.com/kaushalmodi/eless/tree/master
DEBUG: --> Input from pipe/file
DEBUG: Output to terminal -->
DEBUG: var : -D
DEBUG: Raw Args : -D
DEBUG: Emacs Args : -nw
DEBUG: Pipe Contents (up to 10 lines) : test
DEBUG: Temp File : emacs-stdin-rob.HJxNpaJ
--tmpdir
DEBUG: first_line_piped_data = test
usage: grep [-abcDEFGHhIiJLlmnOoqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color=when]
[--context[=num]] [--directories=action] [--label] [--line-buffered]
[--null] [pattern] [file ...]
usage: grep [-abcDEFGHhIiJLlmnOoqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color=when]
[--context[=num]] [--directories=action] [--label] [--line-buffered]
[--null] [pattern] [file ...]
usage: grep [-abcDEFGHhIiJLlmnOoqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color=when]
[--context[=num]] [--directories=action] [--label] [--line-buffered]
[--null] [pattern] [file ...]
DEBUG: No man page or info manual detected
DEBUG: Eless Command : emacs_Q_view_mode emacs-stdin-rob.HJxNpaJ
--tmpdir -nw --eval '(progn
(set-visited-file-name nil)
(rename-buffer "*Stdin*" :unique))'
DEBUG: Args passed to emacs_Q_view_mode : emacs-stdin-rob.HJxNpaJ
A GUI emacs opens without anything in it.
rob ~/b/eless master ± ls
--tmpdir build emacs-stdin-rob.HJxNpaJ
CONTRIBUTING.org doc emacs-stdin-rob.HJxNpaJ?--tmpdir
LICENSE.md eless
README.org eless.org
Parse the first few lines (may be 10?) to see if the file contains ANSI codes. If found, call the ansi-color-apply-on-region
.
Probably remove the -ansi
switch after that?
Idea is to have an option like --info
.
So if one does eless --info emacs
, it opens the Emacs Info Manual in eless
. The argument after --info
could be any Info manual available on the system.
Eventually should be able to alias info
to eless --info
.
This would allow the use of back-quotes and single quotes (and everything in general) without needing to use escapes for constructing the whole emacs config blob.
Reference: http://crowding.github.io/blog/2014/08/16/replace-less-with-emacs/
It would be nice to configure the way that eless invokes emacs -- for instance, I want to use it in vterm
and open in the current emacs frame.
Using elesss would be less jarring if it followed the custom-set-faces in my custom-file.
When loading a file and the filename has parentheses eless breaks with an error.
echo "no content" > "filename with (parentheses)".txt
LANGUAGE=C eless filename\ with\ \(parentheses\).txt
Result:
/usr/bin/eless: eval: line 684: syntax error near unexpected token `('
eless is
eless_version='v0.6'
eless_git_hash='1a21b4b'
From #27 (comment) by @sshaw.
I also get mangled characters. Like this, but only for certain man pages (For me only Perl and Tk man pages, e.g., man Net::FTP).
Let's say we have these files a
and b
.
echo a > a
echo b > b
At present, diff-mode
is auto-enabled in this case:
diff a b | eless
Output:
1c1
< a
---
> b
But the Unified Diff is not auto-detected:
diff -u a b | eless
Output:
--- a 2017-05-11 22:07:28.141078000 -0400
+++ b 2017-05-11 22:07:32.559028000 -0400
@@ -1 +1 @@
-a
+b
Copied #18 (comment) by @sshaw below verbatim:
If adaptation is a goal, I would not require GNU grep and would use an alternate approach.
It seems as though you're using -P
just for regex lookahead.
There are alternatives (untested 😄):
grep -o '^([A-Za-z-_]+\([0-9]+\))(?=\s+.*?\1$)'
Can be:
grep '^\([A-Za-z_-]+([0-9]+)\) \+.*\1$' | grep -o '^[A-Za-z_-]\+([0-9]\+)'
Or instead of using Perl regexes (-P
), just use perl:
perl -ne'/^([A-Za-z-_]+\([0-9]+\))(?=\s+.*?\1$)/ and print'
It's likely already installed and I'm pretty sure it's installed by default more than GNU grep.
Also if you use egrep
then you don't have to escape any of ()+
.
The "eless build requirements" are higher than "eless run requirements".
For future plans like auto-publishing eless
documentation site using ox-hugo
, the minimum requirement for building eless script and documentation is emacs 24.4.. Couple of reasons:
master
(9.2.x), but can make sure that builds work fine on latest Org stable (9.1.x) too.. Minimum requirement for Org 9.1.x is emacs 24.4. So not worth trying to make the build process work on older emacs/Org versions.ox-hugo
build setup, I use advice-add
which got added in emacs 24.4.From your comment in other thread:
make all EMACS=Emacs
/tmp/eless >make all EMACS=Emacs Emacs binary used: Emacs Loading /tmp/eless/build/setup-eless.el (source)... Emacs is now refreshing its package database... Importing package-keyring.gpg... Importing package-keyring.gpg...done Contacting host: orgmode.org:443 Failed to download ‘org’ archive. Failed to download ‘melpa’ archive. Package refresh done Installing ‘org-plus-contrib’ .. Setting ‘package-selected-packages’ temporarily since "emacs -q" would overwrite customizations Setting ‘package-selected-packages’ temporarily since "emacs -q" would overwrite customizations Package ‘org-plus-contrib-’ is unavailable make: *** [vcheck] Error 255
What emacs version was that?
The failure seems odd that it failed in the package download step itself.. http/https issues?
Let's first get make vcheck
working on your system, emacs 24.4 or newer.
Hi again,
Just a suggestion you might want to consider. There's a really cool technique for Bash scripts, which I've seen called a "collapsing function." It's especially useful for optional debug output. Here's an example:
function debug {
# A collapsing function. Cool.
if [[ $debug ]]
then
function debug {
echo -e "${COLOR_YELLOW}DEBUG: ${@}${COLOR_OFF}" >&2
}
debug "$@"
else
function debug {
true
}
fi
}
Then to send debug output, you just do:
debug "Something"
instead of having to do:
if [[ $debug ]]
then
echo something >&2
fi
And by redefining or "collapsing" the function, it avoids the tests when debugging is disabled (though I doubt it matters in a shell script).
(Thanks for eless!)
Processing Texinfo file /home/tobias.rittweiler/Srcs/open-source/eless.git/docs/eless.texi...
File "/home/tobias.rittweiler/Srcs/open-source/eless.git/docs/eless.info" wasn’t produced. See "*Org INFO Texinfo Output*" for details
make: *** [Makefile:58: emacs_batch] Error 255
When not running emacs in batch mode and looking into the mentioned buffer, one can discover that the makeinfo
command is missing.
Suggestions:
texinfo
under Requirements.makeinfo
and fail with a meaningful error message.Need to test most (if not all) eless
usage scenarios on Travis.
As posted by @alphapapa here:
If I do
eless .
, and then open a file from the dired buffer, it's no longer in view mode. :)
Hey, let's talk about the current theme.
I like the new (9448563) Man-overstrike
color but I don't think it meshes well with man
links. In my opinion (by using this site: http://paletton.com/#uid=51v0u0kkOuvb3MlgsBnparKsemh), I think #F3C355 would be a well suited color. I also think that talking about the default menu bar colors would be worth a discussion.
I tried to add this myself with a pull request but for some reason it wouldn't recognize me setting the face.
Thoughts?
One of the users on reddit wanted to override the default eless bindings. [Ref]
Implement a way to load a user config file, if available; probably in ~/.emacs.d/eless.el
.
May be use the env var $EMACS
, which defaults to emacs
.
When running e.g.
$ eless *.patch
I would like to be able to inspect the first file as usual, then press some key to proceed to the next file, and so on until all the files are processed. (This is what emacsclient
does, and the keybinding is C-x #
.) Is there an equivalent way to do this in eless
?
I have a separate emacs installation and don't want to use brew
's installation; I wonder how common that is and whether emacs
should be a required dependency in the formula.
Don't do this:
Input is piped from =man= command
#+BEGIN_SRC shell
if [[ ! -z ${man_page} ]]
then
# After setting PAGER variable to eless, try something like `man grep'.
# That will launch the man page in eless.
Possible solutions:
if/else
blocks across source blockseless
script post-tanglinghi. eless is very nice. so, i've been using it a lot. recently, i was updating a man page for some software of mine which is already installed on my machine. i would do
nroff -man ./credeface.1 2>&1 | eless
but, i would always see the old man page, in spite of the fact that the new man page was right there. finally, i realized if i used less
rather than eless
, i would see the new man page.
that got me to look at the eless
source, and it seems you parse the input enough to realize it is a man page, then decide which man page, then do (the emacs-equivalent of) man 1 credeface
, so giving me the installed man page, rather than the new one i am working on.
i notice that M-x man
is willing to take a filename (especially if preceded by a -l
).
[insert a sentence here on 'i think this is a bug', or 'here is a feature request', or, more likely, 'i don't know what the right thing to do would be'.]
again, thanks for eless!
[edited 02.02.2023, change opinion of M-x man
.]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.