Org-agenda-files replaces directories with explicit filenames - emacs

I have a directory tasks/ in org-agenda-files variable. When i add a file to org-agenda-files variable through C-c [ command (org-agenda-file-to-front), the directory path is replaced by paths of the files, that are currently in that directory. It is bad, because when i add some files to tasks/ later on, they will not contribute to my agenda.
Is there some way to avoid this, or i'm stuck with manually adding files and directories to org-agenda-files?
This problem is acknowledged at Org Mode - Organize Your Life In Plain Text!
Emacs version: 24.0.50.1
Org-mode version: 7.8.09

You could define a command that just adds a file to org-agenda-files without calling org-agenda-files-to-front, and then rebing that to C-c [. For example:
(defun my-org-agenda-file-to-front ()
(interactive)
(setq org-agenda-files (append org-agenda-files (list (buffer-file-name (current-buffer))))))
(define-key org-mode-map (kbd "C-c [") `my-org-agenda-file-to-front)

Related

Unable to run emacs in `magit-status-mode` with using custom initialization file

I like to use terminal tools and the one of them is 'magit' - awesome Git client implemented as an Emacs package. I use it to control Git projects. I have a script which automatically start emacs at computer boot (this same me a time with routine work). But also I'm looking for a way to run emacs in magit-status mode (without manual executing M-x magit-status... each time). Emacs provide a possibility to configure it's environment in init configuration file. To make emacs run magit at boot I created special magit.el file and run emacs from command line
$ emacs -q --load ~/.emacs.d/magit.el
Unfortunately I unable to switch emacs in magic-status-mode - something wrong with init file. Emacs remains in lisp-interaction-mode after boot. The content of init file is below:
;; disable welcome screen at launch
(setq inhibit-startup-screen t)
(setq visible-bell t)
; Disable tabs indent
(setq-default c-basic-offset 4
tab-width 4
indent-tabs-mode nil)
(global-set-key "\C-h" 'delete-backward-char)
;; Makes *scratch* empty.
(setq initial-scratch-message "")
;; Removes *scratch* from buffer after the mode has been set.
(defun remove-scratch-buffer ()
(if (get-buffer "*scratch*")
(kill-buffer "*scratch*")))
;(add-hook 'after-change-major-mode-hook 'remove-scratch-buffer)
;; Removes *messages* from the buffer.
;(setq-default message-log-max nil)
;(kill-buffer "*Messages*")
;; Removes *Completions* from buffer after you've opened a file.
;(add-hook 'minibuffer-exit-hook
; '(lambda ()
; (let ((buffer "*Completions*"))
; (and (get-buffer buffer)
; (kill-buffer buffer)))))
;; Don't show *Buffer list* when opening multiple files at the same time.
(setq inhibit-startup-buffer-menu t)
;; Show only one active window when opening multiple files at the same time.
;(add-hook 'window-setup-hook 'delete-other-windows)
;; Tell emacs where is your personal elisp lib dir (magit)
(add-to-list 'load-path "~/.emacs.d/lisp/")
(load "git") ;; best not to include the ending “.el” or “.elc”
;; activate installed packages
(package-initialize)
(setq-default major-mode 'magit-status-mode)
(add-hook 'after-init-hook #'magit-status-mode)
(if after-init-time
(add-hook 'after-init-hook #'magit-status-mode))
Try this:
(call-interactively 'magit-status)
Instead of all of this:
(setq-default major-mode 'magit-status-mode)
(add-hook 'after-init-hook #'magit-status-mode)
(if after-init-time
(add-hook 'after-init-hook #'magit-status-mode))
Using after-init-hook would make sense in an init file, but with -q you're explicitly not using an init file (using --load is not the same thing), and that hook has already run by the time your custom magit.el file is loaded, so nothing you add to the hook at that stage will ever be processed.
Note that you don't want to call magit-status-mode at all. That's not a major mode you would ever be expected to invoke manually, as you would never want that mode for any buffer other than the one created by the magit-status command.

How to remove the directory .t2d on C-c C-c Clean / M-x TeX-clean?

I use the following code in .emacs to clean the working directory from
unwanted files.
(eval-after-load 'latex
'(progn
(setq LaTeX-clean-intermediate-suffixes (delete "\\.synctex\\.gz" LaTeX-clean-intermediate-suffixes))
(setq LaTeX-clean-intermediate-suffixes (append
LaTeX-clean-intermediate-suffixes
(list "\\.bcf" "\\.synctex\\.gz(busy)" "-blx\\.bib" "\\.run\\.xml" "\\.fdb_latexmk" "\\.fls" "\\.ptc")))
(setq LaTeX-clean-output-suffixes (append LaTeX-clean-output-suffixes (list "\\.synctex\\.gz")))
))
If my LaTeX document contains an error, the current directory contains a folder
.t2d (I compile with texi2dvi -p from within Emacs/AUCTeX). I have to
manually switch to the working directory to remove this folder as, otherwise,
the document would not compile (in fact, compilation would stop with the same
error [in most of the cases]). The idea is therefore to include \\.t2d in the
above list of files being removed on C-c C-c Clean. However, if I do so, C-c
C-c Clean says TeX-clean: Removing old name: is a directory: qrm.t2d. How can
directories be removed on C-c C-c Clean?
The hint from lawlist's comment brought the solution. I first discovered that texi2dvi --mostly-clean already cleans a lot (including the unwanted directory .t2d). I then simply used a rm to remove further unwanted files -- everything wrapped so that I can call it via C-c C-c tidy:
(add-hook 'LaTeX-mode-hook
(lambda ()
;; texi2dvi
(add-to-list 'TeX-command-list
'("texi2dvi" "PDFLATEX='pdflatex --shell-escape -synctex=1 -file-line-error' texi2dvi --max-iterations=5 -p %s.tex" TeX-run-command nil t :help "Run texi2dvi") t)
;; clean
(add-to-list 'TeX-command-list
'("tidy" "texi2dvi --mostly-clean %s.tex; rm %s.pdf \"%s.synctex.gz(busy)\"" TeX-run-command nil t :help "Run clean") t)
;; default
(setq TeX-command-default "texi2dvi")))

Obtain buffer file name without extension in .emacs

I am trying to make shortcuts for portable emacs linking to a portable LaTeX compiler and R for Sweave, but I know very little about the language used in .emacs (this is Lisp?)
Currently I am using fullpath-relative-to-current-file obtained from Link to get the path to .emacs (which is in USBDRIVE/Documents), then get the relative path to the compiler and call it on buffer-file-name which is the full path and filename including extension of the extension:
(global-set-key (kbd "C-c s")
(lambda ()
(interactive)
(cond ((string-equal (file-name-extension (buffer-file-name)) "tex")
(shell-command (concat (fullpath-relative-to-current-file "../PortableApps/miktex/miktex/bin/pdflatex ") buffer-file-name)))
)
(cond ((string-equal (file-name-extension (buffer-file-name)) "Rnw")
(shell-command (concat (fullpath-relative-to-current-file "../PortableApps/R/R-2.14.1/bin/R CMD Sweave ") buffer-file-name " --pdf")))
)
)
)
This allows me to use C-c s to run LaTeX on a tex file and Sweave on an Rnw file. Now I would like to include calls to bibtex, but for that I need the filename and path of the tex file without extension. How can I do that?
Try file-name-sans-extension. For more details, read the File Name Components section of the manual.

change .emacs file's location

I am working on windows xp
I stored emacs in usb
I want to carry the .emacs file as well as binary files
what I tried are
(setenv “HOME” (format "%s" (getenv "emacspath")))
(setenv “HOME” (format "%s/" (getenv "emacspath")))
It seems works if I eval-expression in emacs
After setenv, I could notice setting env is works well by (getenv "home")
but I put the (setenv "home" (format "%s/" (getenv "emacspath")))
in "site-start.el" file in "site-lisp" folder, starting emacs says "Symbol's value as variable is void: "HOME"
Any ideas?
An easier way - just create a batch file on your USB drive where you can set all env variables you need. Then start emacs.exe from the batch.
For example if you want to run SBCL add the following lines to your batch
rem SBCL_HOME is required for SBCL
set SBCL_HOME=%utils%\Lisp\sbcl\1.0.29
set SBCL_RUN=%SBCL_HOME%\sbcl.exe
set SBCL_OPTIONS=--noinform
How about using default.el either as a symlink or as a simple elisp pinter to your file:
(load-file "/path/to/usb/.emacs")
Add following code to a file (e.g. c:/.emacs).
;; This function must be at begin
(defun zxy-relocate-dotemacs ()
"Relocate .emacs file"
(interactive)
(with-temp-buffer
(let (print-level print-length)
(insert (format "(load-file \"%s\")" load-file-name))
(if (file-exists-p "~/.emacs")
(message "[zxy] Don't need relocate .emacs file!")
(progn
(message "[zxy] Relocate .emacs file.")
(write-file "~/.emacs"))))))
(zxy-relocate-dotemacs)
;; Your configuration here
Open emacs and M-x load-file c:/.emacs.
Then it will relocate .emacs to c:/.emacs.
I use this when I copy my emacs to a new computer.
More information please visit my blog abuot emacs.
http://coordinate.sinaapp.com/?cat=3

Loading fic-mode in emacs

This answer gave me the solution I needed. The only problem for me, is that I have to load it, namely fic-mode, manually. More explicitly, whenever I open a c++ file, I have to do M-x fic-mode and then M-x font-lock-fontify-buffer in order to have it really up and running. In my .emacs I have
(require 'fic-mode)
(add-hook 'c++-mode-hook '(lambda () (fic-mode 1)))
but it doesn't do the trick.
Do you have any suggestions how to make it available automatically?
Try the following: create a new file containing the following three lines:
(setq load-path (cons "/path/to/fic-mode-directory" load-path))
(require 'fic-mode)
(add-hook 'c++-mode-hook 'turn-on-fic-mode)
Replace "/path/to/fic-mode-directory" with the absolute path to the directory in which you saved fic-mode.el.
Then from the command line, run
emacs -Q -l /path/to/file
where /path/to/file is the path to the above file.
Now type C-x C-f test.cpp.
Is fic-mode turned on in the resulting buffer?