How to set crossline alike highlighting mode in emacs? - emacs

What i'm trying to do here is that, in my buffer I want to point the cursor position through highlighting the line horizontally and column vertically.
Much like the CrosshairHighlighting mode. (see here. https://www.emacswiki.org/emacs/CrosshairHighlighting)
(global-hl-line-mode 1)
(set-face-background 'highlight nil)
(set-face-foreground 'highlight nil)
(set-face-underline-p 'highlight "#ff0000")
So using hl-line library pkg and these 4 line code in my .emacs, I got my desired part of highlighting the line in underline mode. Here is my emacs ss:
(vline-global-mode 1)
(set-face-background 'vline "#ff0000")
(set-face-foreground 'vline nil)
Similarly I try to set-up for vertical-line with vline library pkg, but unable to thinner the block. Searched a lot about it but couldn't figure it out.
https://stackoverflow.com/a/23813217/4239355
I tried this one earlier to set the vline-style variable to "compose" value (setq vline-style 'compose) it will show the vertical line as a pipe symbol
| which is thicker line. But The problem is that the pipe doesn't look aesthetically pleasing because there is a small gap between lines.

Related

Emacs Line Height

I am trying to set the line height of text in an Emacs buffer so there is space above and below the letters. From the documentation, I infer that the line-height text property may help me to accomplish this.
There is also a line-spacing variable which I can set like (setq-default line-spacing 0.25). This kind of works, except it does not produce space before text, only after it. I don’t like the way this looks when using modes like show-paren-mode, since it “dips” down:
Undesired current behavior (“hanging”)
Desired behavior mockup (vertically-centered)
I'd like to vertically-center the text.
I have discovered that I can temporarily get the effect I want with the following code:
(add-text-properties (point-min) (point-max)
'(line-spacing 0.25 line-height 1.25))
However, in some modes the properties go away in regions where I start typing. How do I make that top and bottom spacing the default? (Hooks won't work.)
Update
TLDR: I've succumbed to the fact that you can't really reliably achieve this natively with Emacs. You need to patch the font itself to include extra spacing. So, I created this script to take care of that.
Old/Incomplete Answer
TLDR: Add this somewhere in init file:
;; Set the padding between lines
(defvar line-padding 3)
(defun add-line-padding ()
"Add extra padding between lines"
; remove padding overlays if they already exist
(let ((overlays (overlays-at (point-min))))
(while overlays
(let ((overlay (car overlays)))
(if (overlay-get overlay 'is-padding-overlay)
(delete-overlay overlay)))
(setq overlays (cdr overlays))))
; add a new padding overlay
(let ((padding-overlay (make-overlay (point-min) (point-max))))
(overlay-put padding-overlay 'is-padding-overlay t)
(overlay-put padding-overlay 'line-spacing (* .1 line-padding))
(overlay-put padding-overlay 'line-height (+ 1 (* .1 line-padding))))
(setq mark-active nil))
(add-hook 'buffer-list-update-hook 'add-line-padding)
Increase or decrease the line-padding value to your liking.
This answer pretty much just summarizes the information in the above question, answer, and comments, so I suggest reading those first.
I use an overlay instead of text properties because it behaves more nicely when adding new text to the buffer (especially via copy/paste).
The buffer-list-update-hook is used as a means of identifying when a new buffer has been created and thus would need to have the overlay applied.
For performance reasons, to not continuously add overlays, the existing padding overlay is deleted if it aleady existed.
As the doc says, line-height is a text (or an overlay) property. It is not a variable.
Try (setq-default line-spacing 20).
line-spacing is a frame parameter or a buffer-local variable. Its value can be an integer number of pixels or a floating-point number specifying spacing relative to the frame's default line height. The doc says nothing about giving it a list value, such as (32 64).
And if you are using Emacs in terminal mode then none of this applies. As the doc says about that:
On text terminals, the line spacing cannot be altered.
Try "Help => More Manuals => Emacs Lisp Reference" and from there type i text properties RET. This will hopefully clarify the situation. As for your specific request, I don't think there's a simple way to get what you want right now. You might like to M-x report-emacs-bug about the display appearence of the paren-highlighting.

How to change the character composing the Emacs vertical border?

I am using Emacs 24, console. I am looking for a way to replace the character of the vertical border with another, \u2502. Since I didn't find much, I believe it is hardcoded in the source.
Is there any better way to do this, other than recompiling Emacs ? I use many different machines, and thus having this customization inside my ./emacs.d/ would be quite awesome as a matter of fact ;].
I use this
;; Reverse colors for the border to have nicer line
(set-face-inverse-video-p 'vertical-border nil)
(set-face-background 'vertical-border (face-background 'default))
;; Set symbol for the border
(set-display-table-slot standard-display-table
'vertical-border
(make-glyph-code ?┃))

Decrease indentation on a couple of lines

Is there some way I can mark text in emacs and shift it left (removing starting spaces) by space/Tab granularity?
Same way I would do on some other editor with Shift+Tab.
Select your region;
Type C-u followed by the number of spaces you want to indent (negative number if you want to decrease indentation);
Use C-x TAB (by default bound to indent-rigidly) to apply the indentation to the region.
This is much more cumbersome than S-TAB, but it is IMHO some kind of last resort in case Emacs formatting doesn't solve your problem.
EDIT: much better solution: Shift a region or line in emacs (accepted answer). This is what I'm currently using in Emacs for changing indentation. WARNING: involves some Emacs Lisp.
This might be simpler and more visually intuitive: first make sure cua-mode is enabled (M-x cua-mode toggles it). Then go to the start of the line and press C-return. A red rectangle appears. Now move your cursor down and right to grow the rectangle as needed. Then press C-d to delete it. That's it.
I come across this problem often when the major-mode doesn't dictate any automatic indentation (or when it messes up).
There is a lot more you can do with cua-mode's rectangles, see http://trey-jackson.blogspot.com/2008/10/emacs-tip-26-cua-mode-specifically.html
Generally emacs places things where the current style dictates when you hit <TAB>, so naturally it's a little different here. The closest thing that comes to mind is M-\ which collapses horizontal whitespace around point. If you want to remove a "rectangle" of space before the lines, then delete-rectangle might be more appropriate, which you can do by setting mark and moving point to select the rectangle and then using C-x r d.
It sounds like the problem you're trying to solve is incorrect indentation of code when you're cutting/pasting. You can solve that by automatically re-indenting the text with something like the following.
Note: Using a prefix argument forces no re-indentation (C-u C-y), plus there's the size threshold variable.
;; automatically indenting yanked text if in programming-modes
(defvar yank-indent-modes '(emacs-lisp-mode
c-mode c++-mode
tcl-mode sql-mode
perl-mode cperl-mode
java-mode jde-mode
lisp-interaction-mode
LaTeX-mode TeX-mode)
"Modes in which to indent regions that are yanked (or yank-popped)")
(defvar yank-advised-indent-threshold 1000
"Threshold (# chars) over which indentation does not automatically occur.")
(defun yank-advised-indent-function (beg end)
"Do indentation, as long as the region isn't too large."
(if (<= (- end beg) yank-advised-indent-threshold)
(indent-region beg end nil)))
(defadvice yank (after yank-indent activate)
"If current mode is one of 'yank-indent-modes, indent yanked text (with prefix arg don't indent)."
(if (and (not (ad-get-arg 0))
(member major-mode yank-indent-modes))
(let ((transient-mark-mode nil))
(yank-advised-indent-function (region-beginning) (region-end)))))

What causes this graphical error in emacs with linum-mode on OS X?

I get this graphical error with linum-mode in my Emacs. I tried upgrading from 23 to 24 (via git) and I've tried both with various supplied binaries online and with my home-compiled version. What I'm really interested in is where to start diagnosing the problem.
The problem goes away if I scroll the torn line numbers off screen and back in.
I have experienced the same problem and spent quite some time trying to resolve it. The graphical error is a result of a clash between linum-mode and how the fringe is rendered. Unfortunately, I was unable to resolve the problem in linum.el, and the fringe display code is part of the C-source.
It can still be done! The easiest way to fix it is to just turn off the fringe.
M-x fringe-mode RET none RET
To make the fringe permanently stay off, I recommend customizing the settings with M-x customize-group RET fringe because some compiled versions of Emacs for Mac OS X have their own fringe settings that can override parts of your .emacs file.
I don't really need those line wrap indicators, so not having a fringe doesn't bother me. However, I did miss a slight separation between the line numbers and the buffer text. I followed the advice of a post on the Emacs Wiki to get that spacing back. In version 0.9x of linum, change line 160 from
(setq width (max width (length str)))
to
(setq width (max width (+ (length str) 1)))
The inspiration for this change is here: http://www.emacswiki.org/emacs/LineNumbers
There are arguments at the source link to set the linum-format variable instead of modifying linum.el. While I understand where they are coming from, most color-themes these days would color the extra space and not provide what I am looking for (a separation of about a space that is the background color). If you do edit linum.el, make sure to run
M-x emacs-lisp-byte-compile-and-load
to make the changes persistent. You can see the result of this by looking at the space before the cursor in the picture found here: http://i.stack.imgur.com/TxyMr.png (I don't have enough reputation to embed images).
No more graphical artifacts!
I had the same problem and I figured out a solution and while it's not the prettiest, due to an extra space to the left of the line number, it's much more elegant than changing the linum.el. Here is the pertinent part of my ~/.emacs:
;; Linum mode
(global-linum-mode t)
;; Offset the number by two spaces to work around some weird fringe glitch
(setq linum-format " %d ")
This removes the fringe overlay issue and does not have any other impact other than offsetting the line number.
to make a separation between the line numbers and the buffer text, the follow change will be better:
In version 0.9x of linum, change line 150 from
(concat "%" (number-to-string w) "d")))))
to
(concat "%" (number-to-string w) "d ")))))
This make the separation have the same background color with line numbers'.
This is how I have it setup in my .emacs and I don't have the problem, although I also don't use emacs with gtk or any other gui.
(linum-mode +1)
(setq linum-format "%d ")
You might want to hack around with (setq linum-format) to see if you can get good results. Also don't forget to browse emacswiki on linum.
The problem was still here on emacs 24.4, OS X 10.10.1.
The solution I worked out:
after loading the theme of your choice:
(load-theme 'whatever)
(set-face-attribute 'fringe nil :background (face-background 'default))

Emacs region highlighting

Is there a way to highlight a string in a text (but not ALL such strings) in a buffer where font-lock-mode is on.
Let's imagine I have a buffer with SQL mode and I want to highlight a string in it.
The following code does not work
(set-text-properties 10 20 '(face hi-yellow))
When I call
(font-lock-mode -1)
it works, but all sql highlighting disappears.
There must be a solution because it's possible to select a region and it will be highlighted but I can't figure out how to do it programmatically
Have a look at http://www.emacswiki.org/emacs/HighlightTemporarily.
Both MarkerPens and Highlight provide functions to highlight a region.
Maybe this helps:
open ***scratch* buffer and enter:
(with-current-buffer "foo" (add-text-properties 1 10 '(comment t face highlight)))
then evaluate with C-j
Characters 1-10 will be highlited in buffer "foo".