-1

My emacs is running on Window 7 and I have just installed yasnippet via M-x package-list and added few lines to my .emacs file because I read around the web that it needs to be initialized.

I tried writing a simple yasnippet for LaTeX, calling it "fraction", triggered by typing fr+ TAB and saved it in ~\.emacs.d\elpa\yasnippet-0.8.0\snippets\latex-mode. This is the code.

# -*- mode: snippet -*-
# name: fraction
# key: fr
# --
\dfrac{$1}{$0}

Since yasnippet was adding a newline everytime I triggered this snippet I modified the .emacs file. This is how it looks now:

;; yasnippet
(add-to-list 'load-path "~/.emacs.d/elpa/yasnippet-0.8.0")
(require 'yasnippet)
(setq yas-snippet-dirs '("~/.emacs.d/elpa/yasnippet-0.8.0/snippets"))
(setq-default mode-require-final-newline nil)
(yas-global-mode 1)

Now however, everytime I type 'fr' it sure gives me \dfrac{}{} but as soon as I write inside the first pair of curly braces, the same value appears in the second pair of braces (denominator) and pressing TAB pushes the cursor out of the last '}'. What am I missing here? How can I fix this problem?

My entire .emacs file is below. I'm probably doing something wrong, please help me correct it.

;;; Schlosser's .emacs
(server-start)
(add-hook 'LaTeX-mode-hook 'turn-on-reftex)
(setq reftex-plug-into-AUCTeX t)
;(setq-default ispell-program-name "aspell")


;;; Brent.Longborough's .emacs
(setq inhibit-splash-screen t); Disable splash screen
(setq visible-bell t); Flashes on error
(show-paren-mode 1); Matches parentheses and such in every mode


;;; AUCTeX
;; Customary Customization, p. 1 and 16 in the manual, and http://www.emacswiki.org/emacs/AUCTeX#toc2
(setq TeX-parse-self t); Enable parse on load.
(setq TeX-auto-save t); Enable parse on save.
(setq-default TeX-master nil)

(setq TeX-PDF-mode t); PDF mode (rather than DVI-mode)

;activate Flyspell, for all modes(?), not just TeX; from alienexp.blogspot.com
(add-to-list 'exec-path "C:/Program Files/Aspell/bin/")
(setq ispell-program-name "aspell")
(setq ispell-dictionary "english") ;to change do M-x ispell-change-dictionary RET


(add-hook 'TeX-mode-hook 'flyspell-mode); Enable Flyspell mode for TeX modes such as AUCTeX. Highlights all misspelled words.
(add-hook 'emacs-lisp-mode-hook 'flyspell-prog-mode); Enable Flyspell program mode for emacs lisp mode, which highlights all misspelled words in comments and strings.
;(setq ispell-dictionary "english"); Default dictionary. To change do M-x ispell-change-dictionary RET.
(add-hook 'TeX-mode-hook
          (lambda () (TeX-fold-mode 1))); Automatically activate TeX-fold-mode.
(setq LaTeX-babel-hyphen nil); Disable language-specific hyphen insertion.

;; " expands into csquotes macros (for this to work babel must be loaded after csquotes).
(setq LaTeX-csquotes-close-quote "}"
      LaTeX-csquotes-open-quote "\\enquote{")

;from StackExchange question "AUCTeX preview font size too small"
(set-default 'preview-scale-function 1.1)

;; LaTeX-math-mode http://www.gnu.org/s/auctex/manual/auctex/Mathematics.html
(add-hook 'TeX-mode-hook 'LaTeX-math-mode)

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(org-format-latex-options
   (quote
    (:foreground default :background default :scale 1.0 :html-foreground "Black" :html-background "Transparent" :html-scale 1.0 :matchers
         ("begin" "$1" "$" "$$" "\\(" "\\["))))
 '(org-startup-with-latex-preview t)
 '(preview-default-document-pt 12)
 '(show-paren-mode t)
 '(transient-mark-mode (quote (only . t))))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 )

;;; a key for tilde symbol
(global-set-key [f2] "~")
;;; visual line word wrapping
(global-visual-line-mode t)


;; yasnippet
(add-to-list 'load-path "~/.emacs.d/elpa/yasnippet-0.8.0")
(require 'yasnippet)
(setq yas-snippet-dirs '("~/.emacs.d/elpa/yasnippet-0.8.0/snippets"))
(setq-default mode-require-final-newline nil)
(yas-global-mode 1)

2 Snapshots

Where the cursor was in the original line was cursor way down below!

WobblyWindows
  • 325
  • 3
  • 14
  • 2
    This works in my installation. Newline problem is mostly due to a stray newline at the end of snippet file and not due to the `mode-require-final-newline` variable. Is this the complete `.emacs` file? – nitishch Sep 16 '15 at 19:35
  • My emacs file is a collection of different people's code (I don't know elisp, not yet). I'm also experiencing some _funny_ behaviour in org-mode when I do `C-c C-x C-l` to preview latex fragments within `$` symbols. It used to display math correctly, like inline, now instead it gives the preview tiny and the cursor goes way down from the line it was. I'll try to post a snapshot of this error and the entire _.emacs_ file in my original post, please have a look at it. – WobblyWindows Sep 16 '15 at 20:51
  • Is everything ok in my .emacs file? Are there conflicting lines? – WobblyWindows Sep 17 '15 at 13:27
  • Instead of posting your entire .emacs, it's better to find the minimum amount that's needed to trigger the error. The [bisection](http://emacs.stackexchange.com/a/1047/5296) technique can help with this. – npostavs Sep 17 '15 at 13:30
  • I've commented out almost everything in my _.emacs_ file except these few lines: `(add-hook 'LaTeX-mode-hook 'turn-on-reftex)` `(setq reftex-plug-into-AUCTeX t) ;;; a key for tilde symbol` `(global-set-key [f2] "~")` `;; visual line word wrapping` `(global-visual-line-mode t)` . The problem is still persisting, both with the snippet and org-mode math preview. Are there any known conflict between AUCTeX and YASnippet or YASnippet and Org-mode that can be fixed? What could it possibly be, at this point? – WobblyWindows Sep 17 '15 at 17:52
  • I know of [#579](https://github.com/capitaomorte/yasnippet/issues/579) and [#362](https://github.com/capitaomorte/yasnippet/issues/362), though they don't seem quite the same. – npostavs Sep 17 '15 at 19:55

1 Answers1

0

I changed my .emacs file by copy/pasting some lines regarding this same problem from another post in stackexchange. Here's how it looks now.

 ;; yasnippet
 (add-to-list 'load-path "~/.emacs.d/elpa/yasnippet-0.8.0")
 (require 'yasnippet)
 (setq yas-snippet-dirs '("~/.emacs.d/elpa/yasnippet-0.8.0/snippets"))
;; (setq-default mode-require-final-newline nil) 
(yas-global-mode 1)
(defun disable-final-newline () (interactive) (set (make-local-variable 'require-final-newline) nil))

I also added Andrea Crotti's YASnippets collection to my YASnippets path and tried to write some of my own. For example:

# -*- mode: snippet -*-
# name: si
# key: si
# --
\SI{${1:number}}{${2:units}}$0

I reloaded all the snippets via the 'YASnippets' menu of LaTeX mode and now things are working fine. I'm not sure those lines fixed the problem because Org-mode still gives me trouble as reported in the pictures above. It seems as if the math preview-box is too big and can't fit the regular lines. I'm inclined to ask a new question on that matter but for now I managed to (temporarily) fix YASnippet's placeholder lining problem.

WobblyWindows
  • 325
  • 3
  • 14