Showing line numbers in dired file browser in Emacs - emacs

I am unable to show line numbers in Emacs when browsing files using Dired.
Dotspacemacs-line-numbers '(:relative nil
:visual t
:disabled-for-modes ;; dired-mode
doc-view-mode
markdown-mode
;; org-mode
pdf-view-mode
;; text-mode
:size-limit-kb 1000)
but line numbers are not showing.
any idea how to enable line numbers in Dired?

Turn on minor mode display-line-numbers-mode:
M-x display-line-numbers-mode. C-h f tells you:
display-line-numbers-mode is an autoloaded interactive compiled Lisp
function in display-line-numbers.el.
(display-line-numbers-mode &optional ARG)
Toggle display of line numbers in the buffer.
This uses display-line-numbers internally.
This is a minor mode. If called interactively, toggle the
Display-Line-Numbers mode mode. If the prefix argument is positive,
enable the mode, and if it is zero or negative, disable the mode.
If called from Lisp, toggle the mode if ARG is toggle. Enable the
mode if ARG is nil, omitted, or is a positive number. Disable the
mode if ARG is a negative number.
To check whether the minor mode is enabled in the current buffer,
evaluate display-line-numbers-mode.
The mode’s hook is called both when the mode is enabled and when it is
disabled.
To change the type of line numbers displayed by default,
customize display-line-numbers-type. To change the type while
the mode is on, set display-line-numbers directly.
Probably introduced at or before Emacs version 26.1.

Related

How to toggle a command in Emacs lisp?

