Content AND Presentation

(Note to English-speaking readers: the links entitled Komentarze na tej stronie lead to comment pages.)

2017-03-18 Deleting all instances of a LaTeX environment

Today, someone asked on the AUCTeX-devel mailing list about a way to delete (or comment out) all the instances of certain environment. Here’s my solution. It’s not 100% robust (it can be fooled by a partially commented out environment, for instance – but that shouldn’t happen anyway), but for a “normal” file it should work well enough. (If you want to comment out environments instead of deleting them, you might use comment-region instead of delete-region. In the case of deletion, consider using diff-buffer-with-file, just to make sure nothing important got deleted.)

Notice the use of save-mark-and-excursion. Also, LaTeX-environment-list-filtered is used to get the list of environments for completion.

(defun LaTeX-delete-environment (env)
  "Delete all instances of environment ENV in the buffer."
  (interactive (list (completing-read "Environment to delete: "
	(goto-char (point-min))
	(while (search-forward (format "\\begin{%s}" env) nil t)
	  (unless (nth 4 (syntax-ppss))
	(delete-region (region-beginning) (region-end))))))

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryLaTeX

Comments on this page

2017-03-13 Ibuffer

Some day, when you have half an hour to spare, press M-x ibuffer RET and then h. Then take your jaw from the floor and put it back in place again.

One use-case: if you sometimes e.g. visit a lot of files (e.g. by means of using follow-mode in a buffer full of grep results), and want to kill their buffers (e.g., because OCD – other than that there is (almost) no reason to do it!), you can use ibuffer’s filtering and marking commands to do that. Another one: query replace in multiple buffers.

CategoryEnglish, CategoryBlog, CategoryEmacs

Comments on this page

2017-03-04 Bookmarking directories in Eshell

A friend of mine showed me a nifty trick, basically bookmarking directories in bash. While this is nice, I often use Eshell, and I wanted a similar thing there. (Notice that while Emacs bookmarks do work in Dired, they won’t let you bookmark a directory in Eshell!) Bonus points for sharing the bookmark database (which is basically a directory called ~/.marks/ containing symlinks to bookmarked directories).

Well, here it is. Notice the (a bit misleadingly named) function file-symlink-p, which returns the target of the symlink if the file with the given name is a symlink and nil otherwise. Also, the directory name is hardcoded, and I didn’t bother to add any error detection – but this would be easy.

(defun eshell/jump (mark)
  "Jump to a directory symlinked to by a file called ~/.marks/MARK."
  (eshell/cd (file-symlink-p (concat "~/.marks/" mark))))

This is nice already, but lacks one important thing: autocompletion. It turns out that this is not difficult at all:

(defun pcomplete/jump ()
  "Complete a command that wants a name of a file in ~/.marks."
  (pcomplete-here* (directory-files "~/.marks/")))

And that’s pretty much it!

On the other hand, it would be probably more Emacs-y to make Emacs bookmarks support Eshell. Still, this solution has an advantage of working both in Eshell and in bash. Moreover, one could add support also for the mark function, which wouldn’t be too difficult.

CategoryEnglish, CategoryBlog, CategoryEmacs

Comments on this page


(Więcej means More in Polish; click it to see older entries.)

CategoryEnglish, CategoryBlog