How do I make Dired display its files using an arbitrary function or set of columns? Basically I want to change from:
-rw-r--r-- 1 konrad konrad 3847863 Out 18 14:17 ClojureinAction.pdf
-rw-rw-r-- 1 tamara tamara 27338341 Out 20 07:16 Halliday, Resnick, Walker - Fundamentals of Physics.pdf
-rw-r--r-- 1 konrad konrad 3921024 Set 22 11:11 Pragmatic.Programming.Clojure.May.2009.pdf
To something like
644 1-5MB ClojureinAction.pdf PDF (5 days ago, 400pgs)
664 10-100MB Halliday, Resnic...pdf PDF (3 days ago, 1000pgs, Tamara's)
644 1-5MB Pragmatic.Progra...pdf PDF (1 min ago, 100 pages)
Thanks!
EDIT: Thanks for the answer, Gareth, but could you be more verbose, please? Apparently the hook will just allow me to run arbitrary code when the buffer loads up. Dired won't even stop loading up the buffer :(
(defun foo (&rest args) (unlocking-buffer (message "foo") (insert "foo\n")))
Glancing at dired's source code, it seems that it gets information from these very formats I'm trying to replace, so I wonder if it's viable to change it this way, or if I'll end up having to rewrite everything.
Dired mode makes quite a few assumptions about ls output format, so changing the format will break many things. I think a more feasible approach is to leave the format alone, and use either text-properties or overlays to change the presentation.
This isn't nearly as drastic as what you're looking for, but it is possible to customize how Emacs calls ls in dired-mode.
M-x customize-variable RET dired-listing-switches RET
I used it to omit the group ID of files with the -o option, saving some horizontal screen real estate.
Write a function that transforms the output of ls into the format you want, and then add that function to dired-after-readin-hook.
Edited to add: dired-mode determines the name of the file by parsing the output of ls, so some features of dired will break when you change the format. You can make (some of) them work again by changing directory-listing-before-filename-regexp and dired-permission-flags-regexp. Since your change to the format is quite radical, you may prefer to rewrite the functions dired-move-to-filename and dired-move-to-end-of-filename.
(This sounds tough but it's not impossible. I customize the format of dired buffers in the manner I described, though not nearly so radically as you propose to do.)
You will have a lot of work if you insist on truncating the filename, because dired-mode assumes that it can get the filename on the current line by calling
(buffer-substring (dired-move-to-filename) (dired-move-to-end-of-filename))
I'd use the answer here: https://stackoverflow.com/a/1796009/714357
and the 'compile command which will run in your default-directory. So it will give you a new buffer, but it is the information you are looking for.
(defun my/ls-mode-numbers ()
(interactive)
(compile " ls -l | awk '{k=0;for(i=0;i<=8;i++)k+=((substr($1,i+2,1)~/[rwx]/) \
*2^(8-i));if(k)printf(\"%0o \",k);print}'"))
Related
I want to implement dynamical text replacement (only the display is replaced, the actual stored file is not replaced) for Emacs, using Elisp.
For example, in LaTeX documents, I want to type \alpha, and let Emacs display it just as α, so it is easier to read. But in the result .tex file, I still want \alpha, instead of α to be saved. (Remark: I could use XeTeX or LuaTeX myself to support UTF-8 directly. But for the reason of collaboration and journal requirements, I don't want the UTF-8 characters to be directly saved in the .tex files. Alternatively I could use preview in AUCTeX. But that doesn't help when I am editing the formula)
An existing example is in org-mode, when we type [[link][name]], right after typing the last ], the displayed text is replaced by just the name, with hyperlink. On the other hand, when saving this file, the saved content is the original [[link][name]], different from the displayed one.
Any ideas how this could be implemented?
PS: The Display Specs That Replace The Text section of Emacs manual goes close. However, I need to specify the start and end points, instead of the desired string for the replacements. This means I need to do search after every user input to decide the start and end points. This looks unrealistic due to performance and complexity of algorithm.
One way to do this is to add font lock keywords for the relevant modes, and to use compose-region to display the new glyph in place of the old string:
(font-lock-add-keywords
'latex-mode `(("\\(\\\\alpha\\)"
(0 (progn (compose-region (match-beginning 1)
(match-end 1) "α")
nil)))))
Please also note that org-mode has a feature of this kind already built-in, not only for links as you mentioned, but also for LaTeX-like entities:
(setq org-pretty-entities t)
Hi I am currently reading some novels in .txt format downloaded from Gutenberg.
Often I come across a word I am unfamiliar with, and I need to look it up on the web.
I recently stumbled upon the Unix dict command-line utility to search for meanings of words. It fetches
the meanings of words from multiples dictionaries and thesauruses on the web.
I would like to have this integrated with Emacs in the following way.
I would like to pass the word under the cursor to the dict and split the window into two buffers
: one buffer containing the current text-file and another-one the meaning of the words.
How would I write an Emacs-Lisp function for doing this?
NOTE: Using dict at the command-line is as simple as dict *word-being-searched*
and I am using Emacs-24 under Ubuntu 11.04
The word-at-point function does most of the work you need:
(require 'thingatpt)
(defun lookup-word-at-point ()
(interactive)
(shell-command (format "dict %s" (shell-quote-argument (word-at-point)))))
Like any other invocation of shell-command, this will show the output of dict in the minibuffer if it's short enough; otherwise, it will pop up a window named *Shell Command Output*.
ispell is your friend. ispell-word, bound by default to M-$ does exactly that.
Also see wordnet.el
EDIT: As Thomas pointed out, ispell is not appropriate. I am a big fan of wordnet that I mentioned earlier, you will need to download the program.
Another option is an interface to the dict command, e.g. enter link description here or one of the alternatives listed on that page.
There is enough stuff out there that you don't need to write something on your own.
What's the best choice for defining a large table in org-mode (by large, I mean that each cell can have multiple lines)? The one feature of org-mode is its ability to export to HTML or LaTeX (or other), but in this case would I have to commit to the export format a priori and hard-code the table in that language (e.g., HTML)? What software would you use to create table with mostly text fields with paragraphs in each cell in the first place (which you could convert to HTML, for instance)?
You might want to look at table-mode. This supports the sort of "large tables" you're talking about. It's been part of the emacs distribution for some time now. Start with
(require 'table)
somewhere in ~/.emacs. Create an empty file or buffer, type
M-x table-insert RET
answer the initial questions sensibly and then play around a bit. You can get some documentation with
C-h f table-insert RET
To find more documentation, you'll need to locate the source code. Start with
M-x locate-library RET table RET
This will show you the location of the byte-compiled lisp file for table-mode, and in that same directory you should fine table.el or table.el.gz, which will contain documentation you'll need to at least skim. Most linux systems (foolishly) do not install the .el files by default, so you'll have to go rooting around with the package manager to get them.
I was fairly sure that org-mode knew how to parse table-mode tables and format them for you, but I can't seem to find that written down anywhere right now.
When viewing piped output to Less, sometimes I'd like to be able to view it in Emacs in order to get syntax highlighting and use emacs commands for searching, marking, copying, etc.
I see that Less has a v command that can be used to open the currently viewed file in $EDITOR. Unfortunately this doesn't work when viewing piped input.
Also, I don't know how to get Emacs to display stdin as a read-only document.
So, is it possible to set up Less with something like v but that pumps the current buffer into Emacs as a read-only file?
Thanks.
If you scroll down in http://www.emacswiki.org/emacs/GnuClient, you'll come to a section titled "Piping data to an Emacs buffer" which may be relevant. Or you can hack up a solution involving emacsclient and temporary files. (link dead).
I found another variant while looking for a duplicate of the dead link: Piping to an emacs buffer with emacsclient which points at code stored on github.
I've formalized the solution here: github e-sink
99.9% of the time, I don't care how many links are pointing to a file. How do I get dired (or alternatively, ls) to not display the number of links?
For reference, the output of ls -l is something like:
-rw-rw-rw- 1 root dir 104 Dec 25 19:32 file
The number of links, in this case, is 1. ls has a flag to remove the group number (104) but not one to remove the number of links, from what I can tell.
I'm afraid editing the format will screw up dired's parsing, as ls has a special flag for producing output to dired.
To control how things are displayed in dired, you can customize the variable dired-listing-switches. However, as you noted, not displaying the number of links is not an option.
A slightly different approach would be to use the package dired-details, which hides all details until you want them. This hides the number of links (but also hides other information). Follow the link to find the package (and a dired-details+ which sounds like it fixes a couple minor inconveniences with dired-details).
Original answer information follows:
(setq dired-listing-switches "-l")
From the "Entering Dired" info page:
The variable
dired-listing-switches' specifies the
options to give tols' for listing
the directory; this string must
contain -l'. If you use a numeric
prefix argument with thedired'
command, you can specify the ls'
switches with the minibuffer before
you enter the directory specification.
No matter how they are specified, the
ls' switches can include short
options (that is, single characters)
requiring no arguments, and long
options (starting with --') whose
arguments are specified with='.
You can use ls-lisp to customize the dired buffer display. ls-lisp is part of GNU Emacs (22.1 or perhaps even earlier) ls-lisp has a ls-lisp-verbosity customize variable that will allow you to show/hide "links", "uid" and "gid". It also has other things that may tickle your customize fancy.
I like ls-lisp so much I use it everywhere, on my Windows and even Linux sessions.