I would like to have a shortcut that would toggle the showing of line numbers in Emacs.
This is what I have so far:
(defun my-toggle-display-line-numbers-mode-function ()
"Toggles the line numbers"
(interactive)
(display-line-numbers-mode)
)
(global-set-key [(f7)] 'my-toggle-display-line-numbers-mode-function)
But it will only turn on the line numbers. I can't turn it off, unlike when I use M-x display-line-numbers-mode which will turn on or off without any problem.
Any idea how to improve my script so it works as intended?
describe-function (C-h f) on display-line-numbers-mode gives the following:
Signature:
(display-line-numbers-mode &optional ARG)
Documentation:
[...]
This is a minor mode. If called interactively, toggle the
Display-Line-Numbers mode mode. [...]
If called from Lisp, toggle the mode if ARG is toggle. Enable
the mode if ARG is nil, omitted, or is a positive number.
Disable the mode if ARG is a negative number.
This is the automatic desciption produced by the define-minor-mode macro, and for most minor modes, the previous documentation will be exactly the same.
What we get from this:
When called interactively (i.e. as a command, using for example M-x display-line-numbers-mode) this acts as a toggle.
When called from Elisp source code, you need to specify an argument.
If you want it to act as a toggle, use (display-line-numbers-mode 'toggle) in your code. If you want something slightly more advanced than a simple toggle (for example, checking some extra conditions), use 1 and -1 as arguments to respectively enable and disable the mode (incidentally, and although the documentation is unclear, 0 counts as a negative number here, and so (display-line-numbers-mode 0) disables the mode.
As it is often the case, Emacs built-in documentation shows all there is to know. Try to get familiar with the help system, it's really good compared to a lot of softwares.

Disable flycheck-mode and prettify-symbols-mode

My emacs.d clones from purcell/emacs.d: An Emacs configuration bundle with batteries included
It enable prettify-symbols-mode and flycheck-mode as default.
Search the custom.el but did not find related setting .
How could disable them from my init.el?
(prettify-symbols-mode -1)
C-h f prettify-symbols-mode:
prettify-symbols-mode is an interactive compiled Lisp function in
‘prog-mode.el’.
(prettify-symbols-mode &optional ARG)
Toggle Prettify Symbols mode.
With a prefix argument ARG, enable Prettify Symbols mode if ARG is
positive, and disable it otherwise. If called from Lisp, enable
the mode if ARG is omitted or nil.
When Prettify Symbols mode and font-locking are enabled, symbols are
prettified (displayed as composed characters) according to the rules
in ‘prettify-symbols-alist’ (which see), which are locally defined
by major modes supporting prettifying. To add further customizations
for a given major mode, you can modify ‘prettify-symbols-alist’ thus:
(add-hook 'emacs-lisp-mode-hook
(lambda ()
(push '("<=" . ?≤) prettify-symbols-alist)))
You can enable this mode locally in desired buffers, or use
‘global-prettify-symbols-mode’ to enable it for all modes that
support it.
This applies to almost every minor mode.

Highlighting trailing whitespace in emacs without changing character

I am trying to get emacs to highlight trailing-spaces. I have tried using WhiteSpace, and also tried setting show-trailing-whitespace variable to true, but in each case it changes the representation of newline and space characters to $ and · characters, as shown in this screen capture.
Ideally I would like to just see the trailing whitespace highlighted in red without any such characters.
Disclaimer: I'm new to emacs, so this may well be obvious.
I don't use any library. I just set show-trailing-whitespace to t and any trailing white space is shown in red. The representation of newline and space characters is NOT changed.
Actually, my ".emacs" file contains this simple line:
(setq-default show-trailing-whitespace t)
In case you don't want to edit your ".emacs" file, you may try:
C-h v show-trailing-whitespace RET then click the customize link
(or just M-x customize-variable RET show-trailing-whitespace RET)
Click the toggle button to set it to on (non-nil)
Click the menu button State > Set for Current Session
Click the menu button State > Save for Future Sessions
[EDIT] (thanks to Francesco Frassinelli for his comment)
With setq-default, the value is changed for every mode.
If you want to disable it for some mode (like term-mode for example), you have to:
find the mode name of the current buffer. Usually you can get it from within the buffer with M-x describe-mode RET (shortcut C-h m or <f1> m).
find the entry "hook" for this mode. Usually, it's the mode name with the suffix -hook. You can find it by searching "hook" in the buffer describing the mode. For example, you may read:
Entry to this mode runs the hooks on ‘term-mode-hook’
add the following to your ".emacs" file:
(add-hook 'term-mode-hook (lambda () (setq show-trailing-whitespace nil)))
or you may try:
M-x customize-variable RET term-mode-hook RET
Click the INS button
Paste (lambda () (setq show-trailing-whitespace nil))
Click the menu button State > Set for Current Session
Click the menu button State > Save for Future Sessions
Note that show-trailing-whitespace automatically becomes buffer-local when set with setq.
Change the value of the whitespace-style variable to
(face trailing)
You might need to restart whitespace-mode for the changes to take effect.
To set a variable, use M-xset-variableEnter.
Another answer is to use library highlight-chars.el (description: Highlight library).
Command hc-toggle-highlight-trailing-whitespace does what you request.
You can also turn on such highlighting automatically, either everywhere or in a given buffer or for a given mode.

Different results when elisp function is run different ways; why?

EDIT: Perhaps (in original post) I used the term "transient" incorrectly (I'm not familiar enough with the jargon yet). What I really mean is that the highlighted region will disappear immediately when the user presses a navigation keys eg. arrow-keys... (2nd EDIT: I've removed the word "transient")
The particular issue of selecting a region so the user gets "cursor-key movement will make highlighting disappear" has been the bane of my existance recently. I get differnt results depending on how I run the following script.
Why does it give different results, and more specifically, is there a way to make it produce "cursor-keys make highlighting disappear" regardless of which mode is running, or whether it is being evaluated while testing? .. CUA mode has this behaviour, but I really need that non CUA mode does it too (and eval, if possible)...
Here are the results, followed by the code. (GNU Emacs 23.1.1)
CUA mode enabled
Evaluate via C-x C-e — both (call-trans-hi) and (trans-hi)
NO-GO: Both set mark and move point to EOL, but nothing is highlighted.
Execute M-x call-trans-hi
ok: Works fine; the region is highlighted and then disappears the first time a key is pressed.
Via key binding C-f1
ok: Works fine; the region is highlighted and then disappears the first time a key is pressed.
no CUA mode (pretty much std emacs)
Evaluate via C-x C-e
NO-GO: Same as 1. when CUA is enabled.
Execute M-x call-trans-hi
NO-GO: The line is highlighted, but it is sticky! and requires C-g (keyboard-quit) to clear it.
Via key binding C-f1
NO-GO: The line is highlighted, but it is sticky! and requires C-g (keyboard-quit) to clear it.
;test (trans-hi) EOL
(defun trans-hi ()
"transient highlight"
(beginning-of-line)
(push-mark (point))
(end-of-line)
(activate-mark))
;test (call-trans-hi) EOL
(defun call-trans-hi ()
"call transient highlight"
(interactive)
(trans-hi))
(global-set-key [C-f1] 'call-trans-hi)
When you look at the source of activate-mark, you can see that it's just setting some variables. I suppose that's why you don't see the mark in both 1., because the actual highlighting happens in some stuff that's done when executing functions interactively instead of just calling them.
In the other cases of no CUA-mode, that just how transient highlighting works outside of CUA-mode. If you want the CUA-mode behaviour, use CUA-mode resp. that part of it.
EDIT:
Does this change (the addition of the setq line) to trans-hi make the highlighting work the way you want?
(defun trans-hi ()
"transient highlight"
(beginning-of-line)
(push-mark (point))
(end-of-line)
(setq transient-mark-mode (cons 'only transient-mark-mode))
(activate-mark))
If you want to see the region highlighted when you mark it, you need
to activate the minor mode transient-mark-mode.
When a region is highlighted and a character insterted the default is
to disable the highlighting and insert the character at the cursor.
If you wish you can delete the selected region by activating the minor
mode delete-selection-mode.

Disable auto indent globally in Emacs

How to disable auto indent in Emacs globally or only for some modes?
I have a number of packages installed for RubyOnRails (ruby, html, js, css).
Let's say I want to disable autoindent for css-mode.
For me, on emacs 24.x, M-xelectric-indent-mode toggled the behavior that I wanted to disable.
FWIW, the behavior was that RET was bound to the command newline which is defined in simple.el... Among other things, the behavior of that command is altered by electric-indent-mode.
You may want to look for variable names containing the word electric. (This is the common Emacs parlance for actions which occur automatically when particular visible characters are typed.)
In this instance, M-x apropos-variable RET electric RET shows me that there is a css-electric-keys variable containing a list of "Self inserting keys which should trigger re-indentation."
You could use M-x customize-variable RET css-electric-keys RET to set this list to nil, or add (setq css-electric-keys nil) to your init file.
Sometimes a minor mode is used to implement electric behaviours, so that you can switch them on and off more easily. Those would likely be found via M-x apropos-command RET electric RET, and you would probably use a major mode hook to ensure that the electric minor mode was disabled, in a similar fashion to this:
(add-hook 'MAJORMODE-mode-hook 'my-MAJORMODE-mode-hook)
(defun my-MAJORMODE-mode-hook ()
(ELECTRICMODE-mode 0))