Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
Particularly, what is the best snippets package out there?
Features:
easy to define new snippets (plain text, custom input with defaults)
simple navigation between predefined positions in the snippet
multiple insertion of the same custom input
accepts currently selected text as a custom input
cross-platform (Windows, Linux)
dynamically evaluated expressions (embedded code) written in a concise programming language (Perl, Python, Ruby are preferred)
nicely coexists with others packages in Emacs
Example of code template, a simple for loop in C:
for (int i = 0; i < %N%; ++i) {
_
}
It is a lot of typing for such common code. I want to invoke a code template or snippet which inserts
that boilerplate code for me. Additionally it stops (on TAB or other keystroke) at %N% (my input replaces it) and final position of the cursor is _.
TextMate's snippets is the most closest match but it is not a cross-platform solution and not for Emacs.
The second closest thing is YASnippet (screencast shows the main capabilities). But it interferes with hippie-expand package in my setup and the embedded language is EmacsLisp which I'm not comfortable with outside .emacs.
EDIT: Posted my answer here to allow voting on YASnippet.
Personally, I've been using Dmacro for years (ftp://ftp.sgi.com/other/dmacro/dmacro.tar.gz).
Here's a review of it that also mentions some alternatives: http://linuxgazette.net/issue39/marsden.html
The EmacsWiki has a page of template engines.
Of these, I've used tempo in the (distant) past to add table support to html-helper-mode, but don't know how it has progressed in the last 15 years.
I'd add my vote for tempo snippets ... easy to setup, powerful (you can run arbitrary elisp in your template - so that you can downcase things, lookup filenames & classes, count things, etc), set the indentation, integrate with abbrevs ... I use it a lot ;)
I vote for http://cedet.sourceforge.net/srecode.shtml
It has very clean syntax and has access to code environment through Semantic.
Also it is a part of a large well supported CEDET distribution (which was built into Emacs for 24.x version series).
UPDATE YASnippet is also a powerful template engine. But it uses an ugly file naming schema (your file name === template name) for you can't put several templates into a single file and have issues with national character sets...
You can try a lightweight solution muban.el
It is written completely in Elisp and has a very simple syntax.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
i'm looking to find a way to beautify my code in MATLAB. I'm talking about tabs, deleting unnecessary spaces etc., the way Eclipse does it with Ctrl+Shift+F
The smart indentation (ctrl + I) is probably all you need (as #Matteo V and #Cris Luengo already mentioned).
However, there are a few other neat tricks that you might want to have a look at if you are really into code development:
Well, first have a look at the Improve Code Readability site of MATLAB. You could use the Apply smart indenting while typing option in the Preferences > MATLAB > Editor/Debugger > Language > Indenting section (it should be turned on per default but I like the Indent all functions setting). There are a bunch of other settings that you may want to explore
If you dig yourself deeper in the MATLAB IDE, you will notice that you can adjust almost everything to your preferences, but the way is not always documented in the web.... however, the local documentation (call doc) contains the info you may be looking for, see this blog-post
I am not aware of an automatic detection of double spaces or similar but you might end up writing your own little callback-function. Most languages ignore this anyway (perhaps except for Python). Code readability is usually a topic that the programmer(s) should care about... and not the machines ;)
Further tips:
respect the Right-hand text limit, which is the vertical gray line in your editor and shall indicate how many characters a single line of code should have as maximum. If it is a comment, wrap it. If it is an expression, try to outsource some commands to a dedicated variable
use equally long variable names. (There is no style guide as in Python, which says that you should use normal words and underscores etc) E.g. if you have two variables describing a commanded and a measured velocity, you could call them v_cmd and v_act and your code perfectly aligns if you apply the same manipulations to both variables ;)
use section. With %% (the space is important) at the beginning of a line in the editor, you create a section (you'll note the slight yellow background color and the bold writing that follows this command). It is convenient to structure your code. You can even run entire sections Editor-Tab > Run > Run section
Although there are programmers claiming that a good code speaks for itself (and therefore doesn't need any comments), to my experience writing comments has never been a bad idea. It improves the readability of your code
The answer might have been a bit elaborate for such an innocent question ... oO
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
https://github.com/emacs-helm/helm-ls-git
Found no tutorial for it on google.
That means it doesn't exist in our universe?
I'm looking for a way to find files and grep files within emacs.
Hopefully as easy as in sublime with project directory opened.
(Your search is automatically limited to the directory you specified in sublime)
The functionality you are after is something dired has been doing successfully for years. The file you have linked in your post is a minor enhancement for a convenience feature added on top of the built-in functionality, it doesn't really deal with searching for files outside the context of Git version control system.
Here are some examples of how you could do it with dired:
M-xfind-name-dired, answer the prompts to select the directory where you want to search and possibly refine by providing a regular expression to match file names. You then will be presented with the buffer listing all files you have selected so far. You can further refine from here by % m and providing it with a regexp to filter the file names on, or just hit t selecting all files in the buffer.
Then hit A and write the regexp to search for inside the selected files. The effect of this command will be to open the file, where the match is found. After you close the file, or return to the original buffer, you can press M-, to move to the next match.
If this sounds too elaborate, then you could just do M-xfind-dired to invoke find in the directory you choose with the arguments you can normally provide to find
To just grep and have the matches shown in a dedicated buffer you could do M-xfind-grep - this will invoke find with the output from it piped to grep. You will then need to modify the command used to invoke this to your taste.
M-xfind-grep-dired will do something similar, however it will display the files, where the match was found in a dired buffer, rather then the lines, where the match occurred.
Finally, there may be a bunch more ways to do this, depending on your particular task and what, in the end, you are trying to accomplish. Perhaps, some times, invoking a shell command to place the results directly in the buffer would be the best way to do it. Other times you may want to write your own eLisp function to do something more elaborate with the results. Sky is he limit :)
I saw this question recently and updated the README on the repo page to reflect installation and usage:
https://github.com/emacs-helm/helm-ls-git
Hope it helps!
This might not answer your entire question but I use the following bit of elisp as a shortcut for greping all files with a set list of extensions under a specific folder:
(defun pgrep (regexp)
"rgrep files inside a project folder"
(interactive
(list (grep-read-regexp)))
(grep-compute-defaults)
(rgrep regexp "*rb *erb *js *css *scss" "~/path/to/folder/"))
Then I just run M-x pgrep foo
For anything more complicated I just run rgrep directly - it lets you specify the root folder, search string, and extension.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Whats the fastest perl template library that allows me to do the following:
variable substitution,
loops (Hashes & Arrays),
layout (wrapper templates)
and at least some conditional logic (< > != == %).
..also has anybody used pltenjin? the benchmarks suggest this is pretty rapid.
I recommend you the Xslate template engine (http://xslate.org/), and it's about 50-100 times faster than others. Please, see this comparative benchmarks: http://xslate.org/benchmark.html
The engine enables the use of Template Toolkit (another template engine) compatible template tokens ('[%', '%]'), and you can use commands like: INCLUDE, FOREACH, WHILE, ...
No, I didn't use plTenjin. From my experience,
this looks almost like HTML::Mason minus the
nice block syntax of Mason.
What site do you manage which is able to saturate
any modern CPU during template processing? I don't
think this would happen easily.
In most cases, there are different bottlenecks
to site performance than any cpu-bound template
processing.
(BTW, from what I read in the plTenjin doc,
you should give HTML::Mason a try..)
Regards
rbo
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
Right now, I use most as my pager. While it has helpful syntax highlighting for man pages, it lacks colored syntax highlighting for anything else (I'm specifically looking for diff/C++).
Meanwhile, pygments is a wonderful program. I can easily make colorized output with it:
# ./pygmentize -f console256 ${file}
hg diff | ./pygmentize -f console256 -l diff
Now, I would like to be able to page the output, so I just use:
# ./pygmentize -f console256 ${file} | most
hg diff | ./pygmentize -f console256 -l diff | most
At this point, most dumps all the colorizing control characters to my screen like so:
^[[38;5;28;01mclass^[[39;00m ^[[38;5;21;01mheap_allocator^[[39;00m
{
^[[38;5;28;01mpublic^[[39;00m^[[38;5;241m:^[[39m
This is, of course, unreadable. I looked though the man page for most, but I couldn't find any "Hey, show those control characters as colors instead of printing them" options. less has the same garbage behavior as most, but more shows the colors perfectly fine, with the obvious limitations of being more.
Is there a pager that supports syntax highlighting or some crazy combination of parameters and programs I can string together to make this work? Ultimately, I would like to get diffs and logs from Mercurial to be highlighted, so maybe there is a shortcut in there...
Might I suggest vimpager?
First off, recent vim distributions (I believe 6.0 and above) come with a pager-esque-mode script. It's quite simple and functional, and operates similarly to less. Try: vim '+help less' +only.
Even better, however, Rafael Kitover has written a much more robust and powerful script called vimpager. It's available on GitHub (or vimscripts). If you are on OS X and using Homebrew, it's as easy as brew install vimpager.
At that point, you can simply set $PAGER=vimpager, or even alias less=vimpager. It works excellently.
less -R shows ANSI color sequences as-is (instead of expanding to caret notation). That'll make syntax highlighting work!
You can also create an environment variable LESS=-R to make this the default behavior. Similarly for other options; see man less.
Look for bat: A cat(1) clone with wings.
bat supports syntax highlighting for a large number of programming and markup languages.
It is not a pager, but it automatically redirects output to less if needed.
You might try using jed. Yes, it's a text editor, not a pager, but it's quite lightweight and the default install contains excellent colorschemes for a wide variety of file types and languages.
Jed has syntax highlighting modes for different languages, simillar to the emacs ones. For example if you piped a C program to it, you can turn on the highlighting by pressing 'ESC', then 'x', then typing 'c-mode' . If it is a php program - change the last part to 'php-mode' and so on ...
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I would like to create only a syntax highlighting minor mode for Emacs. I have the "Writing GNU Emacs Extensions" by O'Reilly, but it does not go into any depth of detail. Is there a simple tutorial for a real or fake programming language highlighting mode?
Thank you
Defining a custom Generic Mode is probably the best place to start. You can define basic syntax highlighting for a language as simply as the following snippet.
(require 'generic-x)
(define-generic-mode
'my-mode ;; name of the mode
'("//") ;; comments delimiter
'("function" "var" "return") ;; some keywords
'(("=" . 'font-lock-operator)
("+" . 'font-lock-operator) ;; some operators
(";" . 'font-lock-builtin)) ;; a built-in
'("\\.myext$") ;; files that trigger this mode
nil ;; any other functions to call
"My custom highlighting mode" ;; doc string
)
It's great for quickly defining some basic syntax highlighting for obscure languages. I even use it for log files in some cases.
EmacsWiki's Mode tutorial has a little more information on creating a major mode, in case you want to expand from syntax highlighting only.
You also might find it useful to look at this answer, which has a pointer to code that defines a minor mode to highlight certain key words - but only in strings and comments.
A minor mode is nicer if all you want is highlights - less baggage.
The relevant portions of the manual are for the function 'font-lock-add-keywords and the variable font-lock-keywords.