• This repository has been archived on 23/Nov/2023
  • Stars
    star
    121
  • Rank 293,924 (Top 6 %)
  • Language
    Erlang
  • License
    Other
  • Created almost 9 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Erlang Docs in the Shell predating EEP-48 and shell_docs

Docs in the Shell

TravisCI Build Status Hex version badge

Still can't remember if it's (Tab, Key) or (Key, Tab) in ets:lookup/2? What about gb_trees:lookup/2? Hint: it's not the same! Ever wished for access to function signatures and documentation straight from erl the way it's possible in languages like Python, Ruby or Elixir?

docsh - light and dark background

Use in Rebar3 shell

Add these lines to your rebar.config:

{plugins,
 [
  {rebar3_docsh, "0.7.2", {pkg, docsh}}
 ]}.
{shell, [{script_file, "_build/default/plugins/rebar3_docsh/priv/docsh_rebar3_shell.escript"}]}.

rebar3 shell will now have a set of new helpers to access docs. Start with h(docsh).

Note: This will dynamically compile and load a user_default module shipped with docsh. It will override your own user_default if you use one.

Use in erl

git clone https://github.com/erszcz/docsh
cd docsh
./install.sh

The script will ask if you're sure you want to create some Erlang configuration files:

$ ./install.sh

Installing docsh

This install script will make docsh globally available in your
user environment.
It will install the following files:

  /Users/erszcz/.erlang
  /Users/erszcz/.erlang.d/user_default.erl

To know more about these files please refer to:

  man erl - sections about 'The .erlang startup file'
            and 'user_default and shell_default'
  man shell_default - parts about user_default

Do you want to proceed? [y/N]

Even if you agree to install, but the target files exist, it won't proceed - don't worry if you have customized your Erlang environment already.

Once the installation is complete, erl will greet you in a bit different way than you might be used to:

$ erl
Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false]

Enabled docsh from: /Users/erszcz/work/erszcz/docsh
Eshell V8.2  (abort with ^G)
1>

Access docs in the shell

Let's see what docsh can give us for some OTP modules. We call h/2 to get the doc for lists:keyfind no matter the arity:

$ erl
Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]

Enabled docsh from: /Users/erszcz/work/erszcz/docsh/_build/default/lib/docsh
Call h(docsh) for interactive help.

Eshell V8.2  (abort with ^G)
1> h(proplists).

# proplists

Support functions for property lists.

Property lists are ordinary lists containing entries in the form
of either tuples, whose first elements are keys used for lookup and
insertion, or atoms, which work as shorthand for tuples {Atom,
true}. (Other terms are allowed in the lists, but are ignored
by this module.) If there is more than one entry in a list for a
certain key, the first occurrence normally overrides any later
(irrespective of the arity of the tuples).

Property lists are useful for representing inherited properties,
such as options passed to a function where a user may specify options
overriding the default settings, object properties, annotations,
etc.

% @type property() = atom() | tuple()

ok
2> t(proplists).
-type property() :: atom() | tuple().
-type proplist() :: [property()].
ok
3>

Let's try with Recon:

git clone https://github.com/ferd/recon
cd recon
./rebar compile
erl -pa ebin/

Once in the Erlang shell:

Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]

Enabled docsh from: /Users/erszcz/work/erszcz/docsh/_build/default/lib/docsh
Call h(docsh) for interactive help.

Eshell V8.2  (abort with ^G)
> s(recon_trace, calls).

recon_trace:calls/2

-spec calls(tspec() | [tspec(), ...], max()) -> num_matches().


recon_trace:calls/3

-spec calls(tspec() | [tspec(), ...], max(), options()) -> num_matches().

ok
> h(recon_trace, calls, 2).

recon_trace:calls/2

-spec calls(tspec() | [tspec(), ...], max()) -> num_matches().

Equivalent to calls({Mod, Fun, Args}, Max, [])
See calls/3

ok
>

As you can see above, s/2 gives us just the function specs. Having read them, we want a more detailed description of recon_trace:calls/2, so we ask for the doc and specify the arity with h/3.

Try it with your project!

