Update library homepage
[smiles-mode.git] / smiles-mode.el
blob281a75c06e2c64e8e2c2a3a733bb386e6a6af809
1 ;;; smiles-mode.el --- Major mode for SMILES.
2 ;;; -*- coding: utf-8 -*-
4 ;; Keywords: SMILES
5 ;; Version: 0.0.1
6 ;; Homepage: https://repo.or.cz/smiles-mode.git
8 ;;; Commentary:
10 ;;; I copy code from:
11 ;;; http://kitchingroup.cheme.cmu.edu/blog/2016/03/26/A-molecule-link-for-org-mode
13 ;; Author: John Kitchin [jkitchin@andrew.cmu.edu]
15 ;;; Code:
17 ;; smiles major mode
18 (require 'easymenu)
20 (defun smiles-cml ()
21 "Convert the smiles string in the buffer to CML."
22 (interactive)
23 (let ((smiles (buffer-string)))
24 (switch-to-buffer (get-buffer-create "SMILES-CML"))
25 (erase-buffer)
26 (insert
27 (shell-command-to-string
28 (format "obabel -:\"%s\" -ocml 2> /dev/null"
29 smiles)))
30 (goto-char (point-min))
31 (xml-mode)))
33 (defun smiles-names ()
34 (interactive)
35 (browse-url
36 (format "http://cactus.nci.nih.gov/chemical/structure/%s/names"
37 (buffer-string))))
39 (defvar smiles-mode-map
40 nil
41 "Keymap for smiles-mode.")
43 ;; adapted from http://ergoemacs.org/emacs/elisp_menu_for_major_mode.html
44 (define-derived-mode smiles-mode fundamental-mode "smiles-mode"
45 "Major mode for SMILES code."
46 (setq buffer-invisibility-spec '(t)
47 mode-name " ☺")
49 (when (not smiles-mode-map)
50 (setq smiles-mode-map (make-sparse-keymap)))
51 (define-key smiles-mode-map (kbd "C-c C-c") 'smiles-cml)
52 (define-key smiles-mode-map (kbd "C-c C-n") 'smiles-names)
54 (define-key smiles-mode-map [menu-bar] (make-sparse-keymap))
56 (let ((menuMap (make-sparse-keymap "SMILES")))
57 (define-key smiles-mode-map [menu-bar smiles] (cons "SMILES" menuMap))
59 (define-key menuMap [cml]
60 '("CML" . smiles-cml))
61 (define-key menuMap [names]
62 '("Names" . smiles-names))))
65 (provide 'smiles-mode)
67 ;;; smiles-mode.el ends here