Is there any way to display the current TTY when using Emacs shell mode? Right now I get around by having tty displayed as part of the prompt but this requires scrolling back
You can display it on the mode line.
Look at the documentation , in elisp manual, section 23.4 -- Mode Line Format. In subsection 23.4.2 there is written how you do it: you write a form that returns the value you are interested about.
`(:eval FORM)'
A list whose first element is the symbol `:eval' says to evaluate
FORM, and use the result as a string to display. Make sure this
evaluation cannot load any files, as doing so could cause infinite
recursion.
Related
Whenever I run a source block in emacs org mode, the whole block executes and then I see the results. Is there a way to see the output of the program in real time?
For instance, when installing packages with pip install, the progress bars appear all at once, and they appear one after another (so org mode is not interpreting carriage returns correctly). Is there a header argument or some variable I can set to fix this? If not, where could I insert a filter function to achieve the same result?
I am using emacs for programming, and recently also gdb.
The "locals" window does show local variables but not arguments to a function, which in a way also could be considered local variables. For example, if I have
void foo(char *bar)
{
int n;
....
}
then n is shown in the "locals" but not bar. Of course, I can print bar but it is not automatically updated while I step through the code and I have to print all the time.
Is there a way to add expressions that are shown in a window and constantly updated as I execute the code?
The display command will certainly fulfill your needs:
If you find that you want to print the value of an expression frequently (to see how it changes), you might want to add it to the
automatic display list so that GDB prints its value each time your
program stops.
By example, once that your are in foo body (under gdb), type:
display bar
The interactive command gud-watch will watch the expression at point and display its value in the speedbar. Prefix it with C-u to be able to enter an expression.
See the manual page Watch Expressions for more details.
At the moment there doesn't seem to be a way to display watched expressions in the locals window.
In some elisp file, they use line-sparator(I have no idea what is the name of it) to sparate some functions.
Some functions maybe be called only by some functions which will be made for API for user. So the two part of functions are different.
In some elisp file, there a one charator which display like a line in Emacs(I call it line-sparator).
For example, in help.el file, after the line (defvar help-button-cache nil) , there is a line-sparator in line 114.
So, My question is How to input it in Emacs.
This character is called "form feed", shown in Emacs as ^L, represented in files as byte 12 (decimal) / 0C (hex). Its function is to separate pages; when sent to a printer, it will usually make the printer output the current page and restart output at the top of a new page.
You can input it with C-q C-l. C-q is bound to quoted-insert, which can insert almost anything into the buffer literally.
You are looking for C-q C-l I believe. This inserts the ^L escape, which is commonly known as a FORM_FEED. Traditionally, this command was used to tell printers to eject the page and start a new one; of course, this has changed over time. Normally, this is used as a directive to clear the screen in terminals.
I'm not sure what you're seeing, because the character displays as ^L to me.
EDIT: sniped.
I find when I'm typing a line like this to a clisp program's standard input ...
((74 25 80))
... the cursor seems to dance, and it doesn't matter whether I'm doing
(read)
or
(read-from-string (read-line))
That is, when I type each right parenthesis, the cursor briefly hovers over the matching left parenthesis. If I type ahead, sometimes the whole line typed up to that point is re-echoed back to me.
This would be fine, I guess, but I'm doing this over a pty, and I want the input from that pty (what shows up on the clisp program's standard output and error output) to be "clean". No dancing cursor, no re-echoing of the line.
I suppose I could use named pipes for the input and output, but I want to handle this through the pty.
How do I make standard input be purely vanilla? No dancing cursor? No re-echoing of typeahead? Can I just modify a configuration file somewhere?
Sounds like GNU Readline is being used. There's a -disable-readline command line flag for clisp according to this page. Failing that, I think you're going to have to use a pipe to either convince readline that it isn't reading from a terminal or that it isn't outputting to a terminal.
At my current job, we have coding-style standards that are different from the ones I normally follow. Fortunately, we have a canned RC file for perltidy that I can apply to reformat files before I submit them to our review process.
I have code for emacs that I use to run a command over a buffer and replace the buffer with the output, which I have adapted for this. But I sometimes alternate between emacs and vim, and would like to have the same capabilities there. I'm sure that this or something similar is simple and had been done and re-done many times over. But I've not had much luck finding any examples of vim-script that seem to do what I need. Which is, in essence, to be able to hit a key combo (like Ctrl-F6, what I use in emacs) and have the buffer be reformatted in-place by perltidy. While I'm a comfortable vim-user, I'm completely clueless at writing this sort of thing for vim.
After trying #hobbs answer I noticed that when filtering the entire buffer through perltidy the cursor returned to byte 1, and I had to make a mental note of the original line number so I could go back after :Tidy completed.
So building on #hobbs' and #Ignacio's answers, I added the following to my .vimrc:
"define :Tidy command to run perltidy on visual selection || entire buffer"
command -range=% -nargs=* Tidy <line1>,<line2>!perltidy
"run :Tidy on entire buffer and return cursor to (approximate) original position"
fun DoTidy()
let l = line(".")
let c = col(".")
:Tidy
call cursor(l, c)
endfun
"shortcut for normal mode to run on entire buffer then return to current line"
au Filetype perl nmap <F2> :call DoTidy()<CR>
"shortcut for visual mode to run on the current visual selection"
au Filetype perl vmap <F2> :Tidy<CR>
(closing " added to comments for SO syntax highlighting purposes (not required, but valid vim syntax))
DoTidy() will return the cursor to its original position plus or minus at most X bytes, where X is the number of bytes added/removed by perltidy relative to the original cursor position. But this is fairly trivial as long as you keep things tidy :).
[Vim version: 7.2]
EDIT: Updated DoTidy() to incorporate #mikew's comment for readability and for compatibility with Vim 7.0
My tidy command:
command -range=% -nargs=* Tidy <line1>,<line2>!
\perltidy (your default options go here) <args>
If you use a visual selection or provide a range then it will tidy the selected range, otherwise it will use the whole file. You can put a set of default options (if you have any) at the point where I wrote (your default options go here), but any arguments that you provide to :Tidy will be appended to the perltidy commandline, overriding your defaults. (If you use a .perltidyrc you might not have default args -- that's fine -- but then again you might want to have a default like --profile=vim that sets up defaults only for when you're working in vim. Whatever works.)
The command to filter the entire buffer through an external program is:
:%!command
Put the following in ~/.vimrc to bind it to Ctrl-F6 in normal mode:
:nmap <C-F6> :%!command<CR>
For added fun:
:au Filetype perl nmap <C-F6> :%!command<CR>
This will only map the filter if editing a Perl file.
Taking hobbs' answer a step further, you can map that command to a shortcut key:
command -range=% -nargs=* Tidy <line1>,<line2>!perltidy -q
noremap <C-F6> :Tidy<CR>
And another step further: Only map the command when you're in a Perl buffer (since you probably wouldn't want to run perltidy on any other language):
autocmd BufRead,BufNewFile *.pl,*.plx,*.pm command! -range=% -nargs=* Tidy <line1>,<line2>!perltidy -q
autocmd BufRead,BufNewFile *.pl,*.plx,*.pm noremap <C-F6> :Tidy<CR>
Now you can press Ctrl-F6 without an active selection to format the whole file, or with an active selection to format just that section.
Instead of creating a new keyboard shortcut, how about replacing the meaning of the = command which is already in people's finger memory for indenting stuff? Yes, perlcritic does more than just indent but when you use perlcritic anyways, then you probably don't want to go back to the inferior "just indent" = command. So lets overwrite it!
filetype plugin indent on
autocmd FileType perl setlocal equalprg=perltidy
And now we can use = just like before but with the added functionality of perlcritic that goes beyond just indenting lines:
== run perlcritic on the current line
5== run perlcritic on five lines
=i{ Re-indent the 'inner block', i.e. the contents of the block
=a{ Re-indent 'a block', i.e. block and containing braces
=2a{ Re-indent '2 blocks', i.e. this block and containing block
gg=G run perlcritic on the entire buffer
And the best part is, that you don't have to learn any new shortcuts but can continue using the ones you already used with more power. :)
I'm used to select text using line oriented visual Shift+V and then I press : an I have !perltidy -pbp -et4 somewhere in history so I hit once or more up arrow ⇧.