In my work I do a lot of copying and pasting from the emacs and I'm looking for a way to copy chunks of code while using linum without copying the line numbers.
e.g.
1 bla
2 blabla
3 blablabla
4 end of stuff to copy
When marking lines 1-3 I'll get
1 bla
2 blabla
3 blablabla
Which is quite useless when trying to paste into shells or other places in the code.
Is there a way to copy without the line numbers and without enabling-disabling the linum every time?
Use a solid line separator
(setq linum-format "%4d \u2502 ")
Or a one space separator from line to buffer contents:
(setq linum-format "%d ")
Related
I wanted to configure my emacs settings, so as it is said in emacsWIKI I edited .emacs.d/init.el (the file didn't exist so I created a new one).
In the file I wrote:
(setq tab-width 4) ;; For changing identation to four spaces.
(defvaralias 'c-basic-offset 'tab-width) ;; For applying the changed identation to C files.
(global-display-line-numbers-mode) ;; For showing absolute line numbers.
(setq column-number-mode t) ;; For showing column numbers.
However, although I changed the identation to 4 spaces emacs writes 8. (The other two lines work instead).
Do you know what this is due to?
I followed this guide
Seeking how could add two spaces after each line on a given text buffer in EMACS.
This is a way for add LINE BREAKS on EMACS export via org-mode.
First off, make sure you (or some package you've installed) haven't added delete-trailing-whitespace on a hook. It's not on any hooks by default, but it's fairly common to add it to before-save-hook.
Quick and dirty:
C-M-< C-M-% $ RET SPACE SPACE RET !.
This will go to the beginning of the buffer (C-M-<),
start query-replace-regexp (C-M-%),
replacing end of line ($) with two spaces and
applying it to the every match (!).
Above, RET means press the return key and SPACE means press the space bar. Replace $ with [^ ][^ ]$ and SPACE SPACE with \& SPACE SPACE to only work on lines that end in less than two spaces (this will also make the operation idempotent). \& means the entire matched string (in this case, the last two characters).
Function:
(defun ensure-trailing-spaces ()
"Ensure there are two spaces at the end of every line."
(interactive "*")
(save-excursion
(goto-char (point-min))
(while (not (eobp))
(end-of-line)
(unless (looking-back " $")
(insert " "))
(forward-line))))
Note that this unconditionally inserts two spaces at the end of every line, even if there is already one space, thus there will either be two or three spaces at the end of every line.
If there are lines in a file that are too long to be displayed on the screen, we can use word wrap. Now long lines are split into chunks visible on the screen.
Usually the code is structured and indenting is used for readability. If a line is wrapped into two (or more) lines, only the first line has right indenting and the other lines begin at the beginning of a row. Is there a way to keep all of the wrapped lines with the same indent level (or more generally different indent level)?
I have searched for a long long time, but still couldn't find a solution. This question is similar to a post for vim, but I didn't find a post or answer for emacs.
The package adaptive-wrap, which can be installed via the ELPA packaging system, should do what you want.
After having installed the package, just run the following commands:
M-xvisual-line-modeRET (to wrap long lines)
M-xadaptive-wrap-prefix-modeRET (to make wrapped lines indent nicely)
I also have the following snippet in my init.el file to automatically activate adaptive-wrap-prefix-mode along with visual-line-mode:
(when (fboundp 'adaptive-wrap-prefix-mode)
(defun my-activate-adaptive-wrap-prefix-mode ()
"Toggle `visual-line-mode' and `adaptive-wrap-prefix-mode' simultaneously."
(adaptive-wrap-prefix-mode (if visual-line-mode 1 -1)))
(add-hook 'visual-line-mode-hook 'my-activate-adaptive-wrap-prefix-mode))
I like format all my code using tab instead of space, but I just want to convert spaces to tabs at the beginning of each lines.
Can tabify just convert space to tabs at the beging of lines?
The documentation for tabify mentions a suitable value for operating on line-leading whitespace only. I used it to write this function which I find handy, but you could just set it in your init file and forego a separate function:
(defun tabify-leading (start end)
"Call `tabify' with `tabify-regexp' set so that only leading
spaces are treated."
(interactive "r")
(setq tabify-regexp-old tabify-regexp)
(unwind-protect
(progn
(setq tabify-regexp "^\t* [ \t]+")
(tabify start end))
(setq tabify-regexp tabify-regexp-old)))
Take a look at SmartTabs
It'll add onto several modes (for several languages) and make it so code indentation are tabs only, while ensuring the display of code is correct regardless of the viewer's tab width.
Excerpt:
Tabs are only used at the beginning of lines. Everything else, like ASCII art and tables, should be formatted with spaces.
Tabs are only used for expressing the indentation level. One tab per “block” – any remaining whitespace is spaces only.
Together with this, you can "tabify" existing code using the tabify command.
I have a single line text file of csv values
I would like to able to 'pretty-print' the file to span multiple lines to make it more readable
The 1st no. represents the no. of csv values in the next section and so on
e.g.
3,1,2,3,3,4,5,6
would be converted to:
3,1,2,3
3,4,5,6
I know a little about making macros, e.g.
C-x (
C-s RET ,
C-x )
using this I can do:
C-u 3 C-x e to move 3 csv values along
My sticking point is how to use the value from file to paste into the arg to C-u
maybe I should be using an e-lisp function instead as its a function I would like to 'save' for continual use across emacs sessions. Is it possible to save macros as such?
any ideas gratefully received
I find elisp easier to think about than keyboard macros. How about this:
(defun csv-line-breaks ()
(interactive)
(while (search-forward "," nil t
(1+ (string-to-number (thing-at-point 'word))))
(delete-char -1)
(insert "\n")))
(global-set-key (kbd "C-c b") 'csv-line-breaks)
With this in your .emacs (or just evaluate the code in your scratch buffer), you put point at the beginning of the line, then hit C-c b to break the line up into the chunks you want.
What this does:
Looping over the buffer until it runs out of values, and for each loop:
Read the first value. (thing-at-point 'word) grabs anything it finds between whitespace of punctuation (more or less).
Convert the value, which is actually a string, into a number
Add one to that number, and move forward that many commas
Delete the previous comma
Insert a new line
You might want to take a look at csv-mode for Emacs: http://emacswiki.org/emacs/CsvMode
Although it might not do exactly what you're looking for, it has a feature for formatting for readability, as well as other features for munging csv files in a variety of ways.