I've attempted to comb the repository (oh the joys of globally used single character names) without luck, but maybe I'm looking for the wrong things.
Seeing documentation for SDL.P would probably also work.
For future reference, is there a good way to go about finding data constructors in Haskell (as they seem to be difficult to grep for in the single-character case)?
Hackage has haddocks for the sdl2 package. If you click the "Index" link, then click "P", you can find a list of all identifiers that start with that letter -- including the P data type.
http://hackage.haskell.org/package/sdl2-2.4.1.0/docs/doc-index-P.html
Is this it? It’s all I could find using stackage search within the “sdl2” package.
https://www.stackage.org/haddock/lts-12.13/sdl2-2.4.1.0/SDL-Internal-Vect.html#v:P
Edit, how I did it:
You can limit the search offered by Stackage to a single package, using the URL: https://www.stackage.org/package/PACKAGE_NAME, so in this case https://www.stackage.org/package/sdl2.
Searching for operators, put them in parentheses, such as "(.)". For your question, search for "P" like so: https://www.stackage.org/lts-12.13/hoogle?q=P&package=sdl2
Related
Is it possible to print the function or class name in which a keyword occurs when using ack or ag? This is something I have highly desired for quite some time.
I think it would be quite tricky, as different programming languages have different ways of enclosing functions/classes.
Note that my goal right is for searching through C source code, however I would prefer a generic solution which covers more languages/syntax.
Author of ack here. No, I don't know of any greplike tool that understands anything about the text files that it's searching. It's something that people ask for all the time, but I've never even thought about implementing it.
You said "I think it would be quite tricky, as different programming languages have different ways of enclosing functions/classes." You're exactly right. Also, consider things like comments
/* void foo() */
and literal strings
printf( "void foo()" );
that would cause problems for any search tool. Neither of those instances of the string void foo() is actually a function declaration.
Check out the More Tools page on beyondgrep.com. Something like cscope might help you.
As commented by #Inian, it would be difficult to get a robust solution using ack, ag and grep as they are not aware of the grammar of the languages.
However, for my case of looking inside C source code files, I used ack with an OR condition to include lines which are starting with the function definitions. In my case, all my functions were either returning int or nothing. Hence, the following code printed out function definition lines alongwith the lines containing the KEYWORD:
ack 'KEYWORD|^void|^int'
Although none of the programs you listed currently have this functionality, Git uses language-based regexps to implement git grep -L (search within a function name). This blog post describes how it works. The current list of regexps are in the git source tree here, and can be extended as described in the blog above.
Also, ctags provides a universal way to enumerate tags from files of multiple languages, but I haven't (yet) found a way to integrate this output with git grep -L yet.
Hackage is great and always be the first place to study how function to be defined and used of specific package.
However, frequently, we need refers multi-packages simultaneously, e.g. Control.Monad, Data.List and ... so on, and switches among of them. The easy way to do that is open mulit-tabs in chrome, but as the number of tabs grow, there are many tabs be opened and the name of package on the tab cannot be showed fully.
So, Are there exist some web sites organize Haskell packages documents like javadoc style, we can browse and select packages in right frame and show the content of document in left frame. Furthermore, it is more appreciated if it can save and list frequent use package document in another frame.
I tend to use Dash but technically that's just downloading it from Hackage, you can also build docs locally (if library has them) but I find those a little cumbersome.
I’m running racket as a repl (with xrepl), and I’m able to use ,doc to see some relevant documentation (almost awesome), but it fires up a web browser to see the documentation. I’d like to be able to see the docs right in the repl, similarly to how it’s presented in other repls (R, Clojure, ipython, pry, etc). Is this possible?
E.g., in Clojure’s lein repl, one can do:
user=> (doc map)
-------------------------
clojure.core/map
([f coll] [f c1 c2] [f c1 c2 c3] [f c1 c2 c3 & colls])
Returns a lazy sequence consisting of the result of applying ...
It would also be great to be able to see source ((source map) in clojure), but I haven’t seen any hints of this being available.
I happen to be using Vim (with slime/tmux), so any Vim-based solution would also work, probably tied to its K built-in help.
I'm not sure this is practical given the nature of Racket documentation.
The help deliverable is HTML.
Unlike Clojure (or Emacs Lisp), Racket doesn't have doc strings in the function definition source.
Racket docs don't have a convention like the one that the first line of a doc string should be a summary (a short-version to use in situations like a list of commands or in a REPL).
You can try xrepl's ,desc <id> command. Starting in Racket 6.1.1, if the function has installed documentation, it will print a rendering of the "blue box" -- the function signature with contracts and/or types. In many cases that's all you need, say to jog your memory. However there is no text describing the item. And if there is no installed help for a function, it won't attempt to show you anything based on the function's definition source.
So for example in racket-mode for Emacs, there is a racket-describe command and it does not fire up a browser -- but it shows the full HTML help (if any) using shr in a separate Emacs buffer. If there is no help, it does try to find the source and extract a contract/type and signature to show you. But again, there is no doc string in that source, to find, much less a one-line summary to show neatly in a REPL.
There are vim fans using Racket; the ones I know are use evil-mode in Emacs and feel it's the best of both worlds. However I appreciate that's not your current workflow using multiple languages, so I'm not proposing that as the solution for you.
I put together VROD, a solution that parses the reference documentation into something that Vim can work with. This provides essentially what you can get from clojure's doc built-in help, but through Vim’s K-help. And it also does some highlighting and shows examples.
(It also happens to do auto-completion of functions.)
Why some functions are not visible in Hoogle? Example: ppTopElement
ppTopElement :: Element -> String
-- Defined in `Text.XML.Light.Output'
Is it a bug?
Workaround: go to FPcomplete instead.
haskell.org's Hoogle (http://www.haskell.org/hoogle/) is quite selective about what it searches, whereas FP Complete's hoogle at https://www.fpcomplete.com/hoogle searches more fully:
Search more widely than haskell.org's hoogle
https://www.fpcomplete.com/hoogle?q=ppTopElement&env=ghc-7.4.2-stable-13.09
Searched for: ppTopElement
ppTopElement :: Element -> String
xml Text.XML.Light.Output
Pretty printing renders XML documents faithfully, with the exception that whitespace may be added/removed in non-verbatim character data.
Search more flexibly than hayoo
Being a hoogle rather than a hayoo, you can search by type, partial type, partial name, misordered type etc. For instance, searching for Element -> String gives lots of functions, some showing, some pretty printing, some just doing the top element.
Aside: there's a lovely online IDE
BTW, Their online IDE is superb (click on the homepage https://www.fpcomplete.com/ and scroll down to Start a Project). It's slick, pretty, and you can add dependencies easily without tedious cabal install problems. I've been tempted to even use it at home where I have ghc installed!
You may want to try Hayoo for that.
Hayoo will search all packages from Hackage, including all function and type definitions. Hoogle only searches on standard Haskell libraries.
Also Hayoo can be queried from Emacs in haskell-mode.
It is a simple question to which I am not able to find the answer:
Given a LaTeX command, how do I find out what package(s) it belongs to or comes from?
For example, given the \qquad horizontal spacing command, what package does it come from? Especially troublesome since it works without including any package!
Given a LaTeX command, how do I find out what package(s) it belongs to or comes from?
Consult your references:
If it's in the index to the TeXbook, it's inherited from TeX, the engine that drives LaTeX.
Otherwise, if it's in the index to the LaTeX manual, it's probably defined in latex.ltx or in one of the standard class files, not in a package.
Otherwise, if it's in the index to The LaTeX Companion, the page number probably tells you what package it's from.
Otherwise, you could do some fancy grepping on the results of find /usr/share/texmf -name '*.sty', but be prepared for a painful exercise.
Or, you could ask on http://stackoverflow.com. But then some idiot will respond by asking why you want to know...
You can search http://www.ctan.org/tex-archive/info/symbols/comprehensive/ for that information and more.
Remember that LaTeX is a macro language on top of TeX, and all the macros are made up of TeX which doesn't need to be imported. \qquad is in that category.
As far as I know, there is no really good general answer to this. But there are a number of techniques you might try for any given command. In the case of \qquad, it's part of basic TeX. Remember that you can always use TeX in interactive mode:
$ tex '\show\qquad'
This is TeX, Version 3.141592 (Web2C 7.5.6)
> \qquad=macro:
->\hskip 2em\relax .
\show\qquad
? x
No pages of output.
Some macros are added by LaTeX on top of TeX, such as \begin:
$ tex '\show\begin'
This is TeX, Version 3.141592 (Web2C 7.5.6)
> \begin=undefined.
\show\begin
? x
No pages of output.
whereas
$ latex '\show\begin'
This is pdfTeXk, Version 3.141592-1.40.3 (Web2C 7.5.6)
%&-line parsing enabled.
entering extended mode
LaTeX2e
Babel and hyphenation patterns for english, usenglishmax, dumylang, noh
yphenation, greek, monogreek, ancientgreek, ibycus, pinyin, loaded.
> \begin=macro:
#1->\#ifundefined {#1}{\def \reserved#a {\#latex#error {Environment #1 undefine
d}\#eha }}{\def \reserved#a {\def \#currenvir {#1}\edef \#currenvline {\on#line
}\csname #1\endcsname }}\#ignorefalse \begingroup \#endpefalse \reserved#a .
\show\begin
? x
No pages of output.
Everything else comes from packages. If you really wanna know which package a macro comes from (other than by google or grepping your texmf tree), you can check after each package you load whether it's defined. Try defining this before any \usepackage commands:
\let\oldusepackage\usepackage
\renewcommand\usepackage[1]{
\oldusepackage{#1}
\ifcsname includegraphics\endcsname
\message{^^Jincludegraphics is defined in #1^^J}
\let\usepackage\oldusepackage
\fi}
Then when you run latex on your .tex file, look for a line in the output that says includegraphics is defined in graphicx. It's not likely, but some devious packages might do bad things with \usepackage so there's a chance this might not work. Another alternative would be to simply define the command you're interested in before loading any packages:
\newcommand\includegraphics{}
Then you might get an error message when the package that defines the command is loading. This is actually less reliable than the former approach, since many packages use \def and \let to define their macros rather than \newcommand, bypassing the "already-defined" check. You could also just insert a check by hand in between each load: \ifcsname includegraphics\endcsname\message{^^Jdefined after graphicx^^J}\fi
Due to lack of reputation I cannot comment on Steve's answer, which was very helpful to me, but I would like to extend it a bit.
First, in his second approach (fiddling with usepackage) the case where usepackage has optional arguments is not dealt with. Secondly, packages are often loaded by other packages via RequirePackage which makes it hard to find the actual place of definition of a command. So my refinement of Steve's answer is:
\usepackage{xargs}
\let\oldusepackage\usepackage
\let\oldRequirePackage\RequirePackage
\renewcommandx{\usepackage}[3][1,3]{
\oldusepackage[#1]{#2}[#3]
\ifcsname includegraphics\endcsname
\message{^^Jincludegraphics is defined in #2^^J}
\let\usepackage\oldusepackage
\let\RequirePackage\oldRequirePackage
\fi}
\renewcommandx{\RequirePackage}[3][1,3]{
\oldRequirePackage[#1]{#2}[#3]
\ifcsname includegraphics\endcsname
\message{^^Jincludegraphics is defined in #2^^J}
\let\usepackage\oldusepackage
\let\RequirePackage\oldRequirePackage
\fi}
The xargs package is used here to get the unusual options of usepackage right (first and third parameter are optional).
Putting this directly after documentclass should tell where includegraphics is defined.