Embed docs in your modules

Make sure to document your code with EDoc. Then add the following to your project's rebar.config:

{plugins,
 [
  {rebar3_docsh, "0.7.2", {pkg, docsh}}
 ]}.

{provider_hooks,
 [
  {post, [{compile, {docsh, compile}}]}
 ]}.

More Repositories

1

erlang-rust-nif

An example Erlang NIF implemented in Rust
Rust
80
star
2

euc-2014

Introduction to Load Testing with Tsung for Erlang User Conference 2014
Erlang
40
star
3

pa

Partial application of Erlang functions
Erlang
26
star
4

learning

Random scraps using different languages and tools saved in case of some disaster
Erlang
14
star
5

ejabberd-trace

Easy tracing of users connected to ejabberd
Erlang
11
star
6

erlang-and-rust-teaser

What's Rust good at and how to tap into it from Erlang? Erlang NIFs in Rust
JavaScript
9
star
7

tsung-scenarios

8
star
8

mlp

MongooseIM log processor
Erlang
7
star
9

mongooseim-docker

Setup a MongooseIM cluster with containerized members
Shell
4
star
10

conds

Check whether _and why_ compound conditional expressions (do not) hold
Erlang
4
star
11

edoc

EEP-48 doc chunk implementation for Erlang/OTP - merged upstream for OTP 24.0!
Erlang
4
star
12

dotfiles

Shell
4
star
13

ecg

Generate a GraphViz .dot file describing an Erlang module call graph
Erlang
3
star
14

carbonizer

Push data to Carbon/Graphite in Erlang
Erlang
2
star
15

tapl-erlang

TaPL in Erlang
Erlang
2
star
16

docsh-example

DEFUNCT: docsh doesn't provide a rebar3 plugin anymore! Minimal working example of using docsh (https://github.com/erszcz/docsh)
Erlang
2
star
17

advanced-erlang-techniques

Some exercises inspired by the Advanced Erlang Techniques training with Robert Virding
Erlang
2
star
18

jsjac-simpleclient-pg

PhoneGap Build-ready package of JS Jabber Client example client
JavaScript
2
star
19

protocols

Elixir
1
star
20

dcsp

Distributed Constraint Satisfaction Problem Simulation
Erlang
1
star
21

timebomb

Simple systray on/off toggle for tracking time spent on a task
C++
1
star
22

mim-jit-loadtest

Erlang
1
star
23

rust-xv6-sh

Rewrite of xv6 sh in Rust
Rust
1
star
24

blog

Raw dump of my notes from https://medium.com/@erszcz
Erlang
1
star
25

plug-open-api-example

Elixir
1
star
26

graph_draw

Git backup of a diagram drawing tool by Hans Nilsson
Erlang
1
star
27

callgraph

Trace local function calls in C programs
Shell
1
star
28

esl-sandbox-gutenberg-generator

Erlang
1
star
29

kerl-docker

A container with Erlang installed via Kerl - intended as a base/dev image
1
star
30

erlang-type-checker-comparison

Comparison of Erlang type checkers: Dialyzer, ETC, and Gradualizer
Elixir
1
star
31

ssldump_demuxer

Quick and dirty hack to convert an ssldump file with mixed records from multiple connections to multiple files each with records from a single connection.
Python
1
star
32

rxml

Experimental fork of esl/exml to get rid of C and use Rust / RustyXML
Erlang
1
star
33

exi

EXI processing in Erlang, EXIP library wrapper
C
1
star
34

hack-erlang-vm

Rust
1
star
35

typed-gen-server-experiment

How far we can push typing the untypable?
Elixir
1
star
36

rebar-deps-gutenberg-generator

Generate rebar.config with just the deps section
Erlang
1
star
37

tracer

Erlang dbg:tracer/0 drop-in replacement
Erlang
1
star
38

exercism

My solutions to tasks from exercism.io
Erlang
1
star
39

calendlex

"Building a simple Calendly clone" with Phoenix 1.7.11
Elixir
1
star
40

monorepo-example

Example Elixir umbrella project with releases built as independent container images
Elixir
1